152217195SDaniel Vetter /* 252217195SDaniel Vetter * Copyright (c) 2016 Intel Corporation 352217195SDaniel Vetter * 452217195SDaniel Vetter * Permission to use, copy, modify, distribute, and sell this software and its 552217195SDaniel Vetter * documentation for any purpose is hereby granted without fee, provided that 652217195SDaniel Vetter * the above copyright notice appear in all copies and that both that copyright 752217195SDaniel Vetter * notice and this permission notice appear in supporting documentation, and 852217195SDaniel Vetter * that the name of the copyright holders not be used in advertising or 952217195SDaniel Vetter * publicity pertaining to distribution of the software without specific, 1052217195SDaniel Vetter * written prior permission. The copyright holders make no representations 1152217195SDaniel Vetter * about the suitability of this software for any purpose. It is provided "as 1252217195SDaniel Vetter * is" without express or implied warranty. 1352217195SDaniel Vetter * 1452217195SDaniel Vetter * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1552217195SDaniel Vetter * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1652217195SDaniel Vetter * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1752217195SDaniel Vetter * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1852217195SDaniel Vetter * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 1952217195SDaniel Vetter * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 2052217195SDaniel Vetter * OF THIS SOFTWARE. 2152217195SDaniel Vetter */ 2252217195SDaniel Vetter 238f86c82aSSimon Ser #include <drm/drm_auth.h> 2452217195SDaniel Vetter #include <drm/drm_connector.h> 25d71d8a4bSMaxime Ripard #include <drm/drm_drv.h> 2652217195SDaniel Vetter #include <drm/drm_edid.h> 279338203cSLaurent Pinchart #include <drm/drm_encoder.h> 2899f45e32SDaniel Vetter #include <drm/drm_file.h> 2935a3b82fSMaxime Ripard #include <drm/drm_managed.h> 30d71d8a4bSMaxime Ripard #include <drm/drm_panel.h> 31d71d8a4bSMaxime Ripard #include <drm/drm_print.h> 32334f74eeSHans de Goede #include <drm/drm_privacy_screen_consumer.h> 33968d81a6SJeykumar Sankaran #include <drm/drm_sysfs.h> 34d71d8a4bSMaxime Ripard #include <drm/drm_utils.h> 3599f45e32SDaniel Vetter 36495e440bSThomas Zimmermann #include <linux/property.h> 3799f45e32SDaniel Vetter #include <linux/uaccess.h> 3852217195SDaniel Vetter 39495e440bSThomas Zimmermann #include <video/cmdline.h> 40495e440bSThomas Zimmermann 4152217195SDaniel Vetter #include "drm_crtc_internal.h" 4252217195SDaniel Vetter #include "drm_internal.h" 4352217195SDaniel Vetter 44ae2a6da8SDaniel Vetter /** 45ae2a6da8SDaniel Vetter * DOC: overview 46ae2a6da8SDaniel Vetter * 47ae2a6da8SDaniel Vetter * In DRM connectors are the general abstraction for display sinks, and include 4884e543bcSAntonio Borneo * also fixed panels or anything else that can display pixels in some form. As 49ae2a6da8SDaniel Vetter * opposed to all other KMS objects representing hardware (like CRTC, encoder or 50ae2a6da8SDaniel Vetter * plane abstractions) connectors can be hotplugged and unplugged at runtime. 51ad093607SThierry Reding * Hence they are reference-counted using drm_connector_get() and 52ad093607SThierry Reding * drm_connector_put(). 53ae2a6da8SDaniel Vetter * 54d574528aSDaniel Vetter * KMS driver must create, initialize, register and attach at a &struct 55d574528aSDaniel Vetter * drm_connector for each such sink. The instance is created as other KMS 56aec97460SDaniel Vetter * objects and initialized by setting the following fields. The connector is 57aec97460SDaniel Vetter * initialized with a call to drm_connector_init() with a pointer to the 58aec97460SDaniel Vetter * &struct drm_connector_funcs and a connector type, and then exposed to 59aec97460SDaniel Vetter * userspace with a call to drm_connector_register(). 60ae2a6da8SDaniel Vetter * 61ae2a6da8SDaniel Vetter * Connectors must be attached to an encoder to be used. For devices that map 62ae2a6da8SDaniel Vetter * connectors to encoders 1:1, the connector should be attached at 63cde4c44dSDaniel Vetter * initialization time with a call to drm_connector_attach_encoder(). The 64d574528aSDaniel Vetter * driver must also set the &drm_connector.encoder field to point to the 65ae2a6da8SDaniel Vetter * attached encoder. 66ae2a6da8SDaniel Vetter * 67ae2a6da8SDaniel Vetter * For connectors which are not fixed (like built-in panels) the driver needs to 68ae2a6da8SDaniel Vetter * support hotplug notifications. The simplest way to do that is by using the 69ae2a6da8SDaniel Vetter * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have 70ae2a6da8SDaniel Vetter * hardware support for hotplug interrupts. Connectors with hardware hotplug 71ae2a6da8SDaniel Vetter * support can instead use e.g. drm_helper_hpd_irq_event(). 72ae2a6da8SDaniel Vetter */ 73ae2a6da8SDaniel Vetter 743d3f7c1eSHans de Goede /* 753d3f7c1eSHans de Goede * Global connector list for drm_connector_find_by_fwnode(). 763d3f7c1eSHans de Goede * Note drm_connector_[un]register() first take connector->lock and then 773d3f7c1eSHans de Goede * take the connector_list_lock. 783d3f7c1eSHans de Goede */ 793d3f7c1eSHans de Goede static DEFINE_MUTEX(connector_list_lock); 803d3f7c1eSHans de Goede static LIST_HEAD(connector_list); 813d3f7c1eSHans de Goede 8252217195SDaniel Vetter struct drm_conn_prop_enum_list { 8352217195SDaniel Vetter int type; 8452217195SDaniel Vetter const char *name; 8552217195SDaniel Vetter struct ida ida; 8652217195SDaniel Vetter }; 8752217195SDaniel Vetter 8852217195SDaniel Vetter /* 8952217195SDaniel Vetter * Connector and encoder types. 9052217195SDaniel Vetter */ 9152217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { 9252217195SDaniel Vetter { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, 9352217195SDaniel Vetter { DRM_MODE_CONNECTOR_VGA, "VGA" }, 9452217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, 9552217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, 9652217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, 9752217195SDaniel Vetter { DRM_MODE_CONNECTOR_Composite, "Composite" }, 9852217195SDaniel Vetter { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, 9952217195SDaniel Vetter { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, 10052217195SDaniel Vetter { DRM_MODE_CONNECTOR_Component, "Component" }, 10152217195SDaniel Vetter { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, 10252217195SDaniel Vetter { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, 10352217195SDaniel Vetter { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, 10452217195SDaniel Vetter { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, 10552217195SDaniel Vetter { DRM_MODE_CONNECTOR_TV, "TV" }, 10652217195SDaniel Vetter { DRM_MODE_CONNECTOR_eDP, "eDP" }, 10752217195SDaniel Vetter { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, 10852217195SDaniel Vetter { DRM_MODE_CONNECTOR_DSI, "DSI" }, 10952217195SDaniel Vetter { DRM_MODE_CONNECTOR_DPI, "DPI" }, 110935774cdSBrian Starkey { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, 111fc06bf1dSNoralf Trønnes { DRM_MODE_CONNECTOR_SPI, "SPI" }, 112757e2671SNoralf Trønnes { DRM_MODE_CONNECTOR_USB, "USB" }, 11352217195SDaniel Vetter }; 11452217195SDaniel Vetter 11552217195SDaniel Vetter void drm_connector_ida_init(void) 11652217195SDaniel Vetter { 11752217195SDaniel Vetter int i; 11852217195SDaniel Vetter 11952217195SDaniel Vetter for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 12052217195SDaniel Vetter ida_init(&drm_connector_enum_list[i].ida); 12152217195SDaniel Vetter } 12252217195SDaniel Vetter 12352217195SDaniel Vetter void drm_connector_ida_destroy(void) 12452217195SDaniel Vetter { 12552217195SDaniel Vetter int i; 12652217195SDaniel Vetter 12752217195SDaniel Vetter for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 12852217195SDaniel Vetter ida_destroy(&drm_connector_enum_list[i].ida); 12952217195SDaniel Vetter } 13052217195SDaniel Vetter 13152217195SDaniel Vetter /** 132b35f90f2SLaurent Pinchart * drm_get_connector_type_name - return a string for connector type 133b35f90f2SLaurent Pinchart * @type: The connector type (DRM_MODE_CONNECTOR_*) 134b35f90f2SLaurent Pinchart * 135b35f90f2SLaurent Pinchart * Returns: the name of the connector type, or NULL if the type is not valid. 136b35f90f2SLaurent Pinchart */ 137b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type) 138b35f90f2SLaurent Pinchart { 139b35f90f2SLaurent Pinchart if (type < ARRAY_SIZE(drm_connector_enum_list)) 140b35f90f2SLaurent Pinchart return drm_connector_enum_list[type].name; 141b35f90f2SLaurent Pinchart 142b35f90f2SLaurent Pinchart return NULL; 143b35f90f2SLaurent Pinchart } 144b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name); 145b35f90f2SLaurent Pinchart 146b35f90f2SLaurent Pinchart /** 14752217195SDaniel Vetter * drm_connector_get_cmdline_mode - reads the user's cmdline mode 14884e543bcSAntonio Borneo * @connector: connector to query 14952217195SDaniel Vetter * 150ae2a6da8SDaniel Vetter * The kernel supports per-connector configuration of its consoles through 15152217195SDaniel Vetter * use of the video= parameter. This function parses that option and 15252217195SDaniel Vetter * extracts the user's specified mode (or enable/disable status) for a 15352217195SDaniel Vetter * particular connector. This is typically only used during the early fbdev 15452217195SDaniel Vetter * setup. 15552217195SDaniel Vetter */ 15652217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector) 15752217195SDaniel Vetter { 15852217195SDaniel Vetter struct drm_cmdline_mode *mode = &connector->cmdline_mode; 159495e440bSThomas Zimmermann const char *option; 16052217195SDaniel Vetter 161495e440bSThomas Zimmermann option = video_get_options(connector->name); 162495e440bSThomas Zimmermann if (!option) 16352217195SDaniel Vetter return; 16452217195SDaniel Vetter 16552217195SDaniel Vetter if (!drm_mode_parse_command_line_for_connector(option, 16652217195SDaniel Vetter connector, 16752217195SDaniel Vetter mode)) 16852217195SDaniel Vetter return; 16952217195SDaniel Vetter 17052217195SDaniel Vetter if (mode->force) { 1716140cf20SJani Nikula DRM_INFO("forcing %s connector %s\n", connector->name, 1726140cf20SJani Nikula drm_get_connector_force_name(mode->force)); 17352217195SDaniel Vetter connector->force = mode->force; 17452217195SDaniel Vetter } 17552217195SDaniel Vetter 1760980939dSHans de Goede if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) { 1770980939dSHans de Goede DRM_INFO("cmdline forces connector %s panel_orientation to %d\n", 1780980939dSHans de Goede connector->name, mode->panel_orientation); 1790980939dSHans de Goede drm_connector_set_panel_orientation(connector, 1800980939dSHans de Goede mode->panel_orientation); 1810980939dSHans de Goede } 1820980939dSHans de Goede 1833aeeb13dSMaxime Ripard DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n", 18450b0946dSMaxime Ripard connector->name, mode->name, 18552217195SDaniel Vetter mode->xres, mode->yres, 18652217195SDaniel Vetter mode->refresh_specified ? mode->refresh : 60, 18752217195SDaniel Vetter mode->rb ? " reduced blanking" : "", 18852217195SDaniel Vetter mode->margins ? " with margins" : "", 18952217195SDaniel Vetter mode->interlace ? " interlaced" : ""); 19052217195SDaniel Vetter } 19152217195SDaniel Vetter 19252217195SDaniel Vetter static void drm_connector_free(struct kref *kref) 19352217195SDaniel Vetter { 19452217195SDaniel Vetter struct drm_connector *connector = 19552217195SDaniel Vetter container_of(kref, struct drm_connector, base.refcount); 19652217195SDaniel Vetter struct drm_device *dev = connector->dev; 19752217195SDaniel Vetter 19852217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 19952217195SDaniel Vetter connector->funcs->destroy(connector); 20052217195SDaniel Vetter } 20152217195SDaniel Vetter 202ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work) 203a703c550SDaniel Vetter { 204ea497bb9SDaniel Vetter struct drm_connector *connector, *n; 205ea497bb9SDaniel Vetter struct drm_device *dev = 206ea497bb9SDaniel Vetter container_of(work, struct drm_device, mode_config.connector_free_work); 207ea497bb9SDaniel Vetter struct drm_mode_config *config = &dev->mode_config; 208ea497bb9SDaniel Vetter unsigned long flags; 209ea497bb9SDaniel Vetter struct llist_node *freed; 210a703c550SDaniel Vetter 211ea497bb9SDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 212ea497bb9SDaniel Vetter freed = llist_del_all(&config->connector_free_list); 213ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 214ea497bb9SDaniel Vetter 215ea497bb9SDaniel Vetter llist_for_each_entry_safe(connector, n, freed, free_node) { 216a703c550SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 217a703c550SDaniel Vetter connector->funcs->destroy(connector); 218a703c550SDaniel Vetter } 219ea497bb9SDaniel Vetter } 220a703c550SDaniel Vetter 221b11af8a2SMaxime Ripard static int __drm_connector_init(struct drm_device *dev, 22252217195SDaniel Vetter struct drm_connector *connector, 22352217195SDaniel Vetter const struct drm_connector_funcs *funcs, 224b11af8a2SMaxime Ripard int connector_type, 225b11af8a2SMaxime Ripard struct i2c_adapter *ddc) 22652217195SDaniel Vetter { 22752217195SDaniel Vetter struct drm_mode_config *config = &dev->mode_config; 22852217195SDaniel Vetter int ret; 22952217195SDaniel Vetter struct ida *connector_ida = 23052217195SDaniel Vetter &drm_connector_enum_list[connector_type].ida; 23152217195SDaniel Vetter 232ba1f665fSHaneen Mohammed WARN_ON(drm_drv_uses_atomic_modeset(dev) && 233ba1f665fSHaneen Mohammed (!funcs->atomic_destroy_state || 234ba1f665fSHaneen Mohammed !funcs->atomic_duplicate_state)); 235ba1f665fSHaneen Mohammed 2362135ea7aSThierry Reding ret = __drm_mode_object_add(dev, &connector->base, 23752217195SDaniel Vetter DRM_MODE_OBJECT_CONNECTOR, 23852217195SDaniel Vetter false, drm_connector_free); 23952217195SDaniel Vetter if (ret) 240613051daSDaniel Vetter return ret; 24152217195SDaniel Vetter 24252217195SDaniel Vetter connector->base.properties = &connector->properties; 24352217195SDaniel Vetter connector->dev = dev; 24452217195SDaniel Vetter connector->funcs = funcs; 24552217195SDaniel Vetter 2462a8d3eacSVille Syrjälä /* connector index is used with 32bit bitmasks */ 247e5d6eeeaSBo Liu ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL); 2482a8d3eacSVille Syrjälä if (ret < 0) { 2492a8d3eacSVille Syrjälä DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n", 2502a8d3eacSVille Syrjälä drm_connector_enum_list[connector_type].name, 2512a8d3eacSVille Syrjälä ret); 25252217195SDaniel Vetter goto out_put; 2532a8d3eacSVille Syrjälä } 25452217195SDaniel Vetter connector->index = ret; 25552217195SDaniel Vetter ret = 0; 25652217195SDaniel Vetter 25752217195SDaniel Vetter connector->connector_type = connector_type; 25852217195SDaniel Vetter connector->connector_type_id = 259e5d6eeeaSBo Liu ida_alloc_min(connector_ida, 1, GFP_KERNEL); 26052217195SDaniel Vetter if (connector->connector_type_id < 0) { 26152217195SDaniel Vetter ret = connector->connector_type_id; 26252217195SDaniel Vetter goto out_put_id; 26352217195SDaniel Vetter } 26452217195SDaniel Vetter connector->name = 26552217195SDaniel Vetter kasprintf(GFP_KERNEL, "%s-%d", 26652217195SDaniel Vetter drm_connector_enum_list[connector_type].name, 26752217195SDaniel Vetter connector->connector_type_id); 26852217195SDaniel Vetter if (!connector->name) { 26952217195SDaniel Vetter ret = -ENOMEM; 27052217195SDaniel Vetter goto out_put_type_id; 27152217195SDaniel Vetter } 27252217195SDaniel Vetter 273b11af8a2SMaxime Ripard /* provide ddc symlink in sysfs */ 274b11af8a2SMaxime Ripard connector->ddc = ddc; 275b11af8a2SMaxime Ripard 2763d3f7c1eSHans de Goede INIT_LIST_HEAD(&connector->global_connector_list_entry); 27752217195SDaniel Vetter INIT_LIST_HEAD(&connector->probed_modes); 27852217195SDaniel Vetter INIT_LIST_HEAD(&connector->modes); 279e73ab00eSDaniel Vetter mutex_init(&connector->mutex); 28090b575f5SJani Nikula mutex_init(&connector->edid_override_mutex); 28152217195SDaniel Vetter connector->edid_blob_ptr = NULL; 2825186421cSStanislav Lisovskiy connector->epoch_counter = 0; 2832de3a078SManasi Navare connector->tile_blob_ptr = NULL; 28452217195SDaniel Vetter connector->status = connector_status_unknown; 2858d70f395SHans de Goede connector->display_info.panel_orientation = 2868d70f395SHans de Goede DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 28752217195SDaniel Vetter 28852217195SDaniel Vetter drm_connector_get_cmdline_mode(connector); 28952217195SDaniel Vetter 29052217195SDaniel Vetter /* We should add connectors at the end to avoid upsetting the connector 291c2ce66daSBeatriz Martins de Carvalho * index too much. 292c2ce66daSBeatriz Martins de Carvalho */ 293613051daSDaniel Vetter spin_lock_irq(&config->connector_list_lock); 29452217195SDaniel Vetter list_add_tail(&connector->head, &config->connector_list); 29552217195SDaniel Vetter config->num_connector++; 296613051daSDaniel Vetter spin_unlock_irq(&config->connector_list_lock); 29752217195SDaniel Vetter 298935774cdSBrian Starkey if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL && 299935774cdSBrian Starkey connector_type != DRM_MODE_CONNECTOR_WRITEBACK) 3006b7e2d5cSGerd Hoffmann drm_connector_attach_edid_property(connector); 30152217195SDaniel Vetter 30252217195SDaniel Vetter drm_object_attach_property(&connector->base, 30352217195SDaniel Vetter config->dpms_property, 0); 30452217195SDaniel Vetter 30540ee6fbeSManasi Navare drm_object_attach_property(&connector->base, 30640ee6fbeSManasi Navare config->link_status_property, 30740ee6fbeSManasi Navare 0); 30840ee6fbeSManasi Navare 30966660d4cSDave Airlie drm_object_attach_property(&connector->base, 31066660d4cSDave Airlie config->non_desktop_property, 31166660d4cSDave Airlie 0); 3122de3a078SManasi Navare drm_object_attach_property(&connector->base, 3132de3a078SManasi Navare config->tile_property, 3142de3a078SManasi Navare 0); 31566660d4cSDave Airlie 31652217195SDaniel Vetter if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 31752217195SDaniel Vetter drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); 31852217195SDaniel Vetter } 31952217195SDaniel Vetter 32052217195SDaniel Vetter connector->debugfs_entry = NULL; 32152217195SDaniel Vetter out_put_type_id: 32252217195SDaniel Vetter if (ret) 323e5d6eeeaSBo Liu ida_free(connector_ida, connector->connector_type_id); 32452217195SDaniel Vetter out_put_id: 32552217195SDaniel Vetter if (ret) 326e5d6eeeaSBo Liu ida_free(&config->connector_ida, connector->index); 32752217195SDaniel Vetter out_put: 32852217195SDaniel Vetter if (ret) 32952217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 33052217195SDaniel Vetter 33152217195SDaniel Vetter return ret; 33252217195SDaniel Vetter } 333b11af8a2SMaxime Ripard 334b11af8a2SMaxime Ripard /** 335b11af8a2SMaxime Ripard * drm_connector_init - Init a preallocated connector 336b11af8a2SMaxime Ripard * @dev: DRM device 337b11af8a2SMaxime Ripard * @connector: the connector to init 338b11af8a2SMaxime Ripard * @funcs: callbacks for this connector 339b11af8a2SMaxime Ripard * @connector_type: user visible type of the connector 340b11af8a2SMaxime Ripard * 341b11af8a2SMaxime Ripard * Initialises a preallocated connector. Connectors should be 342b11af8a2SMaxime Ripard * subclassed as part of driver connector objects. 343b11af8a2SMaxime Ripard * 344b11af8a2SMaxime Ripard * At driver unload time the driver's &drm_connector_funcs.destroy hook 345b11af8a2SMaxime Ripard * should call drm_connector_cleanup() and free the connector structure. 346b11af8a2SMaxime Ripard * The connector structure should not be allocated with devm_kzalloc(). 347b11af8a2SMaxime Ripard * 34835a3b82fSMaxime Ripard * Note: consider using drmm_connector_init() instead of 34935a3b82fSMaxime Ripard * drm_connector_init() to let the DRM managed resource infrastructure 35035a3b82fSMaxime Ripard * take care of cleanup and deallocation. 35135a3b82fSMaxime Ripard * 352b11af8a2SMaxime Ripard * Returns: 353b11af8a2SMaxime Ripard * Zero on success, error code on failure. 354b11af8a2SMaxime Ripard */ 355b11af8a2SMaxime Ripard int drm_connector_init(struct drm_device *dev, 356b11af8a2SMaxime Ripard struct drm_connector *connector, 357b11af8a2SMaxime Ripard const struct drm_connector_funcs *funcs, 358b11af8a2SMaxime Ripard int connector_type) 359b11af8a2SMaxime Ripard { 360a961b197SMaxime Ripard if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) 361a961b197SMaxime Ripard return -EINVAL; 362a961b197SMaxime Ripard 363b11af8a2SMaxime Ripard return __drm_connector_init(dev, connector, funcs, connector_type, NULL); 364b11af8a2SMaxime Ripard } 36552217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init); 36652217195SDaniel Vetter 36752217195SDaniel Vetter /** 368100163dfSAndrzej Pietrasiewicz * drm_connector_init_with_ddc - Init a preallocated connector 369100163dfSAndrzej Pietrasiewicz * @dev: DRM device 370100163dfSAndrzej Pietrasiewicz * @connector: the connector to init 371100163dfSAndrzej Pietrasiewicz * @funcs: callbacks for this connector 372100163dfSAndrzej Pietrasiewicz * @connector_type: user visible type of the connector 373100163dfSAndrzej Pietrasiewicz * @ddc: pointer to the associated ddc adapter 374100163dfSAndrzej Pietrasiewicz * 375100163dfSAndrzej Pietrasiewicz * Initialises a preallocated connector. Connectors should be 376100163dfSAndrzej Pietrasiewicz * subclassed as part of driver connector objects. 377100163dfSAndrzej Pietrasiewicz * 37800ec947cSMaxime Ripard * At driver unload time the driver's &drm_connector_funcs.destroy hook 37900ec947cSMaxime Ripard * should call drm_connector_cleanup() and free the connector structure. 38000ec947cSMaxime Ripard * The connector structure should not be allocated with devm_kzalloc(). 38100ec947cSMaxime Ripard * 382100163dfSAndrzej Pietrasiewicz * Ensures that the ddc field of the connector is correctly set. 383100163dfSAndrzej Pietrasiewicz * 38435a3b82fSMaxime Ripard * Note: consider using drmm_connector_init() instead of 38535a3b82fSMaxime Ripard * drm_connector_init_with_ddc() to let the DRM managed resource 38635a3b82fSMaxime Ripard * infrastructure take care of cleanup and deallocation. 38735a3b82fSMaxime Ripard * 388100163dfSAndrzej Pietrasiewicz * Returns: 389100163dfSAndrzej Pietrasiewicz * Zero on success, error code on failure. 390100163dfSAndrzej Pietrasiewicz */ 391100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev, 392100163dfSAndrzej Pietrasiewicz struct drm_connector *connector, 393100163dfSAndrzej Pietrasiewicz const struct drm_connector_funcs *funcs, 394100163dfSAndrzej Pietrasiewicz int connector_type, 395100163dfSAndrzej Pietrasiewicz struct i2c_adapter *ddc) 396100163dfSAndrzej Pietrasiewicz { 397a961b197SMaxime Ripard if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) 398a961b197SMaxime Ripard return -EINVAL; 399a961b197SMaxime Ripard 400b11af8a2SMaxime Ripard return __drm_connector_init(dev, connector, funcs, connector_type, ddc); 401100163dfSAndrzej Pietrasiewicz } 402100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc); 403100163dfSAndrzej Pietrasiewicz 40435a3b82fSMaxime Ripard static void drm_connector_cleanup_action(struct drm_device *dev, 40535a3b82fSMaxime Ripard void *ptr) 40635a3b82fSMaxime Ripard { 40735a3b82fSMaxime Ripard struct drm_connector *connector = ptr; 40835a3b82fSMaxime Ripard 40935a3b82fSMaxime Ripard drm_connector_cleanup(connector); 41035a3b82fSMaxime Ripard } 41135a3b82fSMaxime Ripard 41235a3b82fSMaxime Ripard /** 41335a3b82fSMaxime Ripard * drmm_connector_init - Init a preallocated connector 41435a3b82fSMaxime Ripard * @dev: DRM device 41535a3b82fSMaxime Ripard * @connector: the connector to init 41635a3b82fSMaxime Ripard * @funcs: callbacks for this connector 41735a3b82fSMaxime Ripard * @connector_type: user visible type of the connector 41835a3b82fSMaxime Ripard * @ddc: optional pointer to the associated ddc adapter 41935a3b82fSMaxime Ripard * 42035a3b82fSMaxime Ripard * Initialises a preallocated connector. Connectors should be 42135a3b82fSMaxime Ripard * subclassed as part of driver connector objects. 42235a3b82fSMaxime Ripard * 42335a3b82fSMaxime Ripard * Cleanup is automatically handled with a call to 42435a3b82fSMaxime Ripard * drm_connector_cleanup() in a DRM-managed action. 42535a3b82fSMaxime Ripard * 42635a3b82fSMaxime Ripard * The connector structure should be allocated with drmm_kzalloc(). 42735a3b82fSMaxime Ripard * 42835a3b82fSMaxime Ripard * Returns: 42935a3b82fSMaxime Ripard * Zero on success, error code on failure. 43035a3b82fSMaxime Ripard */ 43135a3b82fSMaxime Ripard int drmm_connector_init(struct drm_device *dev, 43235a3b82fSMaxime Ripard struct drm_connector *connector, 43335a3b82fSMaxime Ripard const struct drm_connector_funcs *funcs, 43435a3b82fSMaxime Ripard int connector_type, 43535a3b82fSMaxime Ripard struct i2c_adapter *ddc) 43635a3b82fSMaxime Ripard { 43735a3b82fSMaxime Ripard int ret; 43835a3b82fSMaxime Ripard 43935a3b82fSMaxime Ripard if (drm_WARN_ON(dev, funcs && funcs->destroy)) 44035a3b82fSMaxime Ripard return -EINVAL; 44135a3b82fSMaxime Ripard 442a91e5e3eSMaxime Ripard ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc); 44335a3b82fSMaxime Ripard if (ret) 44435a3b82fSMaxime Ripard return ret; 44535a3b82fSMaxime Ripard 44635a3b82fSMaxime Ripard ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action, 44735a3b82fSMaxime Ripard connector); 44835a3b82fSMaxime Ripard if (ret) 44935a3b82fSMaxime Ripard return ret; 45035a3b82fSMaxime Ripard 45135a3b82fSMaxime Ripard return 0; 45235a3b82fSMaxime Ripard } 45335a3b82fSMaxime Ripard EXPORT_SYMBOL(drmm_connector_init); 45435a3b82fSMaxime Ripard 455100163dfSAndrzej Pietrasiewicz /** 4566b7e2d5cSGerd Hoffmann * drm_connector_attach_edid_property - attach edid property. 4576b7e2d5cSGerd Hoffmann * @connector: the connector 4586b7e2d5cSGerd Hoffmann * 4596b7e2d5cSGerd Hoffmann * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a 4606b7e2d5cSGerd Hoffmann * edid property attached by default. This function can be used to 4616b7e2d5cSGerd Hoffmann * explicitly enable the edid property in these cases. 4626b7e2d5cSGerd Hoffmann */ 4636b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector) 4646b7e2d5cSGerd Hoffmann { 4656b7e2d5cSGerd Hoffmann struct drm_mode_config *config = &connector->dev->mode_config; 4666b7e2d5cSGerd Hoffmann 4676b7e2d5cSGerd Hoffmann drm_object_attach_property(&connector->base, 4686b7e2d5cSGerd Hoffmann config->edid_property, 4696b7e2d5cSGerd Hoffmann 0); 4706b7e2d5cSGerd Hoffmann } 4716b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property); 4726b7e2d5cSGerd Hoffmann 4736b7e2d5cSGerd Hoffmann /** 474cde4c44dSDaniel Vetter * drm_connector_attach_encoder - attach a connector to an encoder 47552217195SDaniel Vetter * @connector: connector to attach 47652217195SDaniel Vetter * @encoder: encoder to attach @connector to 47752217195SDaniel Vetter * 47852217195SDaniel Vetter * This function links up a connector to an encoder. Note that the routing 47952217195SDaniel Vetter * restrictions between encoders and crtcs are exposed to userspace through the 48052217195SDaniel Vetter * possible_clones and possible_crtcs bitmasks. 48152217195SDaniel Vetter * 48252217195SDaniel Vetter * Returns: 48352217195SDaniel Vetter * Zero on success, negative errno on failure. 48452217195SDaniel Vetter */ 485cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector, 48652217195SDaniel Vetter struct drm_encoder *encoder) 48752217195SDaniel Vetter { 48852217195SDaniel Vetter /* 48952217195SDaniel Vetter * In the past, drivers have attempted to model the static association 49052217195SDaniel Vetter * of connector to encoder in simple connector/encoder devices using a 49152217195SDaniel Vetter * direct assignment of connector->encoder = encoder. This connection 49252217195SDaniel Vetter * is a logical one and the responsibility of the core, so drivers are 49352217195SDaniel Vetter * expected not to mess with this. 49452217195SDaniel Vetter * 49552217195SDaniel Vetter * Note that the error return should've been enough here, but a large 49652217195SDaniel Vetter * majority of drivers ignores the return value, so add in a big WARN 49752217195SDaniel Vetter * to get people's attention. 49852217195SDaniel Vetter */ 49952217195SDaniel Vetter if (WARN_ON(connector->encoder)) 50052217195SDaniel Vetter return -EINVAL; 50152217195SDaniel Vetter 50262afb4adSJosé Roberto de Souza connector->possible_encoders |= drm_encoder_mask(encoder); 50362afb4adSJosé Roberto de Souza 50452217195SDaniel Vetter return 0; 50552217195SDaniel Vetter } 506cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder); 50752217195SDaniel Vetter 50838cb8d96SVille Syrjälä /** 50962afb4adSJosé Roberto de Souza * drm_connector_has_possible_encoder - check if the connector and encoder are 51062afb4adSJosé Roberto de Souza * associated with each other 51138cb8d96SVille Syrjälä * @connector: the connector 51238cb8d96SVille Syrjälä * @encoder: the encoder 51338cb8d96SVille Syrjälä * 51438cb8d96SVille Syrjälä * Returns: 51538cb8d96SVille Syrjälä * True if @encoder is one of the possible encoders for @connector. 51638cb8d96SVille Syrjälä */ 51738cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector, 51838cb8d96SVille Syrjälä struct drm_encoder *encoder) 51938cb8d96SVille Syrjälä { 52062afb4adSJosé Roberto de Souza return connector->possible_encoders & drm_encoder_mask(encoder); 52138cb8d96SVille Syrjälä } 52238cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder); 52338cb8d96SVille Syrjälä 52452217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector, 52552217195SDaniel Vetter struct drm_display_mode *mode) 52652217195SDaniel Vetter { 52752217195SDaniel Vetter list_del(&mode->head); 52852217195SDaniel Vetter drm_mode_destroy(connector->dev, mode); 52952217195SDaniel Vetter } 53052217195SDaniel Vetter 53152217195SDaniel Vetter /** 53252217195SDaniel Vetter * drm_connector_cleanup - cleans up an initialised connector 53352217195SDaniel Vetter * @connector: connector to cleanup 53452217195SDaniel Vetter * 53552217195SDaniel Vetter * Cleans up the connector but doesn't free the object. 53652217195SDaniel Vetter */ 53752217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector) 53852217195SDaniel Vetter { 53952217195SDaniel Vetter struct drm_device *dev = connector->dev; 54052217195SDaniel Vetter struct drm_display_mode *mode, *t; 54152217195SDaniel Vetter 54252217195SDaniel Vetter /* The connector should have been removed from userspace long before 54352217195SDaniel Vetter * it is finally destroyed. 54452217195SDaniel Vetter */ 54539b50c60SLyude Paul if (WARN_ON(connector->registration_state == 54639b50c60SLyude Paul DRM_CONNECTOR_REGISTERED)) 54752217195SDaniel Vetter drm_connector_unregister(connector); 54852217195SDaniel Vetter 549334f74eeSHans de Goede if (connector->privacy_screen) { 550334f74eeSHans de Goede drm_privacy_screen_put(connector->privacy_screen); 551334f74eeSHans de Goede connector->privacy_screen = NULL; 552334f74eeSHans de Goede } 553334f74eeSHans de Goede 55452217195SDaniel Vetter if (connector->tile_group) { 55552217195SDaniel Vetter drm_mode_put_tile_group(dev, connector->tile_group); 55652217195SDaniel Vetter connector->tile_group = NULL; 55752217195SDaniel Vetter } 55852217195SDaniel Vetter 55952217195SDaniel Vetter list_for_each_entry_safe(mode, t, &connector->probed_modes, head) 56052217195SDaniel Vetter drm_mode_remove(connector, mode); 56152217195SDaniel Vetter 56252217195SDaniel Vetter list_for_each_entry_safe(mode, t, &connector->modes, head) 56352217195SDaniel Vetter drm_mode_remove(connector, mode); 56452217195SDaniel Vetter 565e5d6eeeaSBo Liu ida_free(&drm_connector_enum_list[connector->connector_type].ida, 56652217195SDaniel Vetter connector->connector_type_id); 56752217195SDaniel Vetter 568e5d6eeeaSBo Liu ida_free(&dev->mode_config.connector_ida, connector->index); 56952217195SDaniel Vetter 57052217195SDaniel Vetter kfree(connector->display_info.bus_formats); 571c3292ab5SJani Nikula kfree(connector->display_info.vics); 57252217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 57352217195SDaniel Vetter kfree(connector->name); 57452217195SDaniel Vetter connector->name = NULL; 57548c429c6SHans de Goede fwnode_handle_put(connector->fwnode); 57648c429c6SHans de Goede connector->fwnode = NULL; 577613051daSDaniel Vetter spin_lock_irq(&dev->mode_config.connector_list_lock); 57852217195SDaniel Vetter list_del(&connector->head); 57952217195SDaniel Vetter dev->mode_config.num_connector--; 580613051daSDaniel Vetter spin_unlock_irq(&dev->mode_config.connector_list_lock); 58152217195SDaniel Vetter 58252217195SDaniel Vetter WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); 58352217195SDaniel Vetter if (connector->state && connector->funcs->atomic_destroy_state) 58452217195SDaniel Vetter connector->funcs->atomic_destroy_state(connector, 58552217195SDaniel Vetter connector->state); 58652217195SDaniel Vetter 587e73ab00eSDaniel Vetter mutex_destroy(&connector->mutex); 588e73ab00eSDaniel Vetter 58952217195SDaniel Vetter memset(connector, 0, sizeof(*connector)); 5906fdc2d49SSimon Ser 5916fdc2d49SSimon Ser if (dev->registered) 5926fdc2d49SSimon Ser drm_sysfs_hotplug_event(dev); 59352217195SDaniel Vetter } 59452217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup); 59552217195SDaniel Vetter 59652217195SDaniel Vetter /** 59752217195SDaniel Vetter * drm_connector_register - register a connector 59852217195SDaniel Vetter * @connector: the connector to register 59952217195SDaniel Vetter * 60069b22f51SDaniel Vetter * Register userspace interfaces for a connector. Only call this for connectors 60169b22f51SDaniel Vetter * which can be hotplugged after drm_dev_register() has been called already, 60269b22f51SDaniel Vetter * e.g. DP MST connectors. All other connectors will be registered automatically 60369b22f51SDaniel Vetter * when calling drm_dev_register(). 60452217195SDaniel Vetter * 605d87fbea5SMaxime Ripard * When the connector is no longer available, callers must call 606d87fbea5SMaxime Ripard * drm_connector_unregister(). 607d87fbea5SMaxime Ripard * 60852217195SDaniel Vetter * Returns: 60952217195SDaniel Vetter * Zero on success, error code on failure. 61052217195SDaniel Vetter */ 61152217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector) 61252217195SDaniel Vetter { 613e73ab00eSDaniel Vetter int ret = 0; 61452217195SDaniel Vetter 615e6e7b48bSDaniel Vetter if (!connector->dev->registered) 616e6e7b48bSDaniel Vetter return 0; 617e6e7b48bSDaniel Vetter 618e73ab00eSDaniel Vetter mutex_lock(&connector->mutex); 61939b50c60SLyude Paul if (connector->registration_state != DRM_CONNECTOR_INITIALIZING) 620e73ab00eSDaniel Vetter goto unlock; 62152217195SDaniel Vetter 62252217195SDaniel Vetter ret = drm_sysfs_connector_add(connector); 62352217195SDaniel Vetter if (ret) 624e73ab00eSDaniel Vetter goto unlock; 62552217195SDaniel Vetter 626b792e640SGreg Kroah-Hartman drm_debugfs_connector_add(connector); 62752217195SDaniel Vetter 62852217195SDaniel Vetter if (connector->funcs->late_register) { 62952217195SDaniel Vetter ret = connector->funcs->late_register(connector); 63052217195SDaniel Vetter if (ret) 63152217195SDaniel Vetter goto err_debugfs; 63252217195SDaniel Vetter } 63352217195SDaniel Vetter 63452217195SDaniel Vetter drm_mode_object_register(connector->dev, &connector->base); 63552217195SDaniel Vetter 63639b50c60SLyude Paul connector->registration_state = DRM_CONNECTOR_REGISTERED; 637968d81a6SJeykumar Sankaran 638968d81a6SJeykumar Sankaran /* Let userspace know we have a new connector */ 639ad935754SSimon Ser drm_sysfs_connector_hotplug_event(connector); 640968d81a6SJeykumar Sankaran 641334f74eeSHans de Goede if (connector->privacy_screen) 642334f74eeSHans de Goede drm_privacy_screen_register_notifier(connector->privacy_screen, 643334f74eeSHans de Goede &connector->privacy_screen_notifier); 644334f74eeSHans de Goede 6453d3f7c1eSHans de Goede mutex_lock(&connector_list_lock); 6463d3f7c1eSHans de Goede list_add_tail(&connector->global_connector_list_entry, &connector_list); 6473d3f7c1eSHans de Goede mutex_unlock(&connector_list_lock); 648e73ab00eSDaniel Vetter goto unlock; 64952217195SDaniel Vetter 65052217195SDaniel Vetter err_debugfs: 65152217195SDaniel Vetter drm_debugfs_connector_remove(connector); 65252217195SDaniel Vetter drm_sysfs_connector_remove(connector); 653e73ab00eSDaniel Vetter unlock: 654e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 65552217195SDaniel Vetter return ret; 65652217195SDaniel Vetter } 65752217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register); 65852217195SDaniel Vetter 65952217195SDaniel Vetter /** 66052217195SDaniel Vetter * drm_connector_unregister - unregister a connector 66152217195SDaniel Vetter * @connector: the connector to unregister 66252217195SDaniel Vetter * 66369b22f51SDaniel Vetter * Unregister userspace interfaces for a connector. Only call this for 664d87fbea5SMaxime Ripard * connectors which have been registered explicitly by calling 665d87fbea5SMaxime Ripard * drm_connector_register(). 66652217195SDaniel Vetter */ 66752217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector) 66852217195SDaniel Vetter { 669e73ab00eSDaniel Vetter mutex_lock(&connector->mutex); 67039b50c60SLyude Paul if (connector->registration_state != DRM_CONNECTOR_REGISTERED) { 671e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 67252217195SDaniel Vetter return; 673e73ab00eSDaniel Vetter } 67452217195SDaniel Vetter 6753d3f7c1eSHans de Goede mutex_lock(&connector_list_lock); 6763d3f7c1eSHans de Goede list_del_init(&connector->global_connector_list_entry); 6773d3f7c1eSHans de Goede mutex_unlock(&connector_list_lock); 6783d3f7c1eSHans de Goede 679334f74eeSHans de Goede if (connector->privacy_screen) 680334f74eeSHans de Goede drm_privacy_screen_unregister_notifier( 681334f74eeSHans de Goede connector->privacy_screen, 682334f74eeSHans de Goede &connector->privacy_screen_notifier); 683334f74eeSHans de Goede 68452217195SDaniel Vetter if (connector->funcs->early_unregister) 68552217195SDaniel Vetter connector->funcs->early_unregister(connector); 68652217195SDaniel Vetter 68752217195SDaniel Vetter drm_sysfs_connector_remove(connector); 68852217195SDaniel Vetter drm_debugfs_connector_remove(connector); 68952217195SDaniel Vetter 69039b50c60SLyude Paul connector->registration_state = DRM_CONNECTOR_UNREGISTERED; 691e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 69252217195SDaniel Vetter } 69352217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister); 69452217195SDaniel Vetter 69552217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev) 69652217195SDaniel Vetter { 69752217195SDaniel Vetter struct drm_connector *connector; 698613051daSDaniel Vetter struct drm_connector_list_iter conn_iter; 69952217195SDaniel Vetter 700b982dab1SThierry Reding drm_connector_list_iter_begin(dev, &conn_iter); 701613051daSDaniel Vetter drm_for_each_connector_iter(connector, &conn_iter) 70252217195SDaniel Vetter drm_connector_unregister(connector); 703b982dab1SThierry Reding drm_connector_list_iter_end(&conn_iter); 70452217195SDaniel Vetter } 70552217195SDaniel Vetter 70652217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev) 70752217195SDaniel Vetter { 70852217195SDaniel Vetter struct drm_connector *connector; 709613051daSDaniel Vetter struct drm_connector_list_iter conn_iter; 710613051daSDaniel Vetter int ret = 0; 71152217195SDaniel Vetter 712b982dab1SThierry Reding drm_connector_list_iter_begin(dev, &conn_iter); 713613051daSDaniel Vetter drm_for_each_connector_iter(connector, &conn_iter) { 71452217195SDaniel Vetter ret = drm_connector_register(connector); 71552217195SDaniel Vetter if (ret) 716613051daSDaniel Vetter break; 71752217195SDaniel Vetter } 718b982dab1SThierry Reding drm_connector_list_iter_end(&conn_iter); 71952217195SDaniel Vetter 720613051daSDaniel Vetter if (ret) 72152217195SDaniel Vetter drm_connector_unregister_all(dev); 72252217195SDaniel Vetter return ret; 72352217195SDaniel Vetter } 72452217195SDaniel Vetter 72552217195SDaniel Vetter /** 72652217195SDaniel Vetter * drm_get_connector_status_name - return a string for connector status 72752217195SDaniel Vetter * @status: connector status to compute name of 72852217195SDaniel Vetter * 72952217195SDaniel Vetter * In contrast to the other drm_get_*_name functions this one here returns a 73052217195SDaniel Vetter * const pointer and hence is threadsafe. 731f85d9e59SRandy Dunlap * 732f85d9e59SRandy Dunlap * Returns: connector status string 73352217195SDaniel Vetter */ 73452217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status) 73552217195SDaniel Vetter { 73652217195SDaniel Vetter if (status == connector_status_connected) 73752217195SDaniel Vetter return "connected"; 73852217195SDaniel Vetter else if (status == connector_status_disconnected) 73952217195SDaniel Vetter return "disconnected"; 74052217195SDaniel Vetter else 74152217195SDaniel Vetter return "unknown"; 74252217195SDaniel Vetter } 74352217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name); 74452217195SDaniel Vetter 7456140cf20SJani Nikula /** 7466140cf20SJani Nikula * drm_get_connector_force_name - return a string for connector force 7476140cf20SJani Nikula * @force: connector force to get name of 7486140cf20SJani Nikula * 7496140cf20SJani Nikula * Returns: const pointer to name. 7506140cf20SJani Nikula */ 7516140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force) 7526140cf20SJani Nikula { 7536140cf20SJani Nikula switch (force) { 7546140cf20SJani Nikula case DRM_FORCE_UNSPECIFIED: 7556140cf20SJani Nikula return "unspecified"; 7566140cf20SJani Nikula case DRM_FORCE_OFF: 7576140cf20SJani Nikula return "off"; 7586140cf20SJani Nikula case DRM_FORCE_ON: 7596140cf20SJani Nikula return "on"; 7606140cf20SJani Nikula case DRM_FORCE_ON_DIGITAL: 7616140cf20SJani Nikula return "digital"; 7626140cf20SJani Nikula default: 7636140cf20SJani Nikula return "unknown"; 7646140cf20SJani Nikula } 7656140cf20SJani Nikula } 7666140cf20SJani Nikula 767613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP 768613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = { 769613051daSDaniel Vetter .name = "drm_connector_list_iter" 770613051daSDaniel Vetter }; 771613051daSDaniel Vetter #endif 772613051daSDaniel Vetter 773613051daSDaniel Vetter /** 774b982dab1SThierry Reding * drm_connector_list_iter_begin - initialize a connector_list iterator 775613051daSDaniel Vetter * @dev: DRM device 776613051daSDaniel Vetter * @iter: connector_list iterator 777613051daSDaniel Vetter * 778d574528aSDaniel Vetter * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter 779b982dab1SThierry Reding * must always be cleaned up again by calling drm_connector_list_iter_end(). 780613051daSDaniel Vetter * Iteration itself happens using drm_connector_list_iter_next() or 781613051daSDaniel Vetter * drm_for_each_connector_iter(). 782613051daSDaniel Vetter */ 783b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev, 784613051daSDaniel Vetter struct drm_connector_list_iter *iter) 785613051daSDaniel Vetter { 786613051daSDaniel Vetter iter->dev = dev; 787613051daSDaniel Vetter iter->conn = NULL; 788613051daSDaniel Vetter lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_); 789613051daSDaniel Vetter } 790b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin); 791613051daSDaniel Vetter 792a703c550SDaniel Vetter /* 793a703c550SDaniel Vetter * Extra-safe connector put function that works in any context. Should only be 794a703c550SDaniel Vetter * used from the connector_iter functions, where we never really expect to 795a703c550SDaniel Vetter * actually release the connector when dropping our final reference. 796a703c550SDaniel Vetter */ 797a703c550SDaniel Vetter static void 798ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn) 799a703c550SDaniel Vetter { 800ea497bb9SDaniel Vetter struct drm_mode_config *config = &conn->dev->mode_config; 801ea497bb9SDaniel Vetter 802ea497bb9SDaniel Vetter lockdep_assert_held(&config->connector_list_lock); 803ea497bb9SDaniel Vetter 804ea497bb9SDaniel Vetter if (!refcount_dec_and_test(&conn->base.refcount.refcount)) 805ea497bb9SDaniel Vetter return; 806ea497bb9SDaniel Vetter 807ea497bb9SDaniel Vetter llist_add(&conn->free_node, &config->connector_free_list); 808ea497bb9SDaniel Vetter schedule_work(&config->connector_free_work); 809a703c550SDaniel Vetter } 810a703c550SDaniel Vetter 811613051daSDaniel Vetter /** 812613051daSDaniel Vetter * drm_connector_list_iter_next - return next connector 8134f45c778SLyude Paul * @iter: connector_list iterator 814613051daSDaniel Vetter * 815f85d9e59SRandy Dunlap * Returns: the next connector for @iter, or NULL when the list walk has 816613051daSDaniel Vetter * completed. 817613051daSDaniel Vetter */ 818613051daSDaniel Vetter struct drm_connector * 819613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter) 820613051daSDaniel Vetter { 821613051daSDaniel Vetter struct drm_connector *old_conn = iter->conn; 822613051daSDaniel Vetter struct drm_mode_config *config = &iter->dev->mode_config; 823613051daSDaniel Vetter struct list_head *lhead; 824613051daSDaniel Vetter unsigned long flags; 825613051daSDaniel Vetter 826613051daSDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 827613051daSDaniel Vetter lhead = old_conn ? &old_conn->head : &config->connector_list; 828613051daSDaniel Vetter 829613051daSDaniel Vetter do { 830613051daSDaniel Vetter if (lhead->next == &config->connector_list) { 831613051daSDaniel Vetter iter->conn = NULL; 832613051daSDaniel Vetter break; 833613051daSDaniel Vetter } 834613051daSDaniel Vetter 835613051daSDaniel Vetter lhead = lhead->next; 836613051daSDaniel Vetter iter->conn = list_entry(lhead, struct drm_connector, head); 837613051daSDaniel Vetter 838613051daSDaniel Vetter /* loop until it's not a zombie connector */ 839613051daSDaniel Vetter } while (!kref_get_unless_zero(&iter->conn->base.refcount)); 840613051daSDaniel Vetter 841613051daSDaniel Vetter if (old_conn) 842ea497bb9SDaniel Vetter __drm_connector_put_safe(old_conn); 843ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 844613051daSDaniel Vetter 845613051daSDaniel Vetter return iter->conn; 846613051daSDaniel Vetter } 847613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next); 848613051daSDaniel Vetter 849613051daSDaniel Vetter /** 850b982dab1SThierry Reding * drm_connector_list_iter_end - tear down a connector_list iterator 851613051daSDaniel Vetter * @iter: connector_list iterator 852613051daSDaniel Vetter * 853613051daSDaniel Vetter * Tears down @iter and releases any resources (like &drm_connector references) 854613051daSDaniel Vetter * acquired while walking the list. This must always be called, both when the 855613051daSDaniel Vetter * iteration completes fully or when it was aborted without walking the entire 856613051daSDaniel Vetter * list. 857613051daSDaniel Vetter */ 858b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter) 859613051daSDaniel Vetter { 860ea497bb9SDaniel Vetter struct drm_mode_config *config = &iter->dev->mode_config; 861ea497bb9SDaniel Vetter unsigned long flags; 862ea497bb9SDaniel Vetter 863613051daSDaniel Vetter iter->dev = NULL; 864ea497bb9SDaniel Vetter if (iter->conn) { 865ea497bb9SDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 866ea497bb9SDaniel Vetter __drm_connector_put_safe(iter->conn); 867ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 868ea497bb9SDaniel Vetter } 8695facae4fSQian Cai lock_release(&connector_list_iter_dep_map, _RET_IP_); 870613051daSDaniel Vetter } 871b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end); 872613051daSDaniel Vetter 87352217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { 87452217195SDaniel Vetter { SubPixelUnknown, "Unknown" }, 87552217195SDaniel Vetter { SubPixelHorizontalRGB, "Horizontal RGB" }, 87652217195SDaniel Vetter { SubPixelHorizontalBGR, "Horizontal BGR" }, 87752217195SDaniel Vetter { SubPixelVerticalRGB, "Vertical RGB" }, 87852217195SDaniel Vetter { SubPixelVerticalBGR, "Vertical BGR" }, 87952217195SDaniel Vetter { SubPixelNone, "None" }, 88052217195SDaniel Vetter }; 88152217195SDaniel Vetter 88252217195SDaniel Vetter /** 88352217195SDaniel Vetter * drm_get_subpixel_order_name - return a string for a given subpixel enum 88452217195SDaniel Vetter * @order: enum of subpixel_order 88552217195SDaniel Vetter * 88652217195SDaniel Vetter * Note you could abuse this and return something out of bounds, but that 88752217195SDaniel Vetter * would be a caller error. No unscrubbed user data should make it here. 888f85d9e59SRandy Dunlap * 889f85d9e59SRandy Dunlap * Returns: string describing an enumerated subpixel property 89052217195SDaniel Vetter */ 89152217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order) 89252217195SDaniel Vetter { 89352217195SDaniel Vetter return drm_subpixel_enum_list[order].name; 89452217195SDaniel Vetter } 89552217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name); 89652217195SDaniel Vetter 89752217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = { 89852217195SDaniel Vetter { DRM_MODE_DPMS_ON, "On" }, 89952217195SDaniel Vetter { DRM_MODE_DPMS_STANDBY, "Standby" }, 90052217195SDaniel Vetter { DRM_MODE_DPMS_SUSPEND, "Suspend" }, 90152217195SDaniel Vetter { DRM_MODE_DPMS_OFF, "Off" } 90252217195SDaniel Vetter }; 90352217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) 90452217195SDaniel Vetter 90540ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = { 90640ee6fbeSManasi Navare { DRM_MODE_LINK_STATUS_GOOD, "Good" }, 90740ee6fbeSManasi Navare { DRM_MODE_LINK_STATUS_BAD, "Bad" }, 90840ee6fbeSManasi Navare }; 90940ee6fbeSManasi Navare 910b3c6c8bfSDaniel Vetter /** 911b3c6c8bfSDaniel Vetter * drm_display_info_set_bus_formats - set the supported bus formats 912b3c6c8bfSDaniel Vetter * @info: display info to store bus formats in 913b3c6c8bfSDaniel Vetter * @formats: array containing the supported bus formats 914b3c6c8bfSDaniel Vetter * @num_formats: the number of entries in the fmts array 915b3c6c8bfSDaniel Vetter * 916b3c6c8bfSDaniel Vetter * Store the supported bus formats in display info structure. 917b3c6c8bfSDaniel Vetter * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for 918b3c6c8bfSDaniel Vetter * a full list of available formats. 919f85d9e59SRandy Dunlap * 920f85d9e59SRandy Dunlap * Returns: 921f85d9e59SRandy Dunlap * 0 on success or a negative error code on failure. 922b3c6c8bfSDaniel Vetter */ 923b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info, 924b3c6c8bfSDaniel Vetter const u32 *formats, 925b3c6c8bfSDaniel Vetter unsigned int num_formats) 926b3c6c8bfSDaniel Vetter { 927b3c6c8bfSDaniel Vetter u32 *fmts = NULL; 928b3c6c8bfSDaniel Vetter 929b3c6c8bfSDaniel Vetter if (!formats && num_formats) 930b3c6c8bfSDaniel Vetter return -EINVAL; 931b3c6c8bfSDaniel Vetter 932b3c6c8bfSDaniel Vetter if (formats && num_formats) { 933b3c6c8bfSDaniel Vetter fmts = kmemdup(formats, sizeof(*formats) * num_formats, 934b3c6c8bfSDaniel Vetter GFP_KERNEL); 935b3c6c8bfSDaniel Vetter if (!fmts) 936b3c6c8bfSDaniel Vetter return -ENOMEM; 937b3c6c8bfSDaniel Vetter } 938b3c6c8bfSDaniel Vetter 939b3c6c8bfSDaniel Vetter kfree(info->bus_formats); 940b3c6c8bfSDaniel Vetter info->bus_formats = fmts; 941b3c6c8bfSDaniel Vetter info->num_bus_formats = num_formats; 942b3c6c8bfSDaniel Vetter 943b3c6c8bfSDaniel Vetter return 0; 944b3c6c8bfSDaniel Vetter } 945b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats); 946b3c6c8bfSDaniel Vetter 94752217195SDaniel Vetter /* Optional connector properties. */ 94852217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { 94952217195SDaniel Vetter { DRM_MODE_SCALE_NONE, "None" }, 95052217195SDaniel Vetter { DRM_MODE_SCALE_FULLSCREEN, "Full" }, 95152217195SDaniel Vetter { DRM_MODE_SCALE_CENTER, "Center" }, 95252217195SDaniel Vetter { DRM_MODE_SCALE_ASPECT, "Full aspect" }, 95352217195SDaniel Vetter }; 95452217195SDaniel Vetter 95552217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { 95652217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, 95752217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, 95852217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, 95952217195SDaniel Vetter }; 96052217195SDaniel Vetter 96150525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = { 96250525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" }, 96350525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" }, 96450525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" }, 96550525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" }, 96650525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_GAME, "Game" }, 96750525c33SStanislav Lisovskiy }; 96850525c33SStanislav Lisovskiy 9698d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = { 9708d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" }, 9718d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" }, 9728d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" }, 9738d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" }, 9748d70f395SHans de Goede }; 9758d70f395SHans de Goede 97652217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { 97752217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 97852217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 97952217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 98052217195SDaniel Vetter }; 98152217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) 98252217195SDaniel Vetter 98352217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { 984e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 98552217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 98652217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 98752217195SDaniel Vetter }; 98852217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, 98952217195SDaniel Vetter drm_dvi_i_subconnector_enum_list) 99052217195SDaniel Vetter 9917d63cd85SMaxime Ripard static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = { 9927d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_NTSC, "NTSC" }, 9937d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" }, 9947d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" }, 9957d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_PAL, "PAL" }, 9967d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_PAL_M, "PAL-M" }, 9977d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_PAL_N, "PAL-N" }, 9987d63cd85SMaxime Ripard { DRM_MODE_TV_MODE_SECAM, "SECAM" }, 9997d63cd85SMaxime Ripard }; 10007d63cd85SMaxime Ripard DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list) 10017d63cd85SMaxime Ripard 1002d4613e3eSMaxime Ripard /** 1003d4613e3eSMaxime Ripard * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value 1004d4613e3eSMaxime Ripard * @name: TV Mode name we want to convert 1005d4613e3eSMaxime Ripard * @len: Length of @name 1006d4613e3eSMaxime Ripard * 1007d4613e3eSMaxime Ripard * Translates @name into an enum drm_connector_tv_mode. 1008d4613e3eSMaxime Ripard * 1009d4613e3eSMaxime Ripard * Returns: the enum value on success, a negative errno otherwise. 1010d4613e3eSMaxime Ripard */ 1011d4613e3eSMaxime Ripard int drm_get_tv_mode_from_name(const char *name, size_t len) 1012d4613e3eSMaxime Ripard { 1013d4613e3eSMaxime Ripard unsigned int i; 1014d4613e3eSMaxime Ripard 1015d4613e3eSMaxime Ripard for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) { 1016d4613e3eSMaxime Ripard const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i]; 1017d4613e3eSMaxime Ripard 1018d4613e3eSMaxime Ripard if (strlen(item->name) == len && !strncmp(item->name, name, len)) 1019d4613e3eSMaxime Ripard return item->type; 1020d4613e3eSMaxime Ripard } 1021d4613e3eSMaxime Ripard 1022d4613e3eSMaxime Ripard return -EINVAL; 1023d4613e3eSMaxime Ripard } 1024d4613e3eSMaxime Ripard EXPORT_SYMBOL(drm_get_tv_mode_from_name); 1025d4613e3eSMaxime Ripard 102652217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { 102752217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 102852217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 102952217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 103052217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 103152217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 103252217195SDaniel Vetter }; 103352217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) 103452217195SDaniel Vetter 103552217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { 1036e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 103752217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 103852217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 103952217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 104052217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 104152217195SDaniel Vetter }; 104252217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, 104352217195SDaniel Vetter drm_tv_subconnector_enum_list) 104452217195SDaniel Vetter 1045e5b92773SOleg Vasilev static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = { 1046e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 1047e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */ 1048e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */ 1049e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */ 1050e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */ 1051e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */ 1052e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */ 1053e5b92773SOleg Vasilev }; 1054e5b92773SOleg Vasilev 1055e5b92773SOleg Vasilev DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name, 1056e5b92773SOleg Vasilev drm_dp_subconnector_enum_list) 1057e5b92773SOleg Vasilev 1058c627087cSHarry Wentland 1059c627087cSHarry Wentland static const char * const colorspace_names[] = { 1060d2c6a405SUma Shankar /* For Default case, driver will set the colorspace */ 1061c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_DEFAULT] = "Default", 1062d2c6a405SUma Shankar /* Standard Definition Colorimetry based on CEA 861 */ 1063c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC", 1064c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC", 1065d2c6a405SUma Shankar /* Standard Definition Colorimetry based on IEC 61966-2-4 */ 1066c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601", 1067d2c6a405SUma Shankar /* High Definition Colorimetry based on IEC 61966-2-4 */ 1068c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709", 1069d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-1/Amendment 1 */ 1070c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601", 1071d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-5 [33] */ 1072c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601", 1073d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-5 */ 1074c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_OPRGB] = "opRGB", 1075d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 1076c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC", 1077d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 1078c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB", 1079d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 1080c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC", 1081d2c6a405SUma Shankar /* Added as part of Additional Colorimetry Extension in 861.G */ 1082c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65", 1083c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater", 1084c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED", 1085c627087cSHarry Wentland /* Colorimetry based on scRGB (IEC 61966-2-2) */ 1086c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT", 1087c627087cSHarry Wentland [DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC", 1088d2c6a405SUma Shankar }; 1089d2c6a405SUma Shankar 1090035d53e0SHarry Wentland /** 1091035d53e0SHarry Wentland * drm_get_colorspace_name - return a string for color encoding 1092035d53e0SHarry Wentland * @colorspace: color space to compute name of 1093035d53e0SHarry Wentland * 1094035d53e0SHarry Wentland * In contrast to the other drm_get_*_name functions this one here returns a 1095035d53e0SHarry Wentland * const pointer and hence is threadsafe. 1096035d53e0SHarry Wentland */ 1097035d53e0SHarry Wentland const char *drm_get_colorspace_name(enum drm_colorspace colorspace) 1098035d53e0SHarry Wentland { 1099035d53e0SHarry Wentland if (colorspace < ARRAY_SIZE(colorspace_names) && colorspace_names[colorspace]) 1100035d53e0SHarry Wentland return colorspace_names[colorspace]; 1101035d53e0SHarry Wentland else 1102035d53e0SHarry Wentland return "(null)"; 1103035d53e0SHarry Wentland } 1104035d53e0SHarry Wentland 1105c627087cSHarry Wentland static const u32 hdmi_colorspaces = 1106c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) | 1107c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT709_YCC) | 1108c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_XVYCC_601) | 1109c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_XVYCC_709) | 1110c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_SYCC_601) | 1111c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_OPYCC_601) | 1112c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_OPRGB) | 1113c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) | 1114c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | 1115c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) | 1116c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) | 1117c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER); 1118c627087cSHarry Wentland 111945cf0e91SGwan-gyeong Mun /* 112045cf0e91SGwan-gyeong Mun * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry 112145cf0e91SGwan-gyeong Mun * Format Table 2-120 112245cf0e91SGwan-gyeong Mun */ 1123c627087cSHarry Wentland static const u32 dp_colorspaces = 1124c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) | 1125c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) | 1126c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_OPRGB) | 1127c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) | 1128c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | 1129c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT601_YCC) | 1130c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT709_YCC) | 1131c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_XVYCC_601) | 1132c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_XVYCC_709) | 1133c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_SYCC_601) | 1134c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_OPYCC_601) | 1135c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) | 1136c627087cSHarry Wentland BIT(DRM_MODE_COLORIMETRY_BT2020_YCC); 113745cf0e91SGwan-gyeong Mun 11384ada6f22SDaniel Vetter /** 11394ada6f22SDaniel Vetter * DOC: standard connector properties 11404ada6f22SDaniel Vetter * 11414ada6f22SDaniel Vetter * DRM connectors have a few standardized properties: 11424ada6f22SDaniel Vetter * 11434ada6f22SDaniel Vetter * EDID: 11444ada6f22SDaniel Vetter * Blob property which contains the current EDID read from the sink. This 11454ada6f22SDaniel Vetter * is useful to parse sink identification information like vendor, model 11464ada6f22SDaniel Vetter * and serial. Drivers should update this property by calling 1147c555f023SDaniel Vetter * drm_connector_update_edid_property(), usually after having parsed 11484ada6f22SDaniel Vetter * the EDID using drm_add_edid_modes(). Userspace cannot change this 11494ada6f22SDaniel Vetter * property. 115012767469SSimon Ser * 115112767469SSimon Ser * User-space should not parse the EDID to obtain information exposed via 115212767469SSimon Ser * other KMS properties (because the kernel might apply limits, quirks or 115312767469SSimon Ser * fixups to the EDID). For instance, user-space should not try to parse 115412767469SSimon Ser * mode lists from the EDID. 11554ada6f22SDaniel Vetter * DPMS: 11564ada6f22SDaniel Vetter * Legacy property for setting the power state of the connector. For atomic 11574ada6f22SDaniel Vetter * drivers this is only provided for backwards compatibility with existing 11584ada6f22SDaniel Vetter * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the 11594ada6f22SDaniel Vetter * connector is linked to. Drivers should never set this property directly, 1160d574528aSDaniel Vetter * it is handled by the DRM core by calling the &drm_connector_funcs.dpms 1161144a7999SDaniel Vetter * callback. For atomic drivers the remapping to the "ACTIVE" property is 11621e3e4caeSSimon Ser * implemented in the DRM core. 1163d0d1aee5SDaniel Vetter * 1164d0d1aee5SDaniel Vetter * Note that this property cannot be set through the MODE_ATOMIC ioctl, 1165d0d1aee5SDaniel Vetter * userspace must use "ACTIVE" on the CRTC instead. 1166d0d1aee5SDaniel Vetter * 1167d0d1aee5SDaniel Vetter * WARNING: 1168d0d1aee5SDaniel Vetter * 1169d0d1aee5SDaniel Vetter * For userspace also running on legacy drivers the "DPMS" semantics are a 1170d0d1aee5SDaniel Vetter * lot more complicated. First, userspace cannot rely on the "DPMS" value 1171d0d1aee5SDaniel Vetter * returned by the GETCONNECTOR actually reflecting reality, because many 1172d0d1aee5SDaniel Vetter * drivers fail to update it. For atomic drivers this is taken care of in 1173d0d1aee5SDaniel Vetter * drm_atomic_helper_update_legacy_modeset_state(). 1174d0d1aee5SDaniel Vetter * 1175d0d1aee5SDaniel Vetter * The second issue is that the DPMS state is only well-defined when the 1176d0d1aee5SDaniel Vetter * connector is connected to a CRTC. In atomic the DRM core enforces that 1177d0d1aee5SDaniel Vetter * "ACTIVE" is off in such a case, no such checks exists for "DPMS". 1178d0d1aee5SDaniel Vetter * 1179d0d1aee5SDaniel Vetter * Finally, when enabling an output using the legacy SETCONFIG ioctl then 1180d0d1aee5SDaniel Vetter * "DPMS" is forced to ON. But see above, that might not be reflected in 1181d0d1aee5SDaniel Vetter * the software value on legacy drivers. 1182d0d1aee5SDaniel Vetter * 1183d0d1aee5SDaniel Vetter * Summarizing: Only set "DPMS" when the connector is known to be enabled, 1184d0d1aee5SDaniel Vetter * assume that a successful SETCONFIG call also sets "DPMS" to on, and 1185d0d1aee5SDaniel Vetter * never read back the value of "DPMS" because it can be incorrect. 11864ada6f22SDaniel Vetter * PATH: 11874ada6f22SDaniel Vetter * Connector path property to identify how this sink is physically 11884ada6f22SDaniel Vetter * connected. Used by DP MST. This should be set by calling 118997e14fbeSDaniel Vetter * drm_connector_set_path_property(), in the case of DP MST with the 11904ada6f22SDaniel Vetter * path property the MST manager created. Userspace cannot change this 11914ada6f22SDaniel Vetter * property. 11924ada6f22SDaniel Vetter * TILE: 11934ada6f22SDaniel Vetter * Connector tile group property to indicate how a set of DRM connector 11944ada6f22SDaniel Vetter * compose together into one logical screen. This is used by both high-res 11954ada6f22SDaniel Vetter * external screens (often only using a single cable, but exposing multiple 11964ada6f22SDaniel Vetter * DP MST sinks), or high-res integrated panels (like dual-link DSI) which 11974ada6f22SDaniel Vetter * are not gen-locked. Note that for tiled panels which are genlocked, like 11984ada6f22SDaniel Vetter * dual-link LVDS or dual-link DSI, the driver should try to not expose the 119984e543bcSAntonio Borneo * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers 120097e14fbeSDaniel Vetter * should update this value using drm_connector_set_tile_property(). 12014ada6f22SDaniel Vetter * Userspace cannot change this property. 120240ee6fbeSManasi Navare * link-status: 1203716719a3SSean Paul * Connector link-status property to indicate the status of link. The 1204716719a3SSean Paul * default value of link-status is "GOOD". If something fails during or 1205716719a3SSean Paul * after modeset, the kernel driver may set this to "BAD" and issue a 1206716719a3SSean Paul * hotplug uevent. Drivers should update this value using 120797e14fbeSDaniel Vetter * drm_connector_set_link_status_property(). 1208a66da873SSimon Ser * 1209a66da873SSimon Ser * When user-space receives the hotplug uevent and detects a "BAD" 1210a66da873SSimon Ser * link-status, the sink doesn't receive pixels anymore (e.g. the screen 1211a66da873SSimon Ser * becomes completely black). The list of available modes may have 1212a66da873SSimon Ser * changed. User-space is expected to pick a new mode if the current one 1213a66da873SSimon Ser * has disappeared and perform a new modeset with link-status set to 1214a66da873SSimon Ser * "GOOD" to re-enable the connector. 1215a66da873SSimon Ser * 1216a66da873SSimon Ser * If multiple connectors share the same CRTC and one of them gets a "BAD" 1217a66da873SSimon Ser * link-status, the other are unaffected (ie. the sinks still continue to 1218a66da873SSimon Ser * receive pixels). 1219a66da873SSimon Ser * 1220a66da873SSimon Ser * When user-space performs an atomic commit on a connector with a "BAD" 1221a66da873SSimon Ser * link-status without resetting the property to "GOOD", the sink may 1222a66da873SSimon Ser * still not receive pixels. When user-space performs an atomic commit 1223a66da873SSimon Ser * which resets the link-status property to "GOOD" without the 1224a66da873SSimon Ser * ALLOW_MODESET flag set, it might fail because a modeset is required. 1225a66da873SSimon Ser * 1226a66da873SSimon Ser * User-space can only change link-status to "GOOD", changing it to "BAD" 1227a66da873SSimon Ser * is a no-op. 1228a66da873SSimon Ser * 1229a66da873SSimon Ser * For backwards compatibility with non-atomic userspace the kernel 1230a66da873SSimon Ser * tries to automatically set the link-status back to "GOOD" in the 1231a66da873SSimon Ser * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar 1232a66da873SSimon Ser * to how it might fail if a different screen has been connected in the 1233a66da873SSimon Ser * interim. 123466660d4cSDave Airlie * non_desktop: 123566660d4cSDave Airlie * Indicates the output should be ignored for purposes of displaying a 123666660d4cSDave Airlie * standard desktop environment or console. This is most likely because 123766660d4cSDave Airlie * the output device is not rectilinear. 123824557865SSean Paul * Content Protection: 123924557865SSean Paul * This property is used by userspace to request the kernel protect future 124024557865SSean Paul * content communicated over the link. When requested, kernel will apply 124124557865SSean Paul * the appropriate means of protection (most often HDCP), and use the 124224557865SSean Paul * property to tell userspace the protection is active. 124324557865SSean Paul * 124424557865SSean Paul * Drivers can set this up by calling 124524557865SSean Paul * drm_connector_attach_content_protection_property() on initialization. 124624557865SSean Paul * 124724557865SSean Paul * The value of this property can be one of the following: 124824557865SSean Paul * 1249bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0 125024557865SSean Paul * The link is not protected, content is transmitted in the clear. 1251bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1 125224557865SSean Paul * Userspace has requested content protection, but the link is not 125324557865SSean Paul * currently protected. When in this state, kernel should enable 125424557865SSean Paul * Content Protection as soon as possible. 1255bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2 125624557865SSean Paul * Userspace has requested content protection, and the link is 125724557865SSean Paul * protected. Only the driver can set the property to this value. 125824557865SSean Paul * If userspace attempts to set to ENABLED, kernel will return 125924557865SSean Paul * -EINVAL. 126024557865SSean Paul * 126124557865SSean Paul * A few guidelines: 126224557865SSean Paul * 126324557865SSean Paul * - DESIRED state should be preserved until userspace de-asserts it by 126424557865SSean Paul * setting the property to UNDESIRED. This means ENABLED should only 126524557865SSean Paul * transition to UNDESIRED when the user explicitly requests it. 126624557865SSean Paul * - If the state is DESIRED, kernel should attempt to re-authenticate the 126724557865SSean Paul * link whenever possible. This includes across disable/enable, dpms, 126824557865SSean Paul * hotplug, downstream device changes, link status failures, etc.. 1269bb5a45d4SRamalingam C * - Kernel sends uevent with the connector id and property id through 1270bb5a45d4SRamalingam C * @drm_hdcp_update_content_protection, upon below kernel triggered 1271bb5a45d4SRamalingam C * scenarios: 127212db36bcSSean Paul * 127312db36bcSSean Paul * - DESIRED -> ENABLED (authentication success) 127412db36bcSSean Paul * - ENABLED -> DESIRED (termination of authentication) 1275bb5a45d4SRamalingam C * - Please note no uevents for userspace triggered property state changes, 1276bb5a45d4SRamalingam C * which can't fail such as 127712db36bcSSean Paul * 127812db36bcSSean Paul * - DESIRED/ENABLED -> UNDESIRED 127912db36bcSSean Paul * - UNDESIRED -> DESIRED 1280bb5a45d4SRamalingam C * - Userspace is responsible for polling the property or listen to uevents 1281bb5a45d4SRamalingam C * to determine when the value transitions from ENABLED to DESIRED. 1282bb5a45d4SRamalingam C * This signifies the link is no longer protected and userspace should 1283bb5a45d4SRamalingam C * take appropriate action (whatever that might be). 12844ada6f22SDaniel Vetter * 12857672dbbaSRamalingam C * HDCP Content Type: 12867672dbbaSRamalingam C * This Enum property is used by the userspace to declare the content type 12877672dbbaSRamalingam C * of the display stream, to kernel. Here display stream stands for any 12887672dbbaSRamalingam C * display content that userspace intended to display through HDCP 12897672dbbaSRamalingam C * encryption. 12907672dbbaSRamalingam C * 12917672dbbaSRamalingam C * Content Type of a stream is decided by the owner of the stream, as 12927672dbbaSRamalingam C * "HDCP Type0" or "HDCP Type1". 12937672dbbaSRamalingam C * 12947672dbbaSRamalingam C * The value of the property can be one of the below: 12957672dbbaSRamalingam C * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0 12967672dbbaSRamalingam C * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1 12977672dbbaSRamalingam C * 12987672dbbaSRamalingam C * When kernel starts the HDCP authentication (see "Content Protection" 12997672dbbaSRamalingam C * for details), it uses the content type in "HDCP Content Type" 13007672dbbaSRamalingam C * for performing the HDCP authentication with the display sink. 13017672dbbaSRamalingam C * 13027672dbbaSRamalingam C * Please note in HDCP spec versions, a link can be authenticated with 13037672dbbaSRamalingam C * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be 13047672dbbaSRamalingam C * authenticated with HDCP1.4 only for Content Type 0(though it is implicit 13057672dbbaSRamalingam C * in nature. As there is no reference for Content Type in HDCP1.4). 13067672dbbaSRamalingam C * 13077672dbbaSRamalingam C * HDCP2.2 authentication protocol itself takes the "Content Type" as a 13087672dbbaSRamalingam C * parameter, which is a input for the DP HDCP2.2 encryption algo. 13097672dbbaSRamalingam C * 13107672dbbaSRamalingam C * In case of Type 0 content protection request, kernel driver can choose 13117672dbbaSRamalingam C * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for 13127672dbbaSRamalingam C * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send 13137672dbbaSRamalingam C * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link). 13147672dbbaSRamalingam C * But if the content is classified as "HDCP Type 1", above mentioned 13157672dbbaSRamalingam C * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't 13167672dbbaSRamalingam C * authenticate the HDCP1.4 capable sink for "HDCP Type 1". 13177672dbbaSRamalingam C * 13187672dbbaSRamalingam C * Please note userspace can be ignorant of the HDCP versions used by the 13197672dbbaSRamalingam C * kernel driver to achieve the "HDCP Content Type". 13207672dbbaSRamalingam C * 13217672dbbaSRamalingam C * At current scenario, classifying a content as Type 1 ensures that the 13227672dbbaSRamalingam C * content will be displayed only through the HDCP2.2 encrypted link. 13237672dbbaSRamalingam C * 13247672dbbaSRamalingam C * Note that the HDCP Content Type property is introduced at HDCP 2.2, and 13257672dbbaSRamalingam C * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2 13267672dbbaSRamalingam C * (hence supporting Type 0 and Type 1). Based on how next versions of 13277672dbbaSRamalingam C * HDCP specs are defined content Type could be used for higher versions 13287672dbbaSRamalingam C * too. 13297672dbbaSRamalingam C * 13307672dbbaSRamalingam C * If content type is changed when "Content Protection" is not UNDESIRED, 13317672dbbaSRamalingam C * then kernel will disable the HDCP and re-enable with new type in the 13327672dbbaSRamalingam C * same atomic commit. And when "Content Protection" is ENABLED, it means 13337672dbbaSRamalingam C * that link is HDCP authenticated and encrypted, for the transmission of 13347672dbbaSRamalingam C * the Type of stream mentioned at "HDCP Content Type". 13357672dbbaSRamalingam C * 1336a09db883SUma Shankar * HDR_OUTPUT_METADATA: 1337a09db883SUma Shankar * Connector property to enable userspace to send HDR Metadata to 1338a09db883SUma Shankar * driver. This metadata is based on the composition and blending 1339a09db883SUma Shankar * policies decided by user, taking into account the hardware and 1340a09db883SUma Shankar * sink capabilities. The driver gets this metadata and creates a 1341a09db883SUma Shankar * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI, 1342a09db883SUma Shankar * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then 1343a09db883SUma Shankar * sent to sink. This notifies the sink of the upcoming frame's Color 1344a09db883SUma Shankar * Encoding and Luminance parameters. 1345a09db883SUma Shankar * 1346a09db883SUma Shankar * Userspace first need to detect the HDR capabilities of sink by 1347a09db883SUma Shankar * reading and parsing the EDID. Details of HDR metadata for HDMI 1348a09db883SUma Shankar * are added in CTA 861.G spec. For DP , its defined in VESA DP 1349a09db883SUma Shankar * Standard v1.4. It needs to then get the metadata information 1350a09db883SUma Shankar * of the video/game/app content which are encoded in HDR (basically 1351a09db883SUma Shankar * using HDR transfer functions). With this information it needs to 1352a09db883SUma Shankar * decide on a blending policy and compose the relevant 1353a09db883SUma Shankar * layers/overlays into a common format. Once this blending is done, 1354a09db883SUma Shankar * userspace will be aware of the metadata of the composed frame to 1355a09db883SUma Shankar * be send to sink. It then uses this property to communicate this 1356a09db883SUma Shankar * metadata to driver which then make a Infoframe packet and sends 1357a09db883SUma Shankar * to sink based on the type of encoder connected. 1358a09db883SUma Shankar * 1359a09db883SUma Shankar * Userspace will be responsible to do Tone mapping operation in case: 1360a09db883SUma Shankar * - Some layers are HDR and others are SDR 1361a09db883SUma Shankar * - HDR layers luminance is not same as sink 13629f9b2559SSean Paul * 1363a09db883SUma Shankar * It will even need to do colorspace conversion and get all layers 1364a09db883SUma Shankar * to one common colorspace for blending. It can use either GL, Media 136584e543bcSAntonio Borneo * or display engine to get this done based on the capabilities of the 1366a09db883SUma Shankar * associated hardware. 1367a09db883SUma Shankar * 1368a09db883SUma Shankar * Driver expects metadata to be put in &struct hdr_output_metadata 1369a09db883SUma Shankar * structure from userspace. This is received as blob and stored in 1370a09db883SUma Shankar * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the 1371a09db883SUma Shankar * sink metadata in &struct hdr_sink_metadata, as 1372a09db883SUma Shankar * &drm_connector.hdr_sink_metadata. Driver uses 1373a09db883SUma Shankar * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata, 1374a09db883SUma Shankar * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of 1375a09db883SUma Shankar * HDMI encoder. 1376a09db883SUma Shankar * 137747e22ff1SRadhakrishna Sripada * max bpc: 137847e22ff1SRadhakrishna Sripada * This range property is used by userspace to limit the bit depth. When 137947e22ff1SRadhakrishna Sripada * used the driver would limit the bpc in accordance with the valid range 138047e22ff1SRadhakrishna Sripada * supported by the hardware and sink. Drivers to use the function 138147e22ff1SRadhakrishna Sripada * drm_connector_attach_max_bpc_property() to create and attach the 138247e22ff1SRadhakrishna Sripada * property to the connector during initialization. 138347e22ff1SRadhakrishna Sripada * 13844ada6f22SDaniel Vetter * Connectors also have one standardized atomic property: 13854ada6f22SDaniel Vetter * 13864ada6f22SDaniel Vetter * CRTC_ID: 13874ada6f22SDaniel Vetter * Mode object ID of the &drm_crtc this connector should be connected to. 13888d70f395SHans de Goede * 13898d70f395SHans de Goede * Connectors for LCD panels may also have one standardized property: 13908d70f395SHans de Goede * 13918d70f395SHans de Goede * panel orientation: 13928d70f395SHans de Goede * On some devices the LCD panel is mounted in the casing in such a way 13938d70f395SHans de Goede * that the up/top side of the panel does not match with the top side of 13948d70f395SHans de Goede * the device. Userspace can use this property to check for this. 13958d70f395SHans de Goede * Note that input coordinates from touchscreens (input devices with 13968d70f395SHans de Goede * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel 13978d70f395SHans de Goede * coordinates, so if userspace rotates the picture to adjust for 13988d70f395SHans de Goede * the orientation it must also apply the same transformation to the 1399bbeba09fSDaniel Vetter * touchscreen input coordinates. This property is initialized by calling 140069654c63SDerek Basehore * drm_connector_set_panel_orientation() or 140169654c63SDerek Basehore * drm_connector_set_panel_orientation_with_quirk() 1402bbeba09fSDaniel Vetter * 1403bbeba09fSDaniel Vetter * scaling mode: 1404bbeba09fSDaniel Vetter * This property defines how a non-native mode is upscaled to the native 1405bbeba09fSDaniel Vetter * mode of an LCD panel: 1406bbeba09fSDaniel Vetter * 1407bbeba09fSDaniel Vetter * None: 1408bbeba09fSDaniel Vetter * No upscaling happens, scaling is left to the panel. Not all 1409bbeba09fSDaniel Vetter * drivers expose this mode. 1410bbeba09fSDaniel Vetter * Full: 1411bbeba09fSDaniel Vetter * The output is upscaled to the full resolution of the panel, 1412bbeba09fSDaniel Vetter * ignoring the aspect ratio. 1413bbeba09fSDaniel Vetter * Center: 1414bbeba09fSDaniel Vetter * No upscaling happens, the output is centered within the native 1415bbeba09fSDaniel Vetter * resolution the panel. 1416bbeba09fSDaniel Vetter * Full aspect: 1417bbeba09fSDaniel Vetter * The output is upscaled to maximize either the width or height 1418bbeba09fSDaniel Vetter * while retaining the aspect ratio. 1419bbeba09fSDaniel Vetter * 1420bbeba09fSDaniel Vetter * This property should be set up by calling 1421bbeba09fSDaniel Vetter * drm_connector_attach_scaling_mode_property(). Note that drivers 1422bbeba09fSDaniel Vetter * can also expose this property to external outputs, in which case they 1423bbeba09fSDaniel Vetter * must support "None", which should be the default (since external screens 1424bbeba09fSDaniel Vetter * have a built-in scaler). 1425e5b92773SOleg Vasilev * 1426e5b92773SOleg Vasilev * subconnector: 1427e5b92773SOleg Vasilev * This property is used by DVI-I, TVout and DisplayPort to indicate different 1428e5b92773SOleg Vasilev * connector subtypes. Enum values more or less match with those from main 1429e5b92773SOleg Vasilev * connector types. 1430e5b92773SOleg Vasilev * For DVI-I and TVout there is also a matching property "select subconnector" 1431e5b92773SOleg Vasilev * allowing to switch between signal types. 1432e5b92773SOleg Vasilev * DP subconnector corresponds to a downstream port. 1433107fe904SRajat Jain * 1434107fe904SRajat Jain * privacy-screen sw-state, privacy-screen hw-state: 1435107fe904SRajat Jain * These 2 optional properties can be used to query the state of the 1436107fe904SRajat Jain * electronic privacy screen that is available on some displays; and in 1437107fe904SRajat Jain * some cases also control the state. If a driver implements these 1438107fe904SRajat Jain * properties then both properties must be present. 1439107fe904SRajat Jain * 1440107fe904SRajat Jain * "privacy-screen hw-state" is read-only and reflects the actual state 1441107fe904SRajat Jain * of the privacy-screen, possible values: "Enabled", "Disabled, 1442107fe904SRajat Jain * "Enabled-locked", "Disabled-locked". The locked states indicate 1443107fe904SRajat Jain * that the state cannot be changed through the DRM API. E.g. there 1444107fe904SRajat Jain * might be devices where the firmware-setup options, or a hardware 1445107fe904SRajat Jain * slider-switch, offer always on / off modes. 1446107fe904SRajat Jain * 1447107fe904SRajat Jain * "privacy-screen sw-state" can be set to change the privacy-screen state 1448107fe904SRajat Jain * when not locked. In this case the driver must update the hw-state 1449107fe904SRajat Jain * property to reflect the new state on completion of the commit of the 1450107fe904SRajat Jain * sw-state property. Setting the sw-state property when the hw-state is 1451107fe904SRajat Jain * locked must be interpreted by the driver as a request to change the 1452107fe904SRajat Jain * state to the set state when the hw-state becomes unlocked. E.g. if 1453107fe904SRajat Jain * "privacy-screen hw-state" is "Enabled-locked" and the sw-state 1454107fe904SRajat Jain * gets set to "Disabled" followed by the user unlocking the state by 1455107fe904SRajat Jain * changing the slider-switch position, then the driver must set the 1456107fe904SRajat Jain * state to "Disabled" upon receiving the unlock event. 1457107fe904SRajat Jain * 1458107fe904SRajat Jain * In some cases the privacy-screen's actual state might change outside of 1459107fe904SRajat Jain * control of the DRM code. E.g. there might be a firmware handled hotkey 1460107fe904SRajat Jain * which toggles the actual state, or the actual state might be changed 1461107fe904SRajat Jain * through another userspace API such as writing /proc/acpi/ibm/lcdshadow. 1462107fe904SRajat Jain * In this case the driver must update both the hw-state and the sw-state 1463107fe904SRajat Jain * to reflect the new value, overwriting any pending state requests in the 1464107fe904SRajat Jain * sw-state. Any pending sw-state requests are thus discarded. 1465107fe904SRajat Jain * 1466107fe904SRajat Jain * Note that the ability for the state to change outside of control of 1467107fe904SRajat Jain * the DRM master process means that userspace must not cache the value 1468107fe904SRajat Jain * of the sw-state. Caching the sw-state value and including it in later 1469107fe904SRajat Jain * atomic commits may lead to overriding a state change done through e.g. 1470107fe904SRajat Jain * a firmware handled hotkey. Therefor userspace must not include the 1471107fe904SRajat Jain * privacy-screen sw-state in an atomic commit unless it wants to change 1472107fe904SRajat Jain * its value. 1473409f07d3SSimon Ser * 1474409f07d3SSimon Ser * left margin, right margin, top margin, bottom margin: 1475409f07d3SSimon Ser * Add margins to the connector's viewport. This is typically used to 14763cf15dc2SSimon Ser * mitigate overscan on TVs. 1477409f07d3SSimon Ser * 1478409f07d3SSimon Ser * The value is the size in pixels of the black border which will be 1479409f07d3SSimon Ser * added. The attached CRTC's content will be scaled to fill the whole 1480409f07d3SSimon Ser * area inside the margin. 1481409f07d3SSimon Ser * 1482409f07d3SSimon Ser * The margins configuration might be sent to the sink, e.g. via HDMI AVI 1483409f07d3SSimon Ser * InfoFrames. 1484409f07d3SSimon Ser * 1485409f07d3SSimon Ser * Drivers can set up these properties by calling 1486409f07d3SSimon Ser * drm_mode_create_tv_margin_properties(). 14874ada6f22SDaniel Vetter */ 14884ada6f22SDaniel Vetter 148952217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev) 149052217195SDaniel Vetter { 149152217195SDaniel Vetter struct drm_property *prop; 149252217195SDaniel Vetter 149352217195SDaniel Vetter prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | 149452217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 149552217195SDaniel Vetter "EDID", 0); 149652217195SDaniel Vetter if (!prop) 149752217195SDaniel Vetter return -ENOMEM; 149852217195SDaniel Vetter dev->mode_config.edid_property = prop; 149952217195SDaniel Vetter 150052217195SDaniel Vetter prop = drm_property_create_enum(dev, 0, 150152217195SDaniel Vetter "DPMS", drm_dpms_enum_list, 150252217195SDaniel Vetter ARRAY_SIZE(drm_dpms_enum_list)); 150352217195SDaniel Vetter if (!prop) 150452217195SDaniel Vetter return -ENOMEM; 150552217195SDaniel Vetter dev->mode_config.dpms_property = prop; 150652217195SDaniel Vetter 150752217195SDaniel Vetter prop = drm_property_create(dev, 150852217195SDaniel Vetter DRM_MODE_PROP_BLOB | 150952217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 151052217195SDaniel Vetter "PATH", 0); 151152217195SDaniel Vetter if (!prop) 151252217195SDaniel Vetter return -ENOMEM; 151352217195SDaniel Vetter dev->mode_config.path_property = prop; 151452217195SDaniel Vetter 151552217195SDaniel Vetter prop = drm_property_create(dev, 151652217195SDaniel Vetter DRM_MODE_PROP_BLOB | 151752217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 151852217195SDaniel Vetter "TILE", 0); 151952217195SDaniel Vetter if (!prop) 152052217195SDaniel Vetter return -ENOMEM; 152152217195SDaniel Vetter dev->mode_config.tile_property = prop; 152252217195SDaniel Vetter 152340ee6fbeSManasi Navare prop = drm_property_create_enum(dev, 0, "link-status", 152440ee6fbeSManasi Navare drm_link_status_enum_list, 152540ee6fbeSManasi Navare ARRAY_SIZE(drm_link_status_enum_list)); 152640ee6fbeSManasi Navare if (!prop) 152740ee6fbeSManasi Navare return -ENOMEM; 152840ee6fbeSManasi Navare dev->mode_config.link_status_property = prop; 152940ee6fbeSManasi Navare 153066660d4cSDave Airlie prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop"); 153166660d4cSDave Airlie if (!prop) 153266660d4cSDave Airlie return -ENOMEM; 153366660d4cSDave Airlie dev->mode_config.non_desktop_property = prop; 153466660d4cSDave Airlie 1535fbb5d035SUma Shankar prop = drm_property_create(dev, DRM_MODE_PROP_BLOB, 1536fbb5d035SUma Shankar "HDR_OUTPUT_METADATA", 0); 1537fbb5d035SUma Shankar if (!prop) 1538fbb5d035SUma Shankar return -ENOMEM; 1539fbb5d035SUma Shankar dev->mode_config.hdr_output_metadata_property = prop; 1540fbb5d035SUma Shankar 154152217195SDaniel Vetter return 0; 154252217195SDaniel Vetter } 154352217195SDaniel Vetter 154452217195SDaniel Vetter /** 154552217195SDaniel Vetter * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties 154652217195SDaniel Vetter * @dev: DRM device 154752217195SDaniel Vetter * 154852217195SDaniel Vetter * Called by a driver the first time a DVI-I connector is made. 1549f85d9e59SRandy Dunlap * 1550f85d9e59SRandy Dunlap * Returns: %0 155152217195SDaniel Vetter */ 155252217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev) 155352217195SDaniel Vetter { 155452217195SDaniel Vetter struct drm_property *dvi_i_selector; 155552217195SDaniel Vetter struct drm_property *dvi_i_subconnector; 155652217195SDaniel Vetter 155752217195SDaniel Vetter if (dev->mode_config.dvi_i_select_subconnector_property) 155852217195SDaniel Vetter return 0; 155952217195SDaniel Vetter 156052217195SDaniel Vetter dvi_i_selector = 156152217195SDaniel Vetter drm_property_create_enum(dev, 0, 156252217195SDaniel Vetter "select subconnector", 156352217195SDaniel Vetter drm_dvi_i_select_enum_list, 156452217195SDaniel Vetter ARRAY_SIZE(drm_dvi_i_select_enum_list)); 156552217195SDaniel Vetter dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; 156652217195SDaniel Vetter 156752217195SDaniel Vetter dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 156852217195SDaniel Vetter "subconnector", 156952217195SDaniel Vetter drm_dvi_i_subconnector_enum_list, 157052217195SDaniel Vetter ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); 157152217195SDaniel Vetter dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; 157252217195SDaniel Vetter 157352217195SDaniel Vetter return 0; 157452217195SDaniel Vetter } 157552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); 157652217195SDaniel Vetter 157752217195SDaniel Vetter /** 1578e5b92773SOleg Vasilev * drm_connector_attach_dp_subconnector_property - create subconnector property for DP 1579e5b92773SOleg Vasilev * @connector: drm_connector to attach property 1580e5b92773SOleg Vasilev * 1581e5b92773SOleg Vasilev * Called by a driver when DP connector is created. 1582e5b92773SOleg Vasilev */ 1583e5b92773SOleg Vasilev void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector) 1584e5b92773SOleg Vasilev { 1585e5b92773SOleg Vasilev struct drm_mode_config *mode_config = &connector->dev->mode_config; 1586e5b92773SOleg Vasilev 1587e5b92773SOleg Vasilev if (!mode_config->dp_subconnector_property) 1588e5b92773SOleg Vasilev mode_config->dp_subconnector_property = 1589e5b92773SOleg Vasilev drm_property_create_enum(connector->dev, 1590e5b92773SOleg Vasilev DRM_MODE_PROP_IMMUTABLE, 1591e5b92773SOleg Vasilev "subconnector", 1592e5b92773SOleg Vasilev drm_dp_subconnector_enum_list, 1593e5b92773SOleg Vasilev ARRAY_SIZE(drm_dp_subconnector_enum_list)); 1594e5b92773SOleg Vasilev 1595e5b92773SOleg Vasilev drm_object_attach_property(&connector->base, 1596e5b92773SOleg Vasilev mode_config->dp_subconnector_property, 1597e5b92773SOleg Vasilev DRM_MODE_SUBCONNECTOR_Unknown); 1598e5b92773SOleg Vasilev } 1599e5b92773SOleg Vasilev EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property); 1600e5b92773SOleg Vasilev 1601e5b92773SOleg Vasilev /** 160250525c33SStanislav Lisovskiy * DOC: HDMI connector properties 160350525c33SStanislav Lisovskiy * 160450525c33SStanislav Lisovskiy * content type (HDMI specific): 160550525c33SStanislav Lisovskiy * Indicates content type setting to be used in HDMI infoframes to indicate 16061e55a53aSMatt Roper * content type for the external device, so that it adjusts its display 160750525c33SStanislav Lisovskiy * settings accordingly. 160850525c33SStanislav Lisovskiy * 160950525c33SStanislav Lisovskiy * The value of this property can be one of the following: 161050525c33SStanislav Lisovskiy * 161150525c33SStanislav Lisovskiy * No Data: 161250525c33SStanislav Lisovskiy * Content type is unknown 161350525c33SStanislav Lisovskiy * Graphics: 161450525c33SStanislav Lisovskiy * Content type is graphics 161550525c33SStanislav Lisovskiy * Photo: 161650525c33SStanislav Lisovskiy * Content type is photo 161750525c33SStanislav Lisovskiy * Cinema: 161850525c33SStanislav Lisovskiy * Content type is cinema 161950525c33SStanislav Lisovskiy * Game: 162050525c33SStanislav Lisovskiy * Content type is game 162150525c33SStanislav Lisovskiy * 1622a0a33067SSimon Ser * The meaning of each content type is defined in CTA-861-G table 15. 1623a0a33067SSimon Ser * 162450525c33SStanislav Lisovskiy * Drivers can set up this property by calling 162550525c33SStanislav Lisovskiy * drm_connector_attach_content_type_property(). Decoding to 1626ba609631SDaniel Vetter * infoframe values is done through drm_hdmi_avi_infoframe_content_type(). 162750525c33SStanislav Lisovskiy */ 162850525c33SStanislav Lisovskiy 16297d63cd85SMaxime Ripard /* 16307d63cd85SMaxime Ripard * TODO: Document the properties: 16317d63cd85SMaxime Ripard * - brightness 16327d63cd85SMaxime Ripard * - contrast 16337d63cd85SMaxime Ripard * - flicker reduction 16347d63cd85SMaxime Ripard * - hue 16357d63cd85SMaxime Ripard * - mode 16367d63cd85SMaxime Ripard * - overscan 16377d63cd85SMaxime Ripard * - saturation 16387d63cd85SMaxime Ripard * - select subconnector 16397d63cd85SMaxime Ripard */ 16407d63cd85SMaxime Ripard /** 16417d63cd85SMaxime Ripard * DOC: Analog TV Connector Properties 16427d63cd85SMaxime Ripard * 16437d63cd85SMaxime Ripard * TV Mode: 16447d63cd85SMaxime Ripard * Indicates the TV Mode used on an analog TV connector. The value 16457d63cd85SMaxime Ripard * of this property can be one of the following: 16467d63cd85SMaxime Ripard * 16477d63cd85SMaxime Ripard * NTSC: 16487d63cd85SMaxime Ripard * TV Mode is CCIR System M (aka 525-lines) together with 16497d63cd85SMaxime Ripard * the NTSC Color Encoding. 16507d63cd85SMaxime Ripard * 16517d63cd85SMaxime Ripard * NTSC-443: 16527d63cd85SMaxime Ripard * 16537d63cd85SMaxime Ripard * TV Mode is CCIR System M (aka 525-lines) together with 16547d63cd85SMaxime Ripard * the NTSC Color Encoding, but with a color subcarrier 16557d63cd85SMaxime Ripard * frequency of 4.43MHz 16567d63cd85SMaxime Ripard * 16577d63cd85SMaxime Ripard * NTSC-J: 16587d63cd85SMaxime Ripard * 16597d63cd85SMaxime Ripard * TV Mode is CCIR System M (aka 525-lines) together with 16607d63cd85SMaxime Ripard * the NTSC Color Encoding, but with a black level equal to 16617d63cd85SMaxime Ripard * the blanking level. 16627d63cd85SMaxime Ripard * 16637d63cd85SMaxime Ripard * PAL: 16647d63cd85SMaxime Ripard * 16657d63cd85SMaxime Ripard * TV Mode is CCIR System B (aka 625-lines) together with 16667d63cd85SMaxime Ripard * the PAL Color Encoding. 16677d63cd85SMaxime Ripard * 16687d63cd85SMaxime Ripard * PAL-M: 16697d63cd85SMaxime Ripard * 16707d63cd85SMaxime Ripard * TV Mode is CCIR System M (aka 525-lines) together with 16717d63cd85SMaxime Ripard * the PAL Color Encoding. 16727d63cd85SMaxime Ripard * 16737d63cd85SMaxime Ripard * PAL-N: 16747d63cd85SMaxime Ripard * 16757d63cd85SMaxime Ripard * TV Mode is CCIR System N together with the PAL Color 16767d63cd85SMaxime Ripard * Encoding, a color subcarrier frequency of 3.58MHz, the 16777d63cd85SMaxime Ripard * SECAM color space, and narrower channels than other PAL 16787d63cd85SMaxime Ripard * variants. 16797d63cd85SMaxime Ripard * 16807d63cd85SMaxime Ripard * SECAM: 16817d63cd85SMaxime Ripard * 16827d63cd85SMaxime Ripard * TV Mode is CCIR System B (aka 625-lines) together with 16837d63cd85SMaxime Ripard * the SECAM Color Encoding. 16847d63cd85SMaxime Ripard * 16857d63cd85SMaxime Ripard * Drivers can set up this property by calling 16867d63cd85SMaxime Ripard * drm_mode_create_tv_properties(). 16877d63cd85SMaxime Ripard */ 16887d63cd85SMaxime Ripard 168950525c33SStanislav Lisovskiy /** 169050525c33SStanislav Lisovskiy * drm_connector_attach_content_type_property - attach content-type property 169150525c33SStanislav Lisovskiy * @connector: connector to attach content type property on. 169250525c33SStanislav Lisovskiy * 169350525c33SStanislav Lisovskiy * Called by a driver the first time a HDMI connector is made. 1694f85d9e59SRandy Dunlap * 1695f85d9e59SRandy Dunlap * Returns: %0 169650525c33SStanislav Lisovskiy */ 169750525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector) 169850525c33SStanislav Lisovskiy { 169950525c33SStanislav Lisovskiy if (!drm_mode_create_content_type_property(connector->dev)) 170050525c33SStanislav Lisovskiy drm_object_attach_property(&connector->base, 170150525c33SStanislav Lisovskiy connector->dev->mode_config.content_type_property, 170250525c33SStanislav Lisovskiy DRM_MODE_CONTENT_TYPE_NO_DATA); 170350525c33SStanislav Lisovskiy return 0; 170450525c33SStanislav Lisovskiy } 170550525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property); 170650525c33SStanislav Lisovskiy 170750525c33SStanislav Lisovskiy /** 1708e9d2871fSMauro Carvalho Chehab * drm_connector_attach_tv_margin_properties - attach TV connector margin 1709e9d2871fSMauro Carvalho Chehab * properties 17106c4f52dcSBoris Brezillon * @connector: DRM connector 17116c4f52dcSBoris Brezillon * 17126c4f52dcSBoris Brezillon * Called by a driver when it needs to attach TV margin props to a connector. 17136c4f52dcSBoris Brezillon * Typically used on SDTV and HDMI connectors. 17146c4f52dcSBoris Brezillon */ 17156c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector) 17166c4f52dcSBoris Brezillon { 17176c4f52dcSBoris Brezillon struct drm_device *dev = connector->dev; 17186c4f52dcSBoris Brezillon 17196c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 17206c4f52dcSBoris Brezillon dev->mode_config.tv_left_margin_property, 17216c4f52dcSBoris Brezillon 0); 17226c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 17236c4f52dcSBoris Brezillon dev->mode_config.tv_right_margin_property, 17246c4f52dcSBoris Brezillon 0); 17256c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 17266c4f52dcSBoris Brezillon dev->mode_config.tv_top_margin_property, 17276c4f52dcSBoris Brezillon 0); 17286c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 17296c4f52dcSBoris Brezillon dev->mode_config.tv_bottom_margin_property, 17306c4f52dcSBoris Brezillon 0); 17316c4f52dcSBoris Brezillon } 17326c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties); 17336c4f52dcSBoris Brezillon 17346c4f52dcSBoris Brezillon /** 17356c4f52dcSBoris Brezillon * drm_mode_create_tv_margin_properties - create TV connector margin properties 17366c4f52dcSBoris Brezillon * @dev: DRM device 17376c4f52dcSBoris Brezillon * 17386c4f52dcSBoris Brezillon * Called by a driver's HDMI connector initialization routine, this function 17396c4f52dcSBoris Brezillon * creates the TV margin properties for a given device. No need to call this 17406c4f52dcSBoris Brezillon * function for an SDTV connector, it's already called from 174180ed86d4SMaxime Ripard * drm_mode_create_tv_properties_legacy(). 1742f85d9e59SRandy Dunlap * 1743f85d9e59SRandy Dunlap * Returns: 1744f85d9e59SRandy Dunlap * 0 on success or a negative error code on failure. 17456c4f52dcSBoris Brezillon */ 17466c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev) 17476c4f52dcSBoris Brezillon { 17486c4f52dcSBoris Brezillon if (dev->mode_config.tv_left_margin_property) 17496c4f52dcSBoris Brezillon return 0; 17506c4f52dcSBoris Brezillon 17516c4f52dcSBoris Brezillon dev->mode_config.tv_left_margin_property = 17526c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "left margin", 0, 100); 17536c4f52dcSBoris Brezillon if (!dev->mode_config.tv_left_margin_property) 17546c4f52dcSBoris Brezillon return -ENOMEM; 17556c4f52dcSBoris Brezillon 17566c4f52dcSBoris Brezillon dev->mode_config.tv_right_margin_property = 17576c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "right margin", 0, 100); 17586c4f52dcSBoris Brezillon if (!dev->mode_config.tv_right_margin_property) 17596c4f52dcSBoris Brezillon return -ENOMEM; 17606c4f52dcSBoris Brezillon 17616c4f52dcSBoris Brezillon dev->mode_config.tv_top_margin_property = 17626c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "top margin", 0, 100); 17636c4f52dcSBoris Brezillon if (!dev->mode_config.tv_top_margin_property) 17646c4f52dcSBoris Brezillon return -ENOMEM; 17656c4f52dcSBoris Brezillon 17666c4f52dcSBoris Brezillon dev->mode_config.tv_bottom_margin_property = 17676c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "bottom margin", 0, 100); 17686c4f52dcSBoris Brezillon if (!dev->mode_config.tv_bottom_margin_property) 17696c4f52dcSBoris Brezillon return -ENOMEM; 17706c4f52dcSBoris Brezillon 17716c4f52dcSBoris Brezillon return 0; 17726c4f52dcSBoris Brezillon } 17736c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties); 17746c4f52dcSBoris Brezillon 17756c4f52dcSBoris Brezillon /** 177680ed86d4SMaxime Ripard * drm_mode_create_tv_properties_legacy - create TV specific connector properties 177752217195SDaniel Vetter * @dev: DRM device 177852217195SDaniel Vetter * @num_modes: number of different TV formats (modes) supported 177952217195SDaniel Vetter * @modes: array of pointers to strings containing name of each format 178052217195SDaniel Vetter * 178152217195SDaniel Vetter * Called by a driver's TV initialization routine, this function creates 178252217195SDaniel Vetter * the TV specific connector properties for a given device. Caller is 178352217195SDaniel Vetter * responsible for allocating a list of format names and passing them to 178452217195SDaniel Vetter * this routine. 1785f85d9e59SRandy Dunlap * 17867d63cd85SMaxime Ripard * NOTE: This functions registers the deprecated "mode" connector 17877d63cd85SMaxime Ripard * property to select the analog TV mode (ie, NTSC, PAL, etc.). New 17887d63cd85SMaxime Ripard * drivers must use drm_mode_create_tv_properties() instead. 17897d63cd85SMaxime Ripard * 1790f85d9e59SRandy Dunlap * Returns: 1791f85d9e59SRandy Dunlap * 0 on success or a negative error code on failure. 179252217195SDaniel Vetter */ 179380ed86d4SMaxime Ripard int drm_mode_create_tv_properties_legacy(struct drm_device *dev, 179452217195SDaniel Vetter unsigned int num_modes, 179552217195SDaniel Vetter const char * const modes[]) 179652217195SDaniel Vetter { 179752217195SDaniel Vetter struct drm_property *tv_selector; 179852217195SDaniel Vetter struct drm_property *tv_subconnector; 179952217195SDaniel Vetter unsigned int i; 180052217195SDaniel Vetter 180152217195SDaniel Vetter if (dev->mode_config.tv_select_subconnector_property) 180252217195SDaniel Vetter return 0; 180352217195SDaniel Vetter 180452217195SDaniel Vetter /* 180552217195SDaniel Vetter * Basic connector properties 180652217195SDaniel Vetter */ 180752217195SDaniel Vetter tv_selector = drm_property_create_enum(dev, 0, 180852217195SDaniel Vetter "select subconnector", 180952217195SDaniel Vetter drm_tv_select_enum_list, 181052217195SDaniel Vetter ARRAY_SIZE(drm_tv_select_enum_list)); 181152217195SDaniel Vetter if (!tv_selector) 181252217195SDaniel Vetter goto nomem; 181352217195SDaniel Vetter 181452217195SDaniel Vetter dev->mode_config.tv_select_subconnector_property = tv_selector; 181552217195SDaniel Vetter 181652217195SDaniel Vetter tv_subconnector = 181752217195SDaniel Vetter drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 181852217195SDaniel Vetter "subconnector", 181952217195SDaniel Vetter drm_tv_subconnector_enum_list, 182052217195SDaniel Vetter ARRAY_SIZE(drm_tv_subconnector_enum_list)); 182152217195SDaniel Vetter if (!tv_subconnector) 182252217195SDaniel Vetter goto nomem; 182352217195SDaniel Vetter dev->mode_config.tv_subconnector_property = tv_subconnector; 182452217195SDaniel Vetter 182552217195SDaniel Vetter /* 182652217195SDaniel Vetter * Other, TV specific properties: margins & TV modes. 182752217195SDaniel Vetter */ 18286c4f52dcSBoris Brezillon if (drm_mode_create_tv_margin_properties(dev)) 182952217195SDaniel Vetter goto nomem; 183052217195SDaniel Vetter 1831aab5aaa7SMaxime Ripard if (num_modes) { 18321fd4a5a3SMaxime Ripard dev->mode_config.legacy_tv_mode_property = 183352217195SDaniel Vetter drm_property_create(dev, DRM_MODE_PROP_ENUM, 183452217195SDaniel Vetter "mode", num_modes); 18351fd4a5a3SMaxime Ripard if (!dev->mode_config.legacy_tv_mode_property) 183652217195SDaniel Vetter goto nomem; 183752217195SDaniel Vetter 183852217195SDaniel Vetter for (i = 0; i < num_modes; i++) 18391fd4a5a3SMaxime Ripard drm_property_add_enum(dev->mode_config.legacy_tv_mode_property, 184052217195SDaniel Vetter i, modes[i]); 1841aab5aaa7SMaxime Ripard } 184252217195SDaniel Vetter 184352217195SDaniel Vetter dev->mode_config.tv_brightness_property = 184452217195SDaniel Vetter drm_property_create_range(dev, 0, "brightness", 0, 100); 184552217195SDaniel Vetter if (!dev->mode_config.tv_brightness_property) 184652217195SDaniel Vetter goto nomem; 184752217195SDaniel Vetter 184852217195SDaniel Vetter dev->mode_config.tv_contrast_property = 184952217195SDaniel Vetter drm_property_create_range(dev, 0, "contrast", 0, 100); 185052217195SDaniel Vetter if (!dev->mode_config.tv_contrast_property) 185152217195SDaniel Vetter goto nomem; 185252217195SDaniel Vetter 185352217195SDaniel Vetter dev->mode_config.tv_flicker_reduction_property = 185452217195SDaniel Vetter drm_property_create_range(dev, 0, "flicker reduction", 0, 100); 185552217195SDaniel Vetter if (!dev->mode_config.tv_flicker_reduction_property) 185652217195SDaniel Vetter goto nomem; 185752217195SDaniel Vetter 185852217195SDaniel Vetter dev->mode_config.tv_overscan_property = 185952217195SDaniel Vetter drm_property_create_range(dev, 0, "overscan", 0, 100); 186052217195SDaniel Vetter if (!dev->mode_config.tv_overscan_property) 186152217195SDaniel Vetter goto nomem; 186252217195SDaniel Vetter 186352217195SDaniel Vetter dev->mode_config.tv_saturation_property = 186452217195SDaniel Vetter drm_property_create_range(dev, 0, "saturation", 0, 100); 186552217195SDaniel Vetter if (!dev->mode_config.tv_saturation_property) 186652217195SDaniel Vetter goto nomem; 186752217195SDaniel Vetter 186852217195SDaniel Vetter dev->mode_config.tv_hue_property = 186952217195SDaniel Vetter drm_property_create_range(dev, 0, "hue", 0, 100); 187052217195SDaniel Vetter if (!dev->mode_config.tv_hue_property) 187152217195SDaniel Vetter goto nomem; 187252217195SDaniel Vetter 187352217195SDaniel Vetter return 0; 187452217195SDaniel Vetter nomem: 187552217195SDaniel Vetter return -ENOMEM; 187652217195SDaniel Vetter } 187780ed86d4SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy); 187852217195SDaniel Vetter 187952217195SDaniel Vetter /** 18807d63cd85SMaxime Ripard * drm_mode_create_tv_properties - create TV specific connector properties 18817d63cd85SMaxime Ripard * @dev: DRM device 18827d63cd85SMaxime Ripard * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*) 188304ee2767SRandy Dunlap * 18847d63cd85SMaxime Ripard * Called by a driver's TV initialization routine, this function creates 18857d63cd85SMaxime Ripard * the TV specific connector properties for a given device. 18867d63cd85SMaxime Ripard * 18877d63cd85SMaxime Ripard * Returns: 18887d63cd85SMaxime Ripard * 0 on success or a negative error code on failure. 18897d63cd85SMaxime Ripard */ 18907d63cd85SMaxime Ripard int drm_mode_create_tv_properties(struct drm_device *dev, 18917d63cd85SMaxime Ripard unsigned int supported_tv_modes) 18927d63cd85SMaxime Ripard { 18937d63cd85SMaxime Ripard struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX]; 18947d63cd85SMaxime Ripard struct drm_property *tv_mode; 18957d63cd85SMaxime Ripard unsigned int i, len = 0; 18967d63cd85SMaxime Ripard 18977d63cd85SMaxime Ripard if (dev->mode_config.tv_mode_property) 18987d63cd85SMaxime Ripard return 0; 18997d63cd85SMaxime Ripard 19007d63cd85SMaxime Ripard for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) { 19017d63cd85SMaxime Ripard if (!(supported_tv_modes & BIT(i))) 19027d63cd85SMaxime Ripard continue; 19037d63cd85SMaxime Ripard 19047d63cd85SMaxime Ripard tv_mode_list[len].type = i; 19057d63cd85SMaxime Ripard tv_mode_list[len].name = drm_get_tv_mode_name(i); 19067d63cd85SMaxime Ripard len++; 19077d63cd85SMaxime Ripard } 19087d63cd85SMaxime Ripard 19097d63cd85SMaxime Ripard tv_mode = drm_property_create_enum(dev, 0, "TV mode", 19107d63cd85SMaxime Ripard tv_mode_list, len); 19117d63cd85SMaxime Ripard if (!tv_mode) 19127d63cd85SMaxime Ripard return -ENOMEM; 19137d63cd85SMaxime Ripard 19147d63cd85SMaxime Ripard dev->mode_config.tv_mode_property = tv_mode; 19157d63cd85SMaxime Ripard 19167d63cd85SMaxime Ripard return drm_mode_create_tv_properties_legacy(dev, 0, NULL); 19177d63cd85SMaxime Ripard } 19187d63cd85SMaxime Ripard EXPORT_SYMBOL(drm_mode_create_tv_properties); 19197d63cd85SMaxime Ripard 19207d63cd85SMaxime Ripard /** 192152217195SDaniel Vetter * drm_mode_create_scaling_mode_property - create scaling mode property 192252217195SDaniel Vetter * @dev: DRM device 192352217195SDaniel Vetter * 192452217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 192552217195SDaniel Vetter * connectors. 19268f6e1e22SMaarten Lankhorst * 19278f6e1e22SMaarten Lankhorst * Atomic drivers should use drm_connector_attach_scaling_mode_property() 19289c2fce13SVille Syrjälä * instead to correctly assign &drm_connector_state.scaling_mode 19298f6e1e22SMaarten Lankhorst * in the atomic state. 1930f85d9e59SRandy Dunlap * 1931f85d9e59SRandy Dunlap * Returns: %0 193252217195SDaniel Vetter */ 193352217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev) 193452217195SDaniel Vetter { 193552217195SDaniel Vetter struct drm_property *scaling_mode; 193652217195SDaniel Vetter 193752217195SDaniel Vetter if (dev->mode_config.scaling_mode_property) 193852217195SDaniel Vetter return 0; 193952217195SDaniel Vetter 194052217195SDaniel Vetter scaling_mode = 194152217195SDaniel Vetter drm_property_create_enum(dev, 0, "scaling mode", 194252217195SDaniel Vetter drm_scaling_mode_enum_list, 194352217195SDaniel Vetter ARRAY_SIZE(drm_scaling_mode_enum_list)); 194452217195SDaniel Vetter 194552217195SDaniel Vetter dev->mode_config.scaling_mode_property = scaling_mode; 194652217195SDaniel Vetter 194752217195SDaniel Vetter return 0; 194852217195SDaniel Vetter } 194952217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); 195052217195SDaniel Vetter 195152217195SDaniel Vetter /** 1952ab7a664fSNicholas Kazlauskas * DOC: Variable refresh properties 1953ab7a664fSNicholas Kazlauskas * 1954ab7a664fSNicholas Kazlauskas * Variable refresh rate capable displays can dynamically adjust their 1955ab7a664fSNicholas Kazlauskas * refresh rate by extending the duration of their vertical front porch 1956ab7a664fSNicholas Kazlauskas * until page flip or timeout occurs. This can reduce or remove stuttering 1957ab7a664fSNicholas Kazlauskas * and latency in scenarios where the page flip does not align with the 1958ab7a664fSNicholas Kazlauskas * vblank interval. 1959ab7a664fSNicholas Kazlauskas * 1960ab7a664fSNicholas Kazlauskas * An example scenario would be an application flipping at a constant rate 1961ab7a664fSNicholas Kazlauskas * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank 1962ab7a664fSNicholas Kazlauskas * interval and the same contents will be displayed twice. This can be 1963ab7a664fSNicholas Kazlauskas * observed as stuttering for content with motion. 1964ab7a664fSNicholas Kazlauskas * 1965ab7a664fSNicholas Kazlauskas * If variable refresh rate was active on a display that supported a 1966ab7a664fSNicholas Kazlauskas * variable refresh range from 35Hz to 60Hz no stuttering would be observable 1967ab7a664fSNicholas Kazlauskas * for the example scenario. The minimum supported variable refresh rate of 1968ab7a664fSNicholas Kazlauskas * 35Hz is below the page flip frequency and the vertical front porch can 1969ab7a664fSNicholas Kazlauskas * be extended until the page flip occurs. The vblank interval will be 1970ab7a664fSNicholas Kazlauskas * directly aligned to the page flip rate. 1971ab7a664fSNicholas Kazlauskas * 1972ab7a664fSNicholas Kazlauskas * Not all userspace content is suitable for use with variable refresh rate. 1973ab7a664fSNicholas Kazlauskas * Large and frequent changes in vertical front porch duration may worsen 1974ab7a664fSNicholas Kazlauskas * perceived stuttering for input sensitive applications. 1975ab7a664fSNicholas Kazlauskas * 1976ab7a664fSNicholas Kazlauskas * Panel brightness will also vary with vertical front porch duration. Some 1977ab7a664fSNicholas Kazlauskas * panels may have noticeable differences in brightness between the minimum 1978ab7a664fSNicholas Kazlauskas * vertical front porch duration and the maximum vertical front porch duration. 1979ab7a664fSNicholas Kazlauskas * Large and frequent changes in vertical front porch duration may produce 1980ab7a664fSNicholas Kazlauskas * observable flickering for such panels. 1981ab7a664fSNicholas Kazlauskas * 1982ab7a664fSNicholas Kazlauskas * Userspace control for variable refresh rate is supported via properties 1983ab7a664fSNicholas Kazlauskas * on the &drm_connector and &drm_crtc objects. 1984ab7a664fSNicholas Kazlauskas * 1985ab7a664fSNicholas Kazlauskas * "vrr_capable": 1986ab7a664fSNicholas Kazlauskas * Optional &drm_connector boolean property that drivers should attach 1987ab7a664fSNicholas Kazlauskas * with drm_connector_attach_vrr_capable_property() on connectors that 1988ab7a664fSNicholas Kazlauskas * could support variable refresh rates. Drivers should update the 1989ab7a664fSNicholas Kazlauskas * property value by calling drm_connector_set_vrr_capable_property(). 1990ab7a664fSNicholas Kazlauskas * 1991ab7a664fSNicholas Kazlauskas * Absence of the property should indicate absence of support. 1992ab7a664fSNicholas Kazlauskas * 199377086014SDaniel Vetter * "VRR_ENABLED": 1994ab7a664fSNicholas Kazlauskas * Default &drm_crtc boolean property that notifies the driver that the 1995ab7a664fSNicholas Kazlauskas * content on the CRTC is suitable for variable refresh rate presentation. 1996ab7a664fSNicholas Kazlauskas * The driver will take this property as a hint to enable variable 1997ab7a664fSNicholas Kazlauskas * refresh rate support if the receiver supports it, ie. if the 1998ab7a664fSNicholas Kazlauskas * "vrr_capable" property is true on the &drm_connector object. The 1999ab7a664fSNicholas Kazlauskas * vertical front porch duration will be extended until page-flip or 2000ab7a664fSNicholas Kazlauskas * timeout when enabled. 2001ab7a664fSNicholas Kazlauskas * 2002ab7a664fSNicholas Kazlauskas * The minimum vertical front porch duration is defined as the vertical 2003ab7a664fSNicholas Kazlauskas * front porch duration for the current mode. 2004ab7a664fSNicholas Kazlauskas * 2005ab7a664fSNicholas Kazlauskas * The maximum vertical front porch duration is greater than or equal to 2006ab7a664fSNicholas Kazlauskas * the minimum vertical front porch duration. The duration is derived 2007ab7a664fSNicholas Kazlauskas * from the minimum supported variable refresh rate for the connector. 2008ab7a664fSNicholas Kazlauskas * 2009ab7a664fSNicholas Kazlauskas * The driver may place further restrictions within these minimum 2010ab7a664fSNicholas Kazlauskas * and maximum bounds. 2011ab7a664fSNicholas Kazlauskas */ 2012ab7a664fSNicholas Kazlauskas 2013ab7a664fSNicholas Kazlauskas /** 2014ba1b0f6cSNicholas Kazlauskas * drm_connector_attach_vrr_capable_property - creates the 2015ba1b0f6cSNicholas Kazlauskas * vrr_capable property 2016ba1b0f6cSNicholas Kazlauskas * @connector: connector to create the vrr_capable property on. 2017ba1b0f6cSNicholas Kazlauskas * 2018ba1b0f6cSNicholas Kazlauskas * This is used by atomic drivers to add support for querying 2019ba1b0f6cSNicholas Kazlauskas * variable refresh rate capability for a connector. 2020ba1b0f6cSNicholas Kazlauskas * 2021ba1b0f6cSNicholas Kazlauskas * Returns: 202284e543bcSAntonio Borneo * Zero on success, negative errno on failure. 2023ba1b0f6cSNicholas Kazlauskas */ 2024ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property( 2025ba1b0f6cSNicholas Kazlauskas struct drm_connector *connector) 2026ba1b0f6cSNicholas Kazlauskas { 2027ba1b0f6cSNicholas Kazlauskas struct drm_device *dev = connector->dev; 2028ba1b0f6cSNicholas Kazlauskas struct drm_property *prop; 2029ba1b0f6cSNicholas Kazlauskas 2030ba1b0f6cSNicholas Kazlauskas if (!connector->vrr_capable_property) { 2031ba1b0f6cSNicholas Kazlauskas prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, 2032ba1b0f6cSNicholas Kazlauskas "vrr_capable"); 2033ba1b0f6cSNicholas Kazlauskas if (!prop) 2034ba1b0f6cSNicholas Kazlauskas return -ENOMEM; 2035ba1b0f6cSNicholas Kazlauskas 2036ba1b0f6cSNicholas Kazlauskas connector->vrr_capable_property = prop; 2037ba1b0f6cSNicholas Kazlauskas drm_object_attach_property(&connector->base, prop, 0); 2038ba1b0f6cSNicholas Kazlauskas } 2039ba1b0f6cSNicholas Kazlauskas 2040ba1b0f6cSNicholas Kazlauskas return 0; 2041ba1b0f6cSNicholas Kazlauskas } 2042ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property); 2043ba1b0f6cSNicholas Kazlauskas 2044ba1b0f6cSNicholas Kazlauskas /** 20458f6e1e22SMaarten Lankhorst * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property 20468f6e1e22SMaarten Lankhorst * @connector: connector to attach scaling mode property on. 20478f6e1e22SMaarten Lankhorst * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*). 20488f6e1e22SMaarten Lankhorst * 20498f6e1e22SMaarten Lankhorst * This is used to add support for scaling mode to atomic drivers. 20509c2fce13SVille Syrjälä * The scaling mode will be set to &drm_connector_state.scaling_mode 20518f6e1e22SMaarten Lankhorst * and can be used from &drm_connector_helper_funcs->atomic_check for validation. 20528f6e1e22SMaarten Lankhorst * 20538f6e1e22SMaarten Lankhorst * This is the atomic version of drm_mode_create_scaling_mode_property(). 20548f6e1e22SMaarten Lankhorst * 20558f6e1e22SMaarten Lankhorst * Returns: 20568f6e1e22SMaarten Lankhorst * Zero on success, negative errno on failure. 20578f6e1e22SMaarten Lankhorst */ 20588f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector, 20598f6e1e22SMaarten Lankhorst u32 scaling_mode_mask) 20608f6e1e22SMaarten Lankhorst { 20618f6e1e22SMaarten Lankhorst struct drm_device *dev = connector->dev; 20628f6e1e22SMaarten Lankhorst struct drm_property *scaling_mode_property; 206330e9db6dSVille Syrjälä int i; 20648f6e1e22SMaarten Lankhorst const unsigned valid_scaling_mode_mask = 20658f6e1e22SMaarten Lankhorst (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1; 20668f6e1e22SMaarten Lankhorst 20678f6e1e22SMaarten Lankhorst if (WARN_ON(hweight32(scaling_mode_mask) < 2 || 20688f6e1e22SMaarten Lankhorst scaling_mode_mask & ~valid_scaling_mode_mask)) 20698f6e1e22SMaarten Lankhorst return -EINVAL; 20708f6e1e22SMaarten Lankhorst 20718f6e1e22SMaarten Lankhorst scaling_mode_property = 20728f6e1e22SMaarten Lankhorst drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode", 20738f6e1e22SMaarten Lankhorst hweight32(scaling_mode_mask)); 20748f6e1e22SMaarten Lankhorst 20758f6e1e22SMaarten Lankhorst if (!scaling_mode_property) 20768f6e1e22SMaarten Lankhorst return -ENOMEM; 20778f6e1e22SMaarten Lankhorst 20788f6e1e22SMaarten Lankhorst for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) { 20798f6e1e22SMaarten Lankhorst int ret; 20808f6e1e22SMaarten Lankhorst 20818f6e1e22SMaarten Lankhorst if (!(BIT(i) & scaling_mode_mask)) 20828f6e1e22SMaarten Lankhorst continue; 20838f6e1e22SMaarten Lankhorst 208430e9db6dSVille Syrjälä ret = drm_property_add_enum(scaling_mode_property, 20858f6e1e22SMaarten Lankhorst drm_scaling_mode_enum_list[i].type, 20868f6e1e22SMaarten Lankhorst drm_scaling_mode_enum_list[i].name); 20878f6e1e22SMaarten Lankhorst 20888f6e1e22SMaarten Lankhorst if (ret) { 20898f6e1e22SMaarten Lankhorst drm_property_destroy(dev, scaling_mode_property); 20908f6e1e22SMaarten Lankhorst 20918f6e1e22SMaarten Lankhorst return ret; 20928f6e1e22SMaarten Lankhorst } 20938f6e1e22SMaarten Lankhorst } 20948f6e1e22SMaarten Lankhorst 20958f6e1e22SMaarten Lankhorst drm_object_attach_property(&connector->base, 20968f6e1e22SMaarten Lankhorst scaling_mode_property, 0); 20978f6e1e22SMaarten Lankhorst 20988f6e1e22SMaarten Lankhorst connector->scaling_mode_property = scaling_mode_property; 20998f6e1e22SMaarten Lankhorst 21008f6e1e22SMaarten Lankhorst return 0; 21018f6e1e22SMaarten Lankhorst } 21028f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property); 21038f6e1e22SMaarten Lankhorst 21048f6e1e22SMaarten Lankhorst /** 210552217195SDaniel Vetter * drm_mode_create_aspect_ratio_property - create aspect ratio property 210652217195SDaniel Vetter * @dev: DRM device 210752217195SDaniel Vetter * 210852217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 210952217195SDaniel Vetter * connectors. 211052217195SDaniel Vetter * 211152217195SDaniel Vetter * Returns: 211252217195SDaniel Vetter * Zero on success, negative errno on failure. 211352217195SDaniel Vetter */ 211452217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev) 211552217195SDaniel Vetter { 211652217195SDaniel Vetter if (dev->mode_config.aspect_ratio_property) 211752217195SDaniel Vetter return 0; 211852217195SDaniel Vetter 211952217195SDaniel Vetter dev->mode_config.aspect_ratio_property = 212052217195SDaniel Vetter drm_property_create_enum(dev, 0, "aspect ratio", 212152217195SDaniel Vetter drm_aspect_ratio_enum_list, 212252217195SDaniel Vetter ARRAY_SIZE(drm_aspect_ratio_enum_list)); 212352217195SDaniel Vetter 212452217195SDaniel Vetter if (dev->mode_config.aspect_ratio_property == NULL) 212552217195SDaniel Vetter return -ENOMEM; 212652217195SDaniel Vetter 212752217195SDaniel Vetter return 0; 212852217195SDaniel Vetter } 212952217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); 213052217195SDaniel Vetter 213152217195SDaniel Vetter /** 2132d2c6a405SUma Shankar * DOC: standard connector properties 2133d2c6a405SUma Shankar * 2134d2c6a405SUma Shankar * Colorspace: 2135d2c6a405SUma Shankar * This property helps select a suitable colorspace based on the sink 2136d2c6a405SUma Shankar * capability. Modern sink devices support wider gamut like BT2020. 2137d2c6a405SUma Shankar * This helps switch to BT2020 mode if the BT2020 encoded video stream 2138d2c6a405SUma Shankar * is being played by the user, same for any other colorspace. Thereby 2139d2c6a405SUma Shankar * giving a good visual experience to users. 2140d2c6a405SUma Shankar * 2141d2c6a405SUma Shankar * The expectation from userspace is that it should parse the EDID 2142d2c6a405SUma Shankar * and get supported colorspaces. Use this property and switch to the 2143d2c6a405SUma Shankar * one supported. Sink supported colorspaces should be retrieved by 2144d2c6a405SUma Shankar * userspace from EDID and driver will not explicitly expose them. 2145d2c6a405SUma Shankar * 2146d2c6a405SUma Shankar * Basically the expectation from userspace is: 2147d2c6a405SUma Shankar * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink 2148d2c6a405SUma Shankar * colorspace 2149d2c6a405SUma Shankar * - Set this new property to let the sink know what it 2150d2c6a405SUma Shankar * converted the CRTC output to. 2151d2c6a405SUma Shankar * - This property is just to inform sink what colorspace 2152d2c6a405SUma Shankar * source is trying to drive. 2153d2c6a405SUma Shankar * 21548806cd3aSGwan-gyeong Mun * Because between HDMI and DP have different colorspaces, 215545cf0e91SGwan-gyeong Mun * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and 215645cf0e91SGwan-gyeong Mun * drm_mode_create_dp_colorspace_property() is used for DP connector. 2157d2c6a405SUma Shankar */ 21588806cd3aSGwan-gyeong Mun 21596120611aSHarry Wentland static int drm_mode_create_colorspace_property(struct drm_connector *connector, 2160c627087cSHarry Wentland u32 supported_colorspaces) 21616120611aSHarry Wentland { 21626120611aSHarry Wentland struct drm_device *dev = connector->dev; 2163c627087cSHarry Wentland u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT); 2164c627087cSHarry Wentland struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT]; 2165c627087cSHarry Wentland int i, len; 21666120611aSHarry Wentland 21676120611aSHarry Wentland if (connector->colorspace_property) 21686120611aSHarry Wentland return 0; 21696120611aSHarry Wentland 2170c627087cSHarry Wentland if (!supported_colorspaces) { 2171c627087cSHarry Wentland drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n", 2172c627087cSHarry Wentland connector->base.id, connector->name); 2173c627087cSHarry Wentland return -EINVAL; 2174c627087cSHarry Wentland } 2175c627087cSHarry Wentland 2176c627087cSHarry Wentland if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) { 2177c627087cSHarry Wentland drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n", 2178c627087cSHarry Wentland connector->base.id, connector->name); 2179c627087cSHarry Wentland return -EINVAL; 2180c627087cSHarry Wentland } 2181c627087cSHarry Wentland 2182c627087cSHarry Wentland len = 0; 2183c627087cSHarry Wentland for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) { 2184c627087cSHarry Wentland if ((colorspaces & BIT(i)) == 0) 2185c627087cSHarry Wentland continue; 2186c627087cSHarry Wentland 2187c627087cSHarry Wentland enum_list[len].type = i; 2188c627087cSHarry Wentland enum_list[len].name = colorspace_names[i]; 2189c627087cSHarry Wentland len++; 2190c627087cSHarry Wentland } 21916120611aSHarry Wentland 21926120611aSHarry Wentland connector->colorspace_property = 21936120611aSHarry Wentland drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace", 2194c627087cSHarry Wentland enum_list, 2195c627087cSHarry Wentland len); 21966120611aSHarry Wentland 21976120611aSHarry Wentland if (!connector->colorspace_property) 21986120611aSHarry Wentland return -ENOMEM; 21996120611aSHarry Wentland 22006120611aSHarry Wentland return 0; 22016120611aSHarry Wentland } 2202c627087cSHarry Wentland 22038806cd3aSGwan-gyeong Mun /** 22048806cd3aSGwan-gyeong Mun * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property 22058806cd3aSGwan-gyeong Mun * @connector: connector to create the Colorspace property on. 22068806cd3aSGwan-gyeong Mun * 22078806cd3aSGwan-gyeong Mun * Called by a driver the first time it's needed, must be attached to desired 22088806cd3aSGwan-gyeong Mun * HDMI connectors. 22098806cd3aSGwan-gyeong Mun * 22108806cd3aSGwan-gyeong Mun * Returns: 221184e543bcSAntonio Borneo * Zero on success, negative errno on failure. 22128806cd3aSGwan-gyeong Mun */ 2213c265f340SHarry Wentland int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector, 2214c265f340SHarry Wentland u32 supported_colorspaces) 2215d2c6a405SUma Shankar { 2216c265f340SHarry Wentland u32 colorspaces; 2217c265f340SHarry Wentland 2218c265f340SHarry Wentland if (supported_colorspaces) 2219c265f340SHarry Wentland colorspaces = supported_colorspaces & hdmi_colorspaces; 2220c265f340SHarry Wentland else 2221c265f340SHarry Wentland colorspaces = hdmi_colorspaces; 2222c265f340SHarry Wentland 2223c265f340SHarry Wentland return drm_mode_create_colorspace_property(connector, colorspaces); 2224d2c6a405SUma Shankar } 22258806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property); 2226d2c6a405SUma Shankar 2227d2c6a405SUma Shankar /** 222845cf0e91SGwan-gyeong Mun * drm_mode_create_dp_colorspace_property - create dp colorspace property 222945cf0e91SGwan-gyeong Mun * @connector: connector to create the Colorspace property on. 223045cf0e91SGwan-gyeong Mun * 223145cf0e91SGwan-gyeong Mun * Called by a driver the first time it's needed, must be attached to desired 223245cf0e91SGwan-gyeong Mun * DP connectors. 223345cf0e91SGwan-gyeong Mun * 223445cf0e91SGwan-gyeong Mun * Returns: 223584e543bcSAntonio Borneo * Zero on success, negative errno on failure. 223645cf0e91SGwan-gyeong Mun */ 2237c265f340SHarry Wentland int drm_mode_create_dp_colorspace_property(struct drm_connector *connector, 2238c265f340SHarry Wentland u32 supported_colorspaces) 223945cf0e91SGwan-gyeong Mun { 2240c265f340SHarry Wentland u32 colorspaces; 2241c265f340SHarry Wentland 2242c265f340SHarry Wentland if (supported_colorspaces) 2243c265f340SHarry Wentland colorspaces = supported_colorspaces & dp_colorspaces; 2244c265f340SHarry Wentland else 2245c265f340SHarry Wentland colorspaces = dp_colorspaces; 2246c265f340SHarry Wentland 2247c265f340SHarry Wentland return drm_mode_create_colorspace_property(connector, colorspaces); 224845cf0e91SGwan-gyeong Mun } 224945cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property); 225052217195SDaniel Vetter 225197e14fbeSDaniel Vetter /** 225252217195SDaniel Vetter * drm_mode_create_content_type_property - create content type property 225352217195SDaniel Vetter * @dev: DRM device 225497e14fbeSDaniel Vetter * 225552217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 225652217195SDaniel Vetter * connectors. 225752217195SDaniel Vetter * 225852217195SDaniel Vetter * Returns: 225952217195SDaniel Vetter * Zero on success, negative errno on failure. 226052217195SDaniel Vetter */ 226152217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev) 226252217195SDaniel Vetter { 226352217195SDaniel Vetter if (dev->mode_config.content_type_property) 226497e14fbeSDaniel Vetter return 0; 226552217195SDaniel Vetter 226652217195SDaniel Vetter dev->mode_config.content_type_property = 226752217195SDaniel Vetter drm_property_create_enum(dev, 0, "content type", 226852217195SDaniel Vetter drm_content_type_enum_list, 226952217195SDaniel Vetter ARRAY_SIZE(drm_content_type_enum_list)); 227052217195SDaniel Vetter 227152217195SDaniel Vetter if (dev->mode_config.content_type_property == NULL) 227252217195SDaniel Vetter return -ENOMEM; 227352217195SDaniel Vetter 227452217195SDaniel Vetter return 0; 227552217195SDaniel Vetter } 227652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property); 227752217195SDaniel Vetter 227852217195SDaniel Vetter /** 227952217195SDaniel Vetter * drm_mode_create_suggested_offset_properties - create suggests offset properties 228052217195SDaniel Vetter * @dev: DRM device 228152217195SDaniel Vetter * 228284e543bcSAntonio Borneo * Create the suggested x/y offset property for connectors. 2283f85d9e59SRandy Dunlap * 2284f85d9e59SRandy Dunlap * Returns: 2285f85d9e59SRandy Dunlap * 0 on success or a negative error code on failure. 228652217195SDaniel Vetter */ 228752217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev) 228852217195SDaniel Vetter { 228952217195SDaniel Vetter if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) 229052217195SDaniel Vetter return 0; 229152217195SDaniel Vetter 229252217195SDaniel Vetter dev->mode_config.suggested_x_property = 229352217195SDaniel Vetter drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); 229452217195SDaniel Vetter 229552217195SDaniel Vetter dev->mode_config.suggested_y_property = 229652217195SDaniel Vetter drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); 229752217195SDaniel Vetter 229852217195SDaniel Vetter if (dev->mode_config.suggested_x_property == NULL || 229952217195SDaniel Vetter dev->mode_config.suggested_y_property == NULL) 230052217195SDaniel Vetter return -ENOMEM; 230152217195SDaniel Vetter return 0; 230252217195SDaniel Vetter } 230352217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); 230452217195SDaniel Vetter 230552217195SDaniel Vetter /** 230652217195SDaniel Vetter * drm_connector_set_path_property - set tile property on connector 230752217195SDaniel Vetter * @connector: connector to set property on. 230852217195SDaniel Vetter * @path: path to use for property; must not be NULL. 230952217195SDaniel Vetter * 231052217195SDaniel Vetter * This creates a property to expose to userspace to specify a 231152217195SDaniel Vetter * connector path. This is mainly used for DisplayPort MST where 231252217195SDaniel Vetter * connectors have a topology and we want to allow userspace to give 231352217195SDaniel Vetter * them more meaningful names. 231452217195SDaniel Vetter * 231552217195SDaniel Vetter * Returns: 231652217195SDaniel Vetter * Zero on success, negative errno on failure. 231752217195SDaniel Vetter */ 231852217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector, 231952217195SDaniel Vetter const char *path) 232052217195SDaniel Vetter { 232152217195SDaniel Vetter struct drm_device *dev = connector->dev; 232252217195SDaniel Vetter int ret; 232352217195SDaniel Vetter 232452217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 232552217195SDaniel Vetter &connector->path_blob_ptr, 232652217195SDaniel Vetter strlen(path) + 1, 232752217195SDaniel Vetter path, 232852217195SDaniel Vetter &connector->base, 232952217195SDaniel Vetter dev->mode_config.path_property); 233052217195SDaniel Vetter return ret; 233152217195SDaniel Vetter } 233252217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property); 233352217195SDaniel Vetter 233452217195SDaniel Vetter /** 233552217195SDaniel Vetter * drm_connector_set_tile_property - set tile property on connector 233652217195SDaniel Vetter * @connector: connector to set property on. 233752217195SDaniel Vetter * 233852217195SDaniel Vetter * This looks up the tile information for a connector, and creates a 233952217195SDaniel Vetter * property for userspace to parse if it exists. The property is of 234052217195SDaniel Vetter * the form of 8 integers using ':' as a separator. 23412de3a078SManasi Navare * This is used for dual port tiled displays with DisplayPort SST 23422de3a078SManasi Navare * or DisplayPort MST connectors. 234352217195SDaniel Vetter * 234452217195SDaniel Vetter * Returns: 234552217195SDaniel Vetter * Zero on success, errno on failure. 234652217195SDaniel Vetter */ 234752217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector) 234852217195SDaniel Vetter { 234952217195SDaniel Vetter struct drm_device *dev = connector->dev; 235052217195SDaniel Vetter char tile[256]; 235152217195SDaniel Vetter int ret; 235252217195SDaniel Vetter 235352217195SDaniel Vetter if (!connector->has_tile) { 235452217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 235552217195SDaniel Vetter &connector->tile_blob_ptr, 235652217195SDaniel Vetter 0, 235752217195SDaniel Vetter NULL, 235852217195SDaniel Vetter &connector->base, 235952217195SDaniel Vetter dev->mode_config.tile_property); 236052217195SDaniel Vetter return ret; 236152217195SDaniel Vetter } 236252217195SDaniel Vetter 236352217195SDaniel Vetter snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", 236452217195SDaniel Vetter connector->tile_group->id, connector->tile_is_single_monitor, 236552217195SDaniel Vetter connector->num_h_tile, connector->num_v_tile, 236652217195SDaniel Vetter connector->tile_h_loc, connector->tile_v_loc, 236752217195SDaniel Vetter connector->tile_h_size, connector->tile_v_size); 236852217195SDaniel Vetter 236952217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 237052217195SDaniel Vetter &connector->tile_blob_ptr, 237152217195SDaniel Vetter strlen(tile) + 1, 237252217195SDaniel Vetter tile, 237352217195SDaniel Vetter &connector->base, 237452217195SDaniel Vetter dev->mode_config.tile_property); 237552217195SDaniel Vetter return ret; 237652217195SDaniel Vetter } 237797e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property); 237852217195SDaniel Vetter 237952217195SDaniel Vetter /** 238097e14fbeSDaniel Vetter * drm_connector_set_link_status_property - Set link status property of a connector 238140ee6fbeSManasi Navare * @connector: drm connector 238240ee6fbeSManasi Navare * @link_status: new value of link status property (0: Good, 1: Bad) 238340ee6fbeSManasi Navare * 238440ee6fbeSManasi Navare * In usual working scenario, this link status property will always be set to 238540ee6fbeSManasi Navare * "GOOD". If something fails during or after a mode set, the kernel driver 238640ee6fbeSManasi Navare * may set this link status property to "BAD". The caller then needs to send a 238740ee6fbeSManasi Navare * hotplug uevent for userspace to re-check the valid modes through 238840ee6fbeSManasi Navare * GET_CONNECTOR_IOCTL and retry modeset. 238940ee6fbeSManasi Navare * 239040ee6fbeSManasi Navare * Note: Drivers cannot rely on userspace to support this property and 239140ee6fbeSManasi Navare * issue a modeset. As such, they may choose to handle issues (like 239240ee6fbeSManasi Navare * re-training a link) without userspace's intervention. 239340ee6fbeSManasi Navare * 239440ee6fbeSManasi Navare * The reason for adding this property is to handle link training failures, but 239540ee6fbeSManasi Navare * it is not limited to DP or link training. For example, if we implement 239640ee6fbeSManasi Navare * asynchronous setcrtc, this property can be used to report any failures in that. 239740ee6fbeSManasi Navare */ 239897e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector, 239940ee6fbeSManasi Navare uint64_t link_status) 240040ee6fbeSManasi Navare { 240140ee6fbeSManasi Navare struct drm_device *dev = connector->dev; 240240ee6fbeSManasi Navare 240340ee6fbeSManasi Navare drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 240440ee6fbeSManasi Navare connector->state->link_status = link_status; 240540ee6fbeSManasi Navare drm_modeset_unlock(&dev->mode_config.connection_mutex); 240640ee6fbeSManasi Navare } 240797e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property); 240840ee6fbeSManasi Navare 24098d70f395SHans de Goede /** 241047e22ff1SRadhakrishna Sripada * drm_connector_attach_max_bpc_property - attach "max bpc" property 241147e22ff1SRadhakrishna Sripada * @connector: connector to attach max bpc property on. 241247e22ff1SRadhakrishna Sripada * @min: The minimum bit depth supported by the connector. 241347e22ff1SRadhakrishna Sripada * @max: The maximum bit depth supported by the connector. 241447e22ff1SRadhakrishna Sripada * 241547e22ff1SRadhakrishna Sripada * This is used to add support for limiting the bit depth on a connector. 241647e22ff1SRadhakrishna Sripada * 241747e22ff1SRadhakrishna Sripada * Returns: 241847e22ff1SRadhakrishna Sripada * Zero on success, negative errno on failure. 241947e22ff1SRadhakrishna Sripada */ 242047e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector, 242147e22ff1SRadhakrishna Sripada int min, int max) 242247e22ff1SRadhakrishna Sripada { 242347e22ff1SRadhakrishna Sripada struct drm_device *dev = connector->dev; 242447e22ff1SRadhakrishna Sripada struct drm_property *prop; 242547e22ff1SRadhakrishna Sripada 242647e22ff1SRadhakrishna Sripada prop = connector->max_bpc_property; 242747e22ff1SRadhakrishna Sripada if (!prop) { 242847e22ff1SRadhakrishna Sripada prop = drm_property_create_range(dev, 0, "max bpc", min, max); 242947e22ff1SRadhakrishna Sripada if (!prop) 243047e22ff1SRadhakrishna Sripada return -ENOMEM; 243147e22ff1SRadhakrishna Sripada 243247e22ff1SRadhakrishna Sripada connector->max_bpc_property = prop; 243347e22ff1SRadhakrishna Sripada } 243447e22ff1SRadhakrishna Sripada 243547e22ff1SRadhakrishna Sripada drm_object_attach_property(&connector->base, prop, max); 243647e22ff1SRadhakrishna Sripada connector->state->max_requested_bpc = max; 243747e22ff1SRadhakrishna Sripada connector->state->max_bpc = max; 243847e22ff1SRadhakrishna Sripada 243947e22ff1SRadhakrishna Sripada return 0; 244047e22ff1SRadhakrishna Sripada } 244147e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property); 244247e22ff1SRadhakrishna Sripada 244347e22ff1SRadhakrishna Sripada /** 2444e057b52cSMaxime Ripard * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property 2445e057b52cSMaxime Ripard * @connector: connector to attach the property on. 2446e057b52cSMaxime Ripard * 2447e057b52cSMaxime Ripard * This is used to allow the userspace to send HDR Metadata to the 2448e057b52cSMaxime Ripard * driver. 2449e057b52cSMaxime Ripard * 2450e057b52cSMaxime Ripard * Returns: 2451e057b52cSMaxime Ripard * Zero on success, negative errno on failure. 2452e057b52cSMaxime Ripard */ 2453e057b52cSMaxime Ripard int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector) 2454e057b52cSMaxime Ripard { 2455e057b52cSMaxime Ripard struct drm_device *dev = connector->dev; 2456e057b52cSMaxime Ripard struct drm_property *prop = dev->mode_config.hdr_output_metadata_property; 2457e057b52cSMaxime Ripard 2458e057b52cSMaxime Ripard drm_object_attach_property(&connector->base, prop, 0); 2459e057b52cSMaxime Ripard 2460e057b52cSMaxime Ripard return 0; 2461e057b52cSMaxime Ripard } 2462e057b52cSMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property); 2463e057b52cSMaxime Ripard 2464e057b52cSMaxime Ripard /** 246521f79128SMaxime Ripard * drm_connector_attach_colorspace_property - attach "Colorspace" property 246621f79128SMaxime Ripard * @connector: connector to attach the property on. 246721f79128SMaxime Ripard * 246821f79128SMaxime Ripard * This is used to allow the userspace to signal the output colorspace 246921f79128SMaxime Ripard * to the driver. 247021f79128SMaxime Ripard * 247121f79128SMaxime Ripard * Returns: 247221f79128SMaxime Ripard * Zero on success, negative errno on failure. 247321f79128SMaxime Ripard */ 247421f79128SMaxime Ripard int drm_connector_attach_colorspace_property(struct drm_connector *connector) 247521f79128SMaxime Ripard { 247621f79128SMaxime Ripard struct drm_property *prop = connector->colorspace_property; 247721f79128SMaxime Ripard 247821f79128SMaxime Ripard drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT); 247921f79128SMaxime Ripard 248021f79128SMaxime Ripard return 0; 248121f79128SMaxime Ripard } 248221f79128SMaxime Ripard EXPORT_SYMBOL(drm_connector_attach_colorspace_property); 248321f79128SMaxime Ripard 248421f79128SMaxime Ripard /** 248572921cdfSMaxime Ripard * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed 248672921cdfSMaxime Ripard * @old_state: old connector state to compare 248772921cdfSMaxime Ripard * @new_state: new connector state to compare 248872921cdfSMaxime Ripard * 248972921cdfSMaxime Ripard * This is used by HDR-enabled drivers to test whether the HDR metadata 249072921cdfSMaxime Ripard * have changed between two different connector state (and thus probably 249172921cdfSMaxime Ripard * requires a full blown mode change). 249272921cdfSMaxime Ripard * 249372921cdfSMaxime Ripard * Returns: 249472921cdfSMaxime Ripard * True if the metadata are equal, False otherwise 249572921cdfSMaxime Ripard */ 249672921cdfSMaxime Ripard bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state, 249772921cdfSMaxime Ripard struct drm_connector_state *new_state) 249872921cdfSMaxime Ripard { 249972921cdfSMaxime Ripard struct drm_property_blob *old_blob = old_state->hdr_output_metadata; 250072921cdfSMaxime Ripard struct drm_property_blob *new_blob = new_state->hdr_output_metadata; 250172921cdfSMaxime Ripard 250272921cdfSMaxime Ripard if (!old_blob || !new_blob) 250372921cdfSMaxime Ripard return old_blob == new_blob; 250472921cdfSMaxime Ripard 250572921cdfSMaxime Ripard if (old_blob->length != new_blob->length) 250672921cdfSMaxime Ripard return false; 250772921cdfSMaxime Ripard 250872921cdfSMaxime Ripard return !memcmp(old_blob->data, new_blob->data, old_blob->length); 250972921cdfSMaxime Ripard } 251072921cdfSMaxime Ripard EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal); 251172921cdfSMaxime Ripard 251272921cdfSMaxime Ripard /** 2513ba1b0f6cSNicholas Kazlauskas * drm_connector_set_vrr_capable_property - sets the variable refresh rate 2514ba1b0f6cSNicholas Kazlauskas * capable property for a connector 2515ba1b0f6cSNicholas Kazlauskas * @connector: drm connector 2516ba1b0f6cSNicholas Kazlauskas * @capable: True if the connector is variable refresh rate capable 2517ba1b0f6cSNicholas Kazlauskas * 2518ba1b0f6cSNicholas Kazlauskas * Should be used by atomic drivers to update the indicated support for 2519ba1b0f6cSNicholas Kazlauskas * variable refresh rate over a connector. 2520ba1b0f6cSNicholas Kazlauskas */ 2521ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property( 2522ba1b0f6cSNicholas Kazlauskas struct drm_connector *connector, bool capable) 2523ba1b0f6cSNicholas Kazlauskas { 252462929726SManasi Navare if (!connector->vrr_capable_property) 252562929726SManasi Navare return; 252662929726SManasi Navare 2527ba1b0f6cSNicholas Kazlauskas drm_object_property_set_value(&connector->base, 2528ba1b0f6cSNicholas Kazlauskas connector->vrr_capable_property, 2529ba1b0f6cSNicholas Kazlauskas capable); 2530ba1b0f6cSNicholas Kazlauskas } 2531ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property); 2532ba1b0f6cSNicholas Kazlauskas 2533ba1b0f6cSNicholas Kazlauskas /** 253484e543bcSAntonio Borneo * drm_connector_set_panel_orientation - sets the connector's panel_orientation 253569654c63SDerek Basehore * @connector: connector for which to set the panel-orientation property. 253669654c63SDerek Basehore * @panel_orientation: drm_panel_orientation value to set 25378d70f395SHans de Goede * 253869654c63SDerek Basehore * This function sets the connector's panel_orientation and attaches 253969654c63SDerek Basehore * a "panel orientation" property to the connector. 25408d70f395SHans de Goede * 254169654c63SDerek Basehore * Calling this function on a connector where the panel_orientation has 254269654c63SDerek Basehore * already been set is a no-op (e.g. the orientation has been overridden with 254369654c63SDerek Basehore * a kernel commandline option). 254469654c63SDerek Basehore * 254569654c63SDerek Basehore * It is allowed to call this function with a panel_orientation of 254669654c63SDerek Basehore * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op. 25478d70f395SHans de Goede * 25485e41b01aSHsin-Yi Wang * The function shouldn't be called in panel after drm is registered (i.e. 25495e41b01aSHsin-Yi Wang * drm_dev_register() is called in drm). 25505e41b01aSHsin-Yi Wang * 25518d70f395SHans de Goede * Returns: 25528d70f395SHans de Goede * Zero on success, negative errno on failure. 25538d70f395SHans de Goede */ 255469654c63SDerek Basehore int drm_connector_set_panel_orientation( 255569654c63SDerek Basehore struct drm_connector *connector, 255669654c63SDerek Basehore enum drm_panel_orientation panel_orientation) 25578d70f395SHans de Goede { 25588d70f395SHans de Goede struct drm_device *dev = connector->dev; 25598d70f395SHans de Goede struct drm_display_info *info = &connector->display_info; 25608d70f395SHans de Goede struct drm_property *prop; 25618d70f395SHans de Goede 256269654c63SDerek Basehore /* Already set? */ 256369654c63SDerek Basehore if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 25648d70f395SHans de Goede return 0; 25658d70f395SHans de Goede 256669654c63SDerek Basehore /* Don't attach the property if the orientation is unknown */ 256769654c63SDerek Basehore if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 256869654c63SDerek Basehore return 0; 256969654c63SDerek Basehore 257069654c63SDerek Basehore info->panel_orientation = panel_orientation; 257169654c63SDerek Basehore 25728d70f395SHans de Goede prop = dev->mode_config.panel_orientation_property; 25738d70f395SHans de Goede if (!prop) { 25748d70f395SHans de Goede prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 25758d70f395SHans de Goede "panel orientation", 25768d70f395SHans de Goede drm_panel_orientation_enum_list, 25778d70f395SHans de Goede ARRAY_SIZE(drm_panel_orientation_enum_list)); 25788d70f395SHans de Goede if (!prop) 25798d70f395SHans de Goede return -ENOMEM; 25808d70f395SHans de Goede 25818d70f395SHans de Goede dev->mode_config.panel_orientation_property = prop; 25828d70f395SHans de Goede } 25838d70f395SHans de Goede 25848d70f395SHans de Goede drm_object_attach_property(&connector->base, prop, 25858d70f395SHans de Goede info->panel_orientation); 25868d70f395SHans de Goede return 0; 25878d70f395SHans de Goede } 258869654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation); 258969654c63SDerek Basehore 259069654c63SDerek Basehore /** 2591f85d9e59SRandy Dunlap * drm_connector_set_panel_orientation_with_quirk - set the 2592f85d9e59SRandy Dunlap * connector's panel_orientation after checking for quirks 259369654c63SDerek Basehore * @connector: connector for which to init the panel-orientation property. 259469654c63SDerek Basehore * @panel_orientation: drm_panel_orientation value to set 259569654c63SDerek Basehore * @width: width in pixels of the panel, used for panel quirk detection 259669654c63SDerek Basehore * @height: height in pixels of the panel, used for panel quirk detection 259769654c63SDerek Basehore * 259869654c63SDerek Basehore * Like drm_connector_set_panel_orientation(), but with a check for platform 259969654c63SDerek Basehore * specific (e.g. DMI based) quirks overriding the passed in panel_orientation. 260069654c63SDerek Basehore * 260169654c63SDerek Basehore * Returns: 260269654c63SDerek Basehore * Zero on success, negative errno on failure. 260369654c63SDerek Basehore */ 260469654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk( 260569654c63SDerek Basehore struct drm_connector *connector, 260669654c63SDerek Basehore enum drm_panel_orientation panel_orientation, 260769654c63SDerek Basehore int width, int height) 260869654c63SDerek Basehore { 260969654c63SDerek Basehore int orientation_quirk; 261069654c63SDerek Basehore 261169654c63SDerek Basehore orientation_quirk = drm_get_panel_orientation_quirk(width, height); 261269654c63SDerek Basehore if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 261369654c63SDerek Basehore panel_orientation = orientation_quirk; 261469654c63SDerek Basehore 261569654c63SDerek Basehore return drm_connector_set_panel_orientation(connector, 261669654c63SDerek Basehore panel_orientation); 261769654c63SDerek Basehore } 261869654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk); 26198d70f395SHans de Goede 26205e41b01aSHsin-Yi Wang /** 26215e41b01aSHsin-Yi Wang * drm_connector_set_orientation_from_panel - 26225e41b01aSHsin-Yi Wang * set the connector's panel_orientation from panel's callback. 26235e41b01aSHsin-Yi Wang * @connector: connector for which to init the panel-orientation property. 26245e41b01aSHsin-Yi Wang * @panel: panel that can provide orientation information. 26255e41b01aSHsin-Yi Wang * 26265e41b01aSHsin-Yi Wang * Drm drivers should call this function before drm_dev_register(). 26275e41b01aSHsin-Yi Wang * Orientation is obtained from panel's .get_orientation() callback. 26285e41b01aSHsin-Yi Wang * 26295e41b01aSHsin-Yi Wang * Returns: 26305e41b01aSHsin-Yi Wang * Zero on success, negative errno on failure. 26315e41b01aSHsin-Yi Wang */ 26325e41b01aSHsin-Yi Wang int drm_connector_set_orientation_from_panel( 26335e41b01aSHsin-Yi Wang struct drm_connector *connector, 26345e41b01aSHsin-Yi Wang struct drm_panel *panel) 26355e41b01aSHsin-Yi Wang { 26365e41b01aSHsin-Yi Wang enum drm_panel_orientation orientation; 26375e41b01aSHsin-Yi Wang 26385e41b01aSHsin-Yi Wang if (panel && panel->funcs && panel->funcs->get_orientation) 26395e41b01aSHsin-Yi Wang orientation = panel->funcs->get_orientation(panel); 26405e41b01aSHsin-Yi Wang else 26415e41b01aSHsin-Yi Wang orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 26425e41b01aSHsin-Yi Wang 26435e41b01aSHsin-Yi Wang return drm_connector_set_panel_orientation(connector, orientation); 26445e41b01aSHsin-Yi Wang } 26455e41b01aSHsin-Yi Wang EXPORT_SYMBOL(drm_connector_set_orientation_from_panel); 26465e41b01aSHsin-Yi Wang 2647107fe904SRajat Jain static const struct drm_prop_enum_list privacy_screen_enum[] = { 2648107fe904SRajat Jain { PRIVACY_SCREEN_DISABLED, "Disabled" }, 2649107fe904SRajat Jain { PRIVACY_SCREEN_ENABLED, "Enabled" }, 2650107fe904SRajat Jain { PRIVACY_SCREEN_DISABLED_LOCKED, "Disabled-locked" }, 2651107fe904SRajat Jain { PRIVACY_SCREEN_ENABLED_LOCKED, "Enabled-locked" }, 2652107fe904SRajat Jain }; 2653107fe904SRajat Jain 2654107fe904SRajat Jain /** 2655107fe904SRajat Jain * drm_connector_create_privacy_screen_properties - create the drm connecter's 2656107fe904SRajat Jain * privacy-screen properties. 2657107fe904SRajat Jain * @connector: connector for which to create the privacy-screen properties 2658107fe904SRajat Jain * 2659107fe904SRajat Jain * This function creates the "privacy-screen sw-state" and "privacy-screen 2660107fe904SRajat Jain * hw-state" properties for the connector. They are not attached. 2661107fe904SRajat Jain */ 2662107fe904SRajat Jain void 2663107fe904SRajat Jain drm_connector_create_privacy_screen_properties(struct drm_connector *connector) 2664107fe904SRajat Jain { 2665107fe904SRajat Jain if (connector->privacy_screen_sw_state_property) 2666107fe904SRajat Jain return; 2667107fe904SRajat Jain 2668107fe904SRajat Jain /* Note sw-state only supports the first 2 values of the enum */ 2669107fe904SRajat Jain connector->privacy_screen_sw_state_property = 2670107fe904SRajat Jain drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM, 2671107fe904SRajat Jain "privacy-screen sw-state", 2672107fe904SRajat Jain privacy_screen_enum, 2); 2673107fe904SRajat Jain 2674107fe904SRajat Jain connector->privacy_screen_hw_state_property = 2675107fe904SRajat Jain drm_property_create_enum(connector->dev, 2676107fe904SRajat Jain DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM, 2677107fe904SRajat Jain "privacy-screen hw-state", 2678107fe904SRajat Jain privacy_screen_enum, 2679107fe904SRajat Jain ARRAY_SIZE(privacy_screen_enum)); 2680107fe904SRajat Jain } 2681107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties); 2682107fe904SRajat Jain 2683107fe904SRajat Jain /** 2684107fe904SRajat Jain * drm_connector_attach_privacy_screen_properties - attach the drm connecter's 2685107fe904SRajat Jain * privacy-screen properties. 2686107fe904SRajat Jain * @connector: connector on which to attach the privacy-screen properties 2687107fe904SRajat Jain * 2688107fe904SRajat Jain * This function attaches the "privacy-screen sw-state" and "privacy-screen 2689107fe904SRajat Jain * hw-state" properties to the connector. The initial state of both is set 2690107fe904SRajat Jain * to "Disabled". 2691107fe904SRajat Jain */ 2692107fe904SRajat Jain void 2693107fe904SRajat Jain drm_connector_attach_privacy_screen_properties(struct drm_connector *connector) 2694107fe904SRajat Jain { 2695107fe904SRajat Jain if (!connector->privacy_screen_sw_state_property) 2696107fe904SRajat Jain return; 2697107fe904SRajat Jain 2698107fe904SRajat Jain drm_object_attach_property(&connector->base, 2699107fe904SRajat Jain connector->privacy_screen_sw_state_property, 2700107fe904SRajat Jain PRIVACY_SCREEN_DISABLED); 2701107fe904SRajat Jain 2702107fe904SRajat Jain drm_object_attach_property(&connector->base, 2703107fe904SRajat Jain connector->privacy_screen_hw_state_property, 2704107fe904SRajat Jain PRIVACY_SCREEN_DISABLED); 2705107fe904SRajat Jain } 2706107fe904SRajat Jain EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties); 2707107fe904SRajat Jain 2708334f74eeSHans de Goede static void drm_connector_update_privacy_screen_properties( 2709334f74eeSHans de Goede struct drm_connector *connector, bool set_sw_state) 2710334f74eeSHans de Goede { 2711334f74eeSHans de Goede enum drm_privacy_screen_status sw_state, hw_state; 2712334f74eeSHans de Goede 2713334f74eeSHans de Goede drm_privacy_screen_get_state(connector->privacy_screen, 2714334f74eeSHans de Goede &sw_state, &hw_state); 2715334f74eeSHans de Goede 2716334f74eeSHans de Goede if (set_sw_state) 2717334f74eeSHans de Goede connector->state->privacy_screen_sw_state = sw_state; 2718334f74eeSHans de Goede drm_object_property_set_value(&connector->base, 2719334f74eeSHans de Goede connector->privacy_screen_hw_state_property, hw_state); 2720334f74eeSHans de Goede } 2721334f74eeSHans de Goede 2722334f74eeSHans de Goede static int drm_connector_privacy_screen_notifier( 2723334f74eeSHans de Goede struct notifier_block *nb, unsigned long action, void *data) 2724334f74eeSHans de Goede { 2725334f74eeSHans de Goede struct drm_connector *connector = 2726334f74eeSHans de Goede container_of(nb, struct drm_connector, privacy_screen_notifier); 2727334f74eeSHans de Goede struct drm_device *dev = connector->dev; 2728334f74eeSHans de Goede 2729334f74eeSHans de Goede drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 2730334f74eeSHans de Goede drm_connector_update_privacy_screen_properties(connector, true); 2731334f74eeSHans de Goede drm_modeset_unlock(&dev->mode_config.connection_mutex); 2732334f74eeSHans de Goede 2733*0cf8d292SSimon Ser drm_sysfs_connector_property_event(connector, 2734334f74eeSHans de Goede connector->privacy_screen_sw_state_property); 2735*0cf8d292SSimon Ser drm_sysfs_connector_property_event(connector, 2736334f74eeSHans de Goede connector->privacy_screen_hw_state_property); 2737334f74eeSHans de Goede 2738334f74eeSHans de Goede return NOTIFY_DONE; 2739334f74eeSHans de Goede } 2740334f74eeSHans de Goede 2741334f74eeSHans de Goede /** 2742334f74eeSHans de Goede * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to 2743334f74eeSHans de Goede * the connector 2744334f74eeSHans de Goede * @connector: connector to attach the privacy-screen to 2745334f74eeSHans de Goede * @priv: drm_privacy_screen to attach 2746334f74eeSHans de Goede * 2747334f74eeSHans de Goede * Create and attach the standard privacy-screen properties and register 2748334f74eeSHans de Goede * a generic notifier for generating sysfs-connector-status-events 2749334f74eeSHans de Goede * on external changes to the privacy-screen status. 2750334f74eeSHans de Goede * This function takes ownership of the passed in drm_privacy_screen and will 2751334f74eeSHans de Goede * call drm_privacy_screen_put() on it when the connector is destroyed. 2752334f74eeSHans de Goede */ 2753334f74eeSHans de Goede void drm_connector_attach_privacy_screen_provider( 2754334f74eeSHans de Goede struct drm_connector *connector, struct drm_privacy_screen *priv) 2755334f74eeSHans de Goede { 2756334f74eeSHans de Goede connector->privacy_screen = priv; 2757334f74eeSHans de Goede connector->privacy_screen_notifier.notifier_call = 2758334f74eeSHans de Goede drm_connector_privacy_screen_notifier; 2759334f74eeSHans de Goede 2760334f74eeSHans de Goede drm_connector_create_privacy_screen_properties(connector); 2761334f74eeSHans de Goede drm_connector_update_privacy_screen_properties(connector, true); 2762334f74eeSHans de Goede drm_connector_attach_privacy_screen_properties(connector); 2763334f74eeSHans de Goede } 2764334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider); 2765334f74eeSHans de Goede 2766334f74eeSHans de Goede /** 2767334f74eeSHans de Goede * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state 2768334f74eeSHans de Goede * @connector_state: connector-state to update the privacy-screen for 2769334f74eeSHans de Goede * 2770334f74eeSHans de Goede * This function calls drm_privacy_screen_set_sw_state() on the connector's 2771334f74eeSHans de Goede * privacy-screen. 2772334f74eeSHans de Goede * 2773334f74eeSHans de Goede * If the connector has no privacy-screen, then this is a no-op. 2774334f74eeSHans de Goede */ 2775334f74eeSHans de Goede void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state) 2776334f74eeSHans de Goede { 2777334f74eeSHans de Goede struct drm_connector *connector = connector_state->connector; 2778334f74eeSHans de Goede int ret; 2779334f74eeSHans de Goede 2780334f74eeSHans de Goede if (!connector->privacy_screen) 2781334f74eeSHans de Goede return; 2782334f74eeSHans de Goede 2783334f74eeSHans de Goede ret = drm_privacy_screen_set_sw_state(connector->privacy_screen, 2784334f74eeSHans de Goede connector_state->privacy_screen_sw_state); 2785334f74eeSHans de Goede if (ret) { 2786334f74eeSHans de Goede drm_err(connector->dev, "Error updating privacy-screen sw_state\n"); 2787334f74eeSHans de Goede return; 2788334f74eeSHans de Goede } 2789334f74eeSHans de Goede 2790334f74eeSHans de Goede /* The hw_state property value may have changed, update it. */ 2791334f74eeSHans de Goede drm_connector_update_privacy_screen_properties(connector, false); 2792334f74eeSHans de Goede } 2793334f74eeSHans de Goede EXPORT_SYMBOL(drm_connector_update_privacy_screen); 2794334f74eeSHans de Goede 279597e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj, 279652217195SDaniel Vetter struct drm_property *property, 279752217195SDaniel Vetter uint64_t value) 279852217195SDaniel Vetter { 279952217195SDaniel Vetter int ret = -EINVAL; 280052217195SDaniel Vetter struct drm_connector *connector = obj_to_connector(obj); 280152217195SDaniel Vetter 280252217195SDaniel Vetter /* Do DPMS ourselves */ 280352217195SDaniel Vetter if (property == connector->dev->mode_config.dpms_property) { 280452217195SDaniel Vetter ret = (*connector->funcs->dpms)(connector, (int)value); 280552217195SDaniel Vetter } else if (connector->funcs->set_property) 280652217195SDaniel Vetter ret = connector->funcs->set_property(connector, property, value); 280752217195SDaniel Vetter 2808144a7999SDaniel Vetter if (!ret) 280952217195SDaniel Vetter drm_object_property_set_value(&connector->base, property, value); 281052217195SDaniel Vetter return ret; 281152217195SDaniel Vetter } 281252217195SDaniel Vetter 281397e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev, 281452217195SDaniel Vetter void *data, struct drm_file *file_priv) 281552217195SDaniel Vetter { 281652217195SDaniel Vetter struct drm_mode_connector_set_property *conn_set_prop = data; 281752217195SDaniel Vetter struct drm_mode_obj_set_property obj_set_prop = { 281852217195SDaniel Vetter .value = conn_set_prop->value, 281952217195SDaniel Vetter .prop_id = conn_set_prop->prop_id, 282052217195SDaniel Vetter .obj_id = conn_set_prop->connector_id, 282152217195SDaniel Vetter .obj_type = DRM_MODE_OBJECT_CONNECTOR 282252217195SDaniel Vetter }; 282352217195SDaniel Vetter 282452217195SDaniel Vetter /* It does all the locking and checking we need */ 282552217195SDaniel Vetter return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv); 282652217195SDaniel Vetter } 282752217195SDaniel Vetter 282852217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) 282952217195SDaniel Vetter { 283052217195SDaniel Vetter /* For atomic drivers only state objects are synchronously updated and 2831c2ce66daSBeatriz Martins de Carvalho * protected by modeset locks, so check those first. 2832c2ce66daSBeatriz Martins de Carvalho */ 283352217195SDaniel Vetter if (connector->state) 283452217195SDaniel Vetter return connector->state->best_encoder; 283552217195SDaniel Vetter return connector->encoder; 283652217195SDaniel Vetter } 283752217195SDaniel Vetter 2838c3ff0cdbSAnkit Nautiyal static bool 2839c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode, 28408445e2c5SVille Syrjälä const struct list_head *modes, 284152217195SDaniel Vetter const struct drm_file *file_priv) 284252217195SDaniel Vetter { 284352217195SDaniel Vetter /* 284452217195SDaniel Vetter * If user-space hasn't configured the driver to expose the stereo 3D 284552217195SDaniel Vetter * modes, don't expose them. 284652217195SDaniel Vetter */ 284752217195SDaniel Vetter if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) 284852217195SDaniel Vetter return false; 2849c3ff0cdbSAnkit Nautiyal /* 2850c3ff0cdbSAnkit Nautiyal * If user-space hasn't configured the driver to expose the modes 2851c3ff0cdbSAnkit Nautiyal * with aspect-ratio, don't expose them. However if such a mode 2852c3ff0cdbSAnkit Nautiyal * is unique, let it be exposed, but reset the aspect-ratio flags 2853c3ff0cdbSAnkit Nautiyal * while preparing the list of user-modes. 2854c3ff0cdbSAnkit Nautiyal */ 2855c3ff0cdbSAnkit Nautiyal if (!file_priv->aspect_ratio_allowed) { 28568445e2c5SVille Syrjälä const struct drm_display_mode *mode_itr; 2857c3ff0cdbSAnkit Nautiyal 28588445e2c5SVille Syrjälä list_for_each_entry(mode_itr, modes, head) { 28598445e2c5SVille Syrjälä if (mode_itr->expose_to_userspace && 28608445e2c5SVille Syrjälä drm_mode_match(mode_itr, mode, 2861c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_TIMINGS | 2862c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_CLOCK | 2863c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_FLAGS | 2864c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_3D_FLAGS)) 2865c3ff0cdbSAnkit Nautiyal return false; 2866c3ff0cdbSAnkit Nautiyal } 28678445e2c5SVille Syrjälä } 286852217195SDaniel Vetter 286952217195SDaniel Vetter return true; 287052217195SDaniel Vetter } 287152217195SDaniel Vetter 287252217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data, 287352217195SDaniel Vetter struct drm_file *file_priv) 287452217195SDaniel Vetter { 287552217195SDaniel Vetter struct drm_mode_get_connector *out_resp = data; 287652217195SDaniel Vetter struct drm_connector *connector; 287752217195SDaniel Vetter struct drm_encoder *encoder; 287852217195SDaniel Vetter struct drm_display_mode *mode; 287952217195SDaniel Vetter int mode_count = 0; 288052217195SDaniel Vetter int encoders_count = 0; 288152217195SDaniel Vetter int ret = 0; 288252217195SDaniel Vetter int copied = 0; 288352217195SDaniel Vetter struct drm_mode_modeinfo u_mode; 288452217195SDaniel Vetter struct drm_mode_modeinfo __user *mode_ptr; 288552217195SDaniel Vetter uint32_t __user *encoder_ptr; 2886869e76f7SDesmond Cheong Zhi Xi bool is_current_master; 288752217195SDaniel Vetter 288852217195SDaniel Vetter if (!drm_core_check_feature(dev, DRIVER_MODESET)) 288969fdf420SChris Wilson return -EOPNOTSUPP; 289052217195SDaniel Vetter 289152217195SDaniel Vetter memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); 289252217195SDaniel Vetter 2893418da172SKeith Packard connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id); 289491eefc05SDaniel Vetter if (!connector) 289591eefc05SDaniel Vetter return -ENOENT; 289652217195SDaniel Vetter 289762afb4adSJosé Roberto de Souza encoders_count = hweight32(connector->possible_encoders); 289891eefc05SDaniel Vetter 289991eefc05SDaniel Vetter if ((out_resp->count_encoders >= encoders_count) && encoders_count) { 290091eefc05SDaniel Vetter copied = 0; 290191eefc05SDaniel Vetter encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); 290283aefbb8SVille Syrjälä 290362afb4adSJosé Roberto de Souza drm_connector_for_each_possible_encoder(connector, encoder) { 290483aefbb8SVille Syrjälä if (put_user(encoder->base.id, encoder_ptr + copied)) { 290591eefc05SDaniel Vetter ret = -EFAULT; 2906e94ac351SDaniel Vetter goto out; 290791eefc05SDaniel Vetter } 290891eefc05SDaniel Vetter copied++; 290991eefc05SDaniel Vetter } 291091eefc05SDaniel Vetter } 291191eefc05SDaniel Vetter out_resp->count_encoders = encoders_count; 291291eefc05SDaniel Vetter 291391eefc05SDaniel Vetter out_resp->connector_id = connector->base.id; 291491eefc05SDaniel Vetter out_resp->connector_type = connector->connector_type; 291591eefc05SDaniel Vetter out_resp->connector_type_id = connector->connector_type_id; 291691eefc05SDaniel Vetter 2917869e76f7SDesmond Cheong Zhi Xi is_current_master = drm_is_current_master(file_priv); 2918869e76f7SDesmond Cheong Zhi Xi 291991eefc05SDaniel Vetter mutex_lock(&dev->mode_config.mutex); 292091eefc05SDaniel Vetter if (out_resp->count_modes == 0) { 2921869e76f7SDesmond Cheong Zhi Xi if (is_current_master) 292291eefc05SDaniel Vetter connector->funcs->fill_modes(connector, 292391eefc05SDaniel Vetter dev->mode_config.max_width, 292491eefc05SDaniel Vetter dev->mode_config.max_height); 29258f86c82aSSimon Ser else 29268f86c82aSSimon Ser drm_dbg_kms(dev, "User-space requested a forced probe on [CONNECTOR:%d:%s] but is not the DRM master, demoting to read-only probe", 29278f86c82aSSimon Ser connector->base.id, connector->name); 292891eefc05SDaniel Vetter } 292991eefc05SDaniel Vetter 293091eefc05SDaniel Vetter out_resp->mm_width = connector->display_info.width_mm; 293191eefc05SDaniel Vetter out_resp->mm_height = connector->display_info.height_mm; 293291eefc05SDaniel Vetter out_resp->subpixel = connector->display_info.subpixel_order; 293391eefc05SDaniel Vetter out_resp->connection = connector->status; 293491eefc05SDaniel Vetter 293591eefc05SDaniel Vetter /* delayed so we get modes regardless of pre-fill_modes state */ 29368445e2c5SVille Syrjälä list_for_each_entry(mode, &connector->modes, head) { 29378445e2c5SVille Syrjälä WARN_ON(mode->expose_to_userspace); 29388445e2c5SVille Syrjälä 29398445e2c5SVille Syrjälä if (drm_mode_expose_to_userspace(mode, &connector->modes, 2940c3ff0cdbSAnkit Nautiyal file_priv)) { 29418445e2c5SVille Syrjälä mode->expose_to_userspace = true; 294291eefc05SDaniel Vetter mode_count++; 2943c3ff0cdbSAnkit Nautiyal } 29448445e2c5SVille Syrjälä } 294591eefc05SDaniel Vetter 294652217195SDaniel Vetter /* 294752217195SDaniel Vetter * This ioctl is called twice, once to determine how much space is 294852217195SDaniel Vetter * needed, and the 2nd time to fill it. 294952217195SDaniel Vetter */ 295052217195SDaniel Vetter if ((out_resp->count_modes >= mode_count) && mode_count) { 295152217195SDaniel Vetter copied = 0; 295252217195SDaniel Vetter mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; 29538445e2c5SVille Syrjälä list_for_each_entry(mode, &connector->modes, head) { 29548445e2c5SVille Syrjälä if (!mode->expose_to_userspace) 29558445e2c5SVille Syrjälä continue; 29568445e2c5SVille Syrjälä 29578445e2c5SVille Syrjälä /* Clear the tag for the next time around */ 29588445e2c5SVille Syrjälä mode->expose_to_userspace = false; 29598445e2c5SVille Syrjälä 296052217195SDaniel Vetter drm_mode_convert_to_umode(&u_mode, mode); 2961c3ff0cdbSAnkit Nautiyal /* 2962c3ff0cdbSAnkit Nautiyal * Reset aspect ratio flags of user-mode, if modes with 2963c3ff0cdbSAnkit Nautiyal * aspect-ratio are not supported. 2964c3ff0cdbSAnkit Nautiyal */ 2965c3ff0cdbSAnkit Nautiyal if (!file_priv->aspect_ratio_allowed) 2966c3ff0cdbSAnkit Nautiyal u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK; 296752217195SDaniel Vetter if (copy_to_user(mode_ptr + copied, 296852217195SDaniel Vetter &u_mode, sizeof(u_mode))) { 296952217195SDaniel Vetter ret = -EFAULT; 29708445e2c5SVille Syrjälä 29718445e2c5SVille Syrjälä /* 29728445e2c5SVille Syrjälä * Clear the tag for the rest of 29738445e2c5SVille Syrjälä * the modes for the next time around. 29748445e2c5SVille Syrjälä */ 29758445e2c5SVille Syrjälä list_for_each_entry_continue(mode, &connector->modes, head) 29768445e2c5SVille Syrjälä mode->expose_to_userspace = false; 29778445e2c5SVille Syrjälä 2978e94ac351SDaniel Vetter mutex_unlock(&dev->mode_config.mutex); 2979e94ac351SDaniel Vetter 298052217195SDaniel Vetter goto out; 298152217195SDaniel Vetter } 298252217195SDaniel Vetter copied++; 298352217195SDaniel Vetter } 29848445e2c5SVille Syrjälä } else { 29858445e2c5SVille Syrjälä /* Clear the tag for the next time around */ 29868445e2c5SVille Syrjälä list_for_each_entry(mode, &connector->modes, head) 29878445e2c5SVille Syrjälä mode->expose_to_userspace = false; 298852217195SDaniel Vetter } 29898445e2c5SVille Syrjälä 299052217195SDaniel Vetter out_resp->count_modes = mode_count; 299152217195SDaniel Vetter mutex_unlock(&dev->mode_config.mutex); 2992e94ac351SDaniel Vetter 2993e94ac351SDaniel Vetter drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 2994e94ac351SDaniel Vetter encoder = drm_connector_get_encoder(connector); 2995e94ac351SDaniel Vetter if (encoder) 2996e94ac351SDaniel Vetter out_resp->encoder_id = encoder->base.id; 2997e94ac351SDaniel Vetter else 2998e94ac351SDaniel Vetter out_resp->encoder_id = 0; 2999e94ac351SDaniel Vetter 3000e94ac351SDaniel Vetter /* Only grab properties after probing, to make sure EDID and other 3001c2ce66daSBeatriz Martins de Carvalho * properties reflect the latest status. 3002c2ce66daSBeatriz Martins de Carvalho */ 3003e94ac351SDaniel Vetter ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic, 3004e94ac351SDaniel Vetter (uint32_t __user *)(unsigned long)(out_resp->props_ptr), 3005e94ac351SDaniel Vetter (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), 3006e94ac351SDaniel Vetter &out_resp->count_props); 3007e94ac351SDaniel Vetter drm_modeset_unlock(&dev->mode_config.connection_mutex); 3008e94ac351SDaniel Vetter 3009e94ac351SDaniel Vetter out: 3010ad093607SThierry Reding drm_connector_put(connector); 301152217195SDaniel Vetter 301252217195SDaniel Vetter return ret; 301352217195SDaniel Vetter } 301452217195SDaniel Vetter 30153d3f7c1eSHans de Goede /** 30163d3f7c1eSHans de Goede * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode 30173d3f7c1eSHans de Goede * @fwnode: fwnode for which to find the matching drm_connector 30183d3f7c1eSHans de Goede * 30193d3f7c1eSHans de Goede * This functions looks up a drm_connector based on its associated fwnode. When 30203d3f7c1eSHans de Goede * a connector is found a reference to the connector is returned. The caller must 30213d3f7c1eSHans de Goede * call drm_connector_put() to release this reference when it is done with the 30223d3f7c1eSHans de Goede * connector. 30233d3f7c1eSHans de Goede * 30243d3f7c1eSHans de Goede * Returns: A reference to the found connector or an ERR_PTR(). 30253d3f7c1eSHans de Goede */ 30263d3f7c1eSHans de Goede struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode) 30273d3f7c1eSHans de Goede { 30283d3f7c1eSHans de Goede struct drm_connector *connector, *found = ERR_PTR(-ENODEV); 30293d3f7c1eSHans de Goede 30303d3f7c1eSHans de Goede if (!fwnode) 30313d3f7c1eSHans de Goede return ERR_PTR(-ENODEV); 30323d3f7c1eSHans de Goede 30333d3f7c1eSHans de Goede mutex_lock(&connector_list_lock); 30343d3f7c1eSHans de Goede 30353d3f7c1eSHans de Goede list_for_each_entry(connector, &connector_list, global_connector_list_entry) { 30363d3f7c1eSHans de Goede if (connector->fwnode == fwnode || 30373d3f7c1eSHans de Goede (connector->fwnode && connector->fwnode->secondary == fwnode)) { 30383d3f7c1eSHans de Goede drm_connector_get(connector); 30393d3f7c1eSHans de Goede found = connector; 30403d3f7c1eSHans de Goede break; 30413d3f7c1eSHans de Goede } 30423d3f7c1eSHans de Goede } 30433d3f7c1eSHans de Goede 30443d3f7c1eSHans de Goede mutex_unlock(&connector_list_lock); 30453d3f7c1eSHans de Goede 30463d3f7c1eSHans de Goede return found; 30473d3f7c1eSHans de Goede } 30483d3f7c1eSHans de Goede 304972ad4968SHans de Goede /** 305072ad4968SHans de Goede * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector 3051f85d9e59SRandy Dunlap * @connector_fwnode: fwnode_handle to report the event on 305272ad4968SHans de Goede * 305372ad4968SHans de Goede * On some hardware a hotplug event notification may come from outside the display 305472ad4968SHans de Goede * driver / device. An example of this is some USB Type-C setups where the hardware 305572ad4968SHans de Goede * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD 305672ad4968SHans de Goede * status bit to the GPU's DP HPD pin. 305772ad4968SHans de Goede * 305872ad4968SHans de Goede * This function can be used to report these out-of-band events after obtaining 305972ad4968SHans de Goede * a drm_connector reference through calling drm_connector_find_by_fwnode(). 306072ad4968SHans de Goede */ 306172ad4968SHans de Goede void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode) 306272ad4968SHans de Goede { 306372ad4968SHans de Goede struct drm_connector *connector; 306472ad4968SHans de Goede 306572ad4968SHans de Goede connector = drm_connector_find_by_fwnode(connector_fwnode); 306672ad4968SHans de Goede if (IS_ERR(connector)) 306772ad4968SHans de Goede return; 306872ad4968SHans de Goede 306972ad4968SHans de Goede if (connector->funcs->oob_hotplug_event) 307072ad4968SHans de Goede connector->funcs->oob_hotplug_event(connector); 307172ad4968SHans de Goede 307272ad4968SHans de Goede drm_connector_put(connector); 307372ad4968SHans de Goede } 307472ad4968SHans de Goede EXPORT_SYMBOL(drm_connector_oob_hotplug_event); 307572ad4968SHans de Goede 30769498c19bSDaniel Vetter 30779498c19bSDaniel Vetter /** 30789498c19bSDaniel Vetter * DOC: Tile group 30799498c19bSDaniel Vetter * 30809498c19bSDaniel Vetter * Tile groups are used to represent tiled monitors with a unique integer 30819498c19bSDaniel Vetter * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle, 30829498c19bSDaniel Vetter * we store this in a tile group, so we have a common identifier for all tiles 30839498c19bSDaniel Vetter * in a monitor group. The property is called "TILE". Drivers can manage tile 30849498c19bSDaniel Vetter * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and 30859498c19bSDaniel Vetter * drm_mode_get_tile_group(). But this is only needed for internal panels where 30869498c19bSDaniel Vetter * the tile group information is exposed through a non-standard way. 30879498c19bSDaniel Vetter */ 30889498c19bSDaniel Vetter 30899498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref) 30909498c19bSDaniel Vetter { 30919498c19bSDaniel Vetter struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); 30929498c19bSDaniel Vetter struct drm_device *dev = tg->dev; 3093948de842SSuraj Upadhyay 30949498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 30959498c19bSDaniel Vetter idr_remove(&dev->mode_config.tile_idr, tg->id); 30969498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 30979498c19bSDaniel Vetter kfree(tg); 30989498c19bSDaniel Vetter } 30999498c19bSDaniel Vetter 31009498c19bSDaniel Vetter /** 31019498c19bSDaniel Vetter * drm_mode_put_tile_group - drop a reference to a tile group. 31029498c19bSDaniel Vetter * @dev: DRM device 31039498c19bSDaniel Vetter * @tg: tile group to drop reference to. 31049498c19bSDaniel Vetter * 31059498c19bSDaniel Vetter * drop reference to tile group and free if 0. 31069498c19bSDaniel Vetter */ 31079498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev, 31089498c19bSDaniel Vetter struct drm_tile_group *tg) 31099498c19bSDaniel Vetter { 31109498c19bSDaniel Vetter kref_put(&tg->refcount, drm_tile_group_free); 31119498c19bSDaniel Vetter } 31129498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group); 31139498c19bSDaniel Vetter 31149498c19bSDaniel Vetter /** 31159498c19bSDaniel Vetter * drm_mode_get_tile_group - get a reference to an existing tile group 31169498c19bSDaniel Vetter * @dev: DRM device 31179498c19bSDaniel Vetter * @topology: 8-bytes unique per monitor. 31189498c19bSDaniel Vetter * 31199498c19bSDaniel Vetter * Use the unique bytes to get a reference to an existing tile group. 31209498c19bSDaniel Vetter * 31219498c19bSDaniel Vetter * RETURNS: 31229498c19bSDaniel Vetter * tile group or NULL if not found. 31239498c19bSDaniel Vetter */ 31249498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 3125267ea759SVille Syrjälä const char topology[8]) 31269498c19bSDaniel Vetter { 31279498c19bSDaniel Vetter struct drm_tile_group *tg; 31289498c19bSDaniel Vetter int id; 3129948de842SSuraj Upadhyay 31309498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 31319498c19bSDaniel Vetter idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { 31329498c19bSDaniel Vetter if (!memcmp(tg->group_data, topology, 8)) { 31339498c19bSDaniel Vetter if (!kref_get_unless_zero(&tg->refcount)) 31349498c19bSDaniel Vetter tg = NULL; 31359498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 31369498c19bSDaniel Vetter return tg; 31379498c19bSDaniel Vetter } 31389498c19bSDaniel Vetter } 31399498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 31409498c19bSDaniel Vetter return NULL; 31419498c19bSDaniel Vetter } 31429498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group); 31439498c19bSDaniel Vetter 31449498c19bSDaniel Vetter /** 31459498c19bSDaniel Vetter * drm_mode_create_tile_group - create a tile group from a displayid description 31469498c19bSDaniel Vetter * @dev: DRM device 31479498c19bSDaniel Vetter * @topology: 8-bytes unique per monitor. 31489498c19bSDaniel Vetter * 31499498c19bSDaniel Vetter * Create a tile group for the unique monitor, and get a unique 31509498c19bSDaniel Vetter * identifier for the tile group. 31519498c19bSDaniel Vetter * 31529498c19bSDaniel Vetter * RETURNS: 3153705c8160SDan Carpenter * new tile group or NULL. 31549498c19bSDaniel Vetter */ 31559498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 3156267ea759SVille Syrjälä const char topology[8]) 31579498c19bSDaniel Vetter { 31589498c19bSDaniel Vetter struct drm_tile_group *tg; 31599498c19bSDaniel Vetter int ret; 31609498c19bSDaniel Vetter 31619498c19bSDaniel Vetter tg = kzalloc(sizeof(*tg), GFP_KERNEL); 31629498c19bSDaniel Vetter if (!tg) 3163705c8160SDan Carpenter return NULL; 31649498c19bSDaniel Vetter 31659498c19bSDaniel Vetter kref_init(&tg->refcount); 31669498c19bSDaniel Vetter memcpy(tg->group_data, topology, 8); 31679498c19bSDaniel Vetter tg->dev = dev; 31689498c19bSDaniel Vetter 31699498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 31709498c19bSDaniel Vetter ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); 31719498c19bSDaniel Vetter if (ret >= 0) { 31729498c19bSDaniel Vetter tg->id = ret; 31739498c19bSDaniel Vetter } else { 31749498c19bSDaniel Vetter kfree(tg); 3175705c8160SDan Carpenter tg = NULL; 31769498c19bSDaniel Vetter } 31779498c19bSDaniel Vetter 31789498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 31799498c19bSDaniel Vetter return tg; 31809498c19bSDaniel Vetter } 31819498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group); 3182