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 2352217195SDaniel Vetter #include <drm/drm_connector.h> 2452217195SDaniel Vetter #include <drm/drm_edid.h> 259338203cSLaurent Pinchart #include <drm/drm_encoder.h> 268d70f395SHans de Goede #include <drm/drm_utils.h> 2799f45e32SDaniel Vetter #include <drm/drm_print.h> 2899f45e32SDaniel Vetter #include <drm/drm_drv.h> 2999f45e32SDaniel Vetter #include <drm/drm_file.h> 30968d81a6SJeykumar Sankaran #include <drm/drm_sysfs.h> 3199f45e32SDaniel Vetter 3299f45e32SDaniel Vetter #include <linux/uaccess.h> 3352217195SDaniel Vetter 3452217195SDaniel Vetter #include "drm_crtc_internal.h" 3552217195SDaniel Vetter #include "drm_internal.h" 3652217195SDaniel Vetter 37ae2a6da8SDaniel Vetter /** 38ae2a6da8SDaniel Vetter * DOC: overview 39ae2a6da8SDaniel Vetter * 40ae2a6da8SDaniel Vetter * In DRM connectors are the general abstraction for display sinks, and include 4184e543bcSAntonio Borneo * also fixed panels or anything else that can display pixels in some form. As 42ae2a6da8SDaniel Vetter * opposed to all other KMS objects representing hardware (like CRTC, encoder or 43ae2a6da8SDaniel Vetter * plane abstractions) connectors can be hotplugged and unplugged at runtime. 44ad093607SThierry Reding * Hence they are reference-counted using drm_connector_get() and 45ad093607SThierry Reding * drm_connector_put(). 46ae2a6da8SDaniel Vetter * 47d574528aSDaniel Vetter * KMS driver must create, initialize, register and attach at a &struct 48d574528aSDaniel Vetter * drm_connector for each such sink. The instance is created as other KMS 49aec97460SDaniel Vetter * objects and initialized by setting the following fields. The connector is 50aec97460SDaniel Vetter * initialized with a call to drm_connector_init() with a pointer to the 51aec97460SDaniel Vetter * &struct drm_connector_funcs and a connector type, and then exposed to 52aec97460SDaniel Vetter * userspace with a call to drm_connector_register(). 53ae2a6da8SDaniel Vetter * 54ae2a6da8SDaniel Vetter * Connectors must be attached to an encoder to be used. For devices that map 55ae2a6da8SDaniel Vetter * connectors to encoders 1:1, the connector should be attached at 56cde4c44dSDaniel Vetter * initialization time with a call to drm_connector_attach_encoder(). The 57d574528aSDaniel Vetter * driver must also set the &drm_connector.encoder field to point to the 58ae2a6da8SDaniel Vetter * attached encoder. 59ae2a6da8SDaniel Vetter * 60ae2a6da8SDaniel Vetter * For connectors which are not fixed (like built-in panels) the driver needs to 61ae2a6da8SDaniel Vetter * support hotplug notifications. The simplest way to do that is by using the 62ae2a6da8SDaniel Vetter * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have 63ae2a6da8SDaniel Vetter * hardware support for hotplug interrupts. Connectors with hardware hotplug 64ae2a6da8SDaniel Vetter * support can instead use e.g. drm_helper_hpd_irq_event(). 65ae2a6da8SDaniel Vetter */ 66ae2a6da8SDaniel Vetter 6752217195SDaniel Vetter struct drm_conn_prop_enum_list { 6852217195SDaniel Vetter int type; 6952217195SDaniel Vetter const char *name; 7052217195SDaniel Vetter struct ida ida; 7152217195SDaniel Vetter }; 7252217195SDaniel Vetter 7352217195SDaniel Vetter /* 7452217195SDaniel Vetter * Connector and encoder types. 7552217195SDaniel Vetter */ 7652217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { 7752217195SDaniel Vetter { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, 7852217195SDaniel Vetter { DRM_MODE_CONNECTOR_VGA, "VGA" }, 7952217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, 8052217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, 8152217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, 8252217195SDaniel Vetter { DRM_MODE_CONNECTOR_Composite, "Composite" }, 8352217195SDaniel Vetter { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, 8452217195SDaniel Vetter { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, 8552217195SDaniel Vetter { DRM_MODE_CONNECTOR_Component, "Component" }, 8652217195SDaniel Vetter { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, 8752217195SDaniel Vetter { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, 8852217195SDaniel Vetter { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, 8952217195SDaniel Vetter { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, 9052217195SDaniel Vetter { DRM_MODE_CONNECTOR_TV, "TV" }, 9152217195SDaniel Vetter { DRM_MODE_CONNECTOR_eDP, "eDP" }, 9252217195SDaniel Vetter { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, 9352217195SDaniel Vetter { DRM_MODE_CONNECTOR_DSI, "DSI" }, 9452217195SDaniel Vetter { DRM_MODE_CONNECTOR_DPI, "DPI" }, 95935774cdSBrian Starkey { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, 96fc06bf1dSNoralf Trønnes { DRM_MODE_CONNECTOR_SPI, "SPI" }, 9752217195SDaniel Vetter }; 9852217195SDaniel Vetter 9952217195SDaniel Vetter void drm_connector_ida_init(void) 10052217195SDaniel Vetter { 10152217195SDaniel Vetter int i; 10252217195SDaniel Vetter 10352217195SDaniel Vetter for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 10452217195SDaniel Vetter ida_init(&drm_connector_enum_list[i].ida); 10552217195SDaniel Vetter } 10652217195SDaniel Vetter 10752217195SDaniel Vetter void drm_connector_ida_destroy(void) 10852217195SDaniel Vetter { 10952217195SDaniel Vetter int i; 11052217195SDaniel Vetter 11152217195SDaniel Vetter for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 11252217195SDaniel Vetter ida_destroy(&drm_connector_enum_list[i].ida); 11352217195SDaniel Vetter } 11452217195SDaniel Vetter 11552217195SDaniel Vetter /** 116b35f90f2SLaurent Pinchart * drm_get_connector_type_name - return a string for connector type 117b35f90f2SLaurent Pinchart * @type: The connector type (DRM_MODE_CONNECTOR_*) 118b35f90f2SLaurent Pinchart * 119b35f90f2SLaurent Pinchart * Returns: the name of the connector type, or NULL if the type is not valid. 120b35f90f2SLaurent Pinchart */ 121b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type) 122b35f90f2SLaurent Pinchart { 123b35f90f2SLaurent Pinchart if (type < ARRAY_SIZE(drm_connector_enum_list)) 124b35f90f2SLaurent Pinchart return drm_connector_enum_list[type].name; 125b35f90f2SLaurent Pinchart 126b35f90f2SLaurent Pinchart return NULL; 127b35f90f2SLaurent Pinchart } 128b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name); 129b35f90f2SLaurent Pinchart 130b35f90f2SLaurent Pinchart /** 13152217195SDaniel Vetter * drm_connector_get_cmdline_mode - reads the user's cmdline mode 13284e543bcSAntonio Borneo * @connector: connector to query 13352217195SDaniel Vetter * 134ae2a6da8SDaniel Vetter * The kernel supports per-connector configuration of its consoles through 13552217195SDaniel Vetter * use of the video= parameter. This function parses that option and 13652217195SDaniel Vetter * extracts the user's specified mode (or enable/disable status) for a 13752217195SDaniel Vetter * particular connector. This is typically only used during the early fbdev 13852217195SDaniel Vetter * setup. 13952217195SDaniel Vetter */ 14052217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector) 14152217195SDaniel Vetter { 14252217195SDaniel Vetter struct drm_cmdline_mode *mode = &connector->cmdline_mode; 14352217195SDaniel Vetter char *option = NULL; 14452217195SDaniel Vetter 14552217195SDaniel Vetter if (fb_get_options(connector->name, &option)) 14652217195SDaniel Vetter return; 14752217195SDaniel Vetter 14852217195SDaniel Vetter if (!drm_mode_parse_command_line_for_connector(option, 14952217195SDaniel Vetter connector, 15052217195SDaniel Vetter mode)) 15152217195SDaniel Vetter return; 15252217195SDaniel Vetter 15352217195SDaniel Vetter if (mode->force) { 1546140cf20SJani Nikula DRM_INFO("forcing %s connector %s\n", connector->name, 1556140cf20SJani Nikula drm_get_connector_force_name(mode->force)); 15652217195SDaniel Vetter connector->force = mode->force; 15752217195SDaniel Vetter } 15852217195SDaniel Vetter 1590980939dSHans de Goede if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) { 1600980939dSHans de Goede DRM_INFO("cmdline forces connector %s panel_orientation to %d\n", 1610980939dSHans de Goede connector->name, mode->panel_orientation); 1620980939dSHans de Goede drm_connector_set_panel_orientation(connector, 1630980939dSHans de Goede mode->panel_orientation); 1640980939dSHans de Goede } 1650980939dSHans de Goede 1663aeeb13dSMaxime Ripard DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n", 16750b0946dSMaxime Ripard connector->name, mode->name, 16852217195SDaniel Vetter mode->xres, mode->yres, 16952217195SDaniel Vetter mode->refresh_specified ? mode->refresh : 60, 17052217195SDaniel Vetter mode->rb ? " reduced blanking" : "", 17152217195SDaniel Vetter mode->margins ? " with margins" : "", 17252217195SDaniel Vetter mode->interlace ? " interlaced" : ""); 17352217195SDaniel Vetter } 17452217195SDaniel Vetter 17552217195SDaniel Vetter static void drm_connector_free(struct kref *kref) 17652217195SDaniel Vetter { 17752217195SDaniel Vetter struct drm_connector *connector = 17852217195SDaniel Vetter container_of(kref, struct drm_connector, base.refcount); 17952217195SDaniel Vetter struct drm_device *dev = connector->dev; 18052217195SDaniel Vetter 18152217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 18252217195SDaniel Vetter connector->funcs->destroy(connector); 18352217195SDaniel Vetter } 18452217195SDaniel Vetter 185ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work) 186a703c550SDaniel Vetter { 187ea497bb9SDaniel Vetter struct drm_connector *connector, *n; 188ea497bb9SDaniel Vetter struct drm_device *dev = 189ea497bb9SDaniel Vetter container_of(work, struct drm_device, mode_config.connector_free_work); 190ea497bb9SDaniel Vetter struct drm_mode_config *config = &dev->mode_config; 191ea497bb9SDaniel Vetter unsigned long flags; 192ea497bb9SDaniel Vetter struct llist_node *freed; 193a703c550SDaniel Vetter 194ea497bb9SDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 195ea497bb9SDaniel Vetter freed = llist_del_all(&config->connector_free_list); 196ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 197ea497bb9SDaniel Vetter 198ea497bb9SDaniel Vetter llist_for_each_entry_safe(connector, n, freed, free_node) { 199a703c550SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 200a703c550SDaniel Vetter connector->funcs->destroy(connector); 201a703c550SDaniel Vetter } 202ea497bb9SDaniel Vetter } 203a703c550SDaniel Vetter 20452217195SDaniel Vetter /** 20552217195SDaniel Vetter * drm_connector_init - Init a preallocated connector 20652217195SDaniel Vetter * @dev: DRM device 20752217195SDaniel Vetter * @connector: the connector to init 20852217195SDaniel Vetter * @funcs: callbacks for this connector 20952217195SDaniel Vetter * @connector_type: user visible type of the connector 21052217195SDaniel Vetter * 21152217195SDaniel Vetter * Initialises a preallocated connector. Connectors should be 21252217195SDaniel Vetter * subclassed as part of driver connector objects. 21352217195SDaniel Vetter * 21452217195SDaniel Vetter * Returns: 21552217195SDaniel Vetter * Zero on success, error code on failure. 21652217195SDaniel Vetter */ 21752217195SDaniel Vetter int drm_connector_init(struct drm_device *dev, 21852217195SDaniel Vetter struct drm_connector *connector, 21952217195SDaniel Vetter const struct drm_connector_funcs *funcs, 22052217195SDaniel Vetter int connector_type) 22152217195SDaniel Vetter { 22252217195SDaniel Vetter struct drm_mode_config *config = &dev->mode_config; 22352217195SDaniel Vetter int ret; 22452217195SDaniel Vetter struct ida *connector_ida = 22552217195SDaniel Vetter &drm_connector_enum_list[connector_type].ida; 22652217195SDaniel Vetter 227ba1f665fSHaneen Mohammed WARN_ON(drm_drv_uses_atomic_modeset(dev) && 228ba1f665fSHaneen Mohammed (!funcs->atomic_destroy_state || 229ba1f665fSHaneen Mohammed !funcs->atomic_duplicate_state)); 230ba1f665fSHaneen Mohammed 2312135ea7aSThierry Reding ret = __drm_mode_object_add(dev, &connector->base, 23252217195SDaniel Vetter DRM_MODE_OBJECT_CONNECTOR, 23352217195SDaniel Vetter false, drm_connector_free); 23452217195SDaniel Vetter if (ret) 235613051daSDaniel Vetter return ret; 23652217195SDaniel Vetter 23752217195SDaniel Vetter connector->base.properties = &connector->properties; 23852217195SDaniel Vetter connector->dev = dev; 23952217195SDaniel Vetter connector->funcs = funcs; 24052217195SDaniel Vetter 2412a8d3eacSVille Syrjälä /* connector index is used with 32bit bitmasks */ 2422a8d3eacSVille Syrjälä ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL); 2432a8d3eacSVille Syrjälä if (ret < 0) { 2442a8d3eacSVille Syrjälä DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n", 2452a8d3eacSVille Syrjälä drm_connector_enum_list[connector_type].name, 2462a8d3eacSVille Syrjälä ret); 24752217195SDaniel Vetter goto out_put; 2482a8d3eacSVille Syrjälä } 24952217195SDaniel Vetter connector->index = ret; 25052217195SDaniel Vetter ret = 0; 25152217195SDaniel Vetter 25252217195SDaniel Vetter connector->connector_type = connector_type; 25352217195SDaniel Vetter connector->connector_type_id = 25452217195SDaniel Vetter ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); 25552217195SDaniel Vetter if (connector->connector_type_id < 0) { 25652217195SDaniel Vetter ret = connector->connector_type_id; 25752217195SDaniel Vetter goto out_put_id; 25852217195SDaniel Vetter } 25952217195SDaniel Vetter connector->name = 26052217195SDaniel Vetter kasprintf(GFP_KERNEL, "%s-%d", 26152217195SDaniel Vetter drm_connector_enum_list[connector_type].name, 26252217195SDaniel Vetter connector->connector_type_id); 26352217195SDaniel Vetter if (!connector->name) { 26452217195SDaniel Vetter ret = -ENOMEM; 26552217195SDaniel Vetter goto out_put_type_id; 26652217195SDaniel Vetter } 26752217195SDaniel Vetter 26852217195SDaniel Vetter INIT_LIST_HEAD(&connector->probed_modes); 26952217195SDaniel Vetter INIT_LIST_HEAD(&connector->modes); 270e73ab00eSDaniel Vetter mutex_init(&connector->mutex); 27152217195SDaniel Vetter connector->edid_blob_ptr = NULL; 2725186421cSStanislav Lisovskiy connector->epoch_counter = 0; 2732de3a078SManasi Navare connector->tile_blob_ptr = NULL; 27452217195SDaniel Vetter connector->status = connector_status_unknown; 2758d70f395SHans de Goede connector->display_info.panel_orientation = 2768d70f395SHans de Goede DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 27752217195SDaniel Vetter 27852217195SDaniel Vetter drm_connector_get_cmdline_mode(connector); 27952217195SDaniel Vetter 28052217195SDaniel Vetter /* We should add connectors at the end to avoid upsetting the connector 28152217195SDaniel Vetter * index too much. */ 282613051daSDaniel Vetter spin_lock_irq(&config->connector_list_lock); 28352217195SDaniel Vetter list_add_tail(&connector->head, &config->connector_list); 28452217195SDaniel Vetter config->num_connector++; 285613051daSDaniel Vetter spin_unlock_irq(&config->connector_list_lock); 28652217195SDaniel Vetter 287935774cdSBrian Starkey if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL && 288935774cdSBrian Starkey connector_type != DRM_MODE_CONNECTOR_WRITEBACK) 2896b7e2d5cSGerd Hoffmann drm_connector_attach_edid_property(connector); 29052217195SDaniel Vetter 29152217195SDaniel Vetter drm_object_attach_property(&connector->base, 29252217195SDaniel Vetter config->dpms_property, 0); 29352217195SDaniel Vetter 29440ee6fbeSManasi Navare drm_object_attach_property(&connector->base, 29540ee6fbeSManasi Navare config->link_status_property, 29640ee6fbeSManasi Navare 0); 29740ee6fbeSManasi Navare 29866660d4cSDave Airlie drm_object_attach_property(&connector->base, 29966660d4cSDave Airlie config->non_desktop_property, 30066660d4cSDave Airlie 0); 3012de3a078SManasi Navare drm_object_attach_property(&connector->base, 3022de3a078SManasi Navare config->tile_property, 3032de3a078SManasi Navare 0); 30466660d4cSDave Airlie 30552217195SDaniel Vetter if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 30652217195SDaniel Vetter drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); 30752217195SDaniel Vetter } 30852217195SDaniel Vetter 30952217195SDaniel Vetter connector->debugfs_entry = NULL; 31052217195SDaniel Vetter out_put_type_id: 31152217195SDaniel Vetter if (ret) 312587680c1SChristophe JAILLET ida_simple_remove(connector_ida, connector->connector_type_id); 31352217195SDaniel Vetter out_put_id: 31452217195SDaniel Vetter if (ret) 315587680c1SChristophe JAILLET ida_simple_remove(&config->connector_ida, connector->index); 31652217195SDaniel Vetter out_put: 31752217195SDaniel Vetter if (ret) 31852217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 31952217195SDaniel Vetter 32052217195SDaniel Vetter return ret; 32152217195SDaniel Vetter } 32252217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init); 32352217195SDaniel Vetter 32452217195SDaniel Vetter /** 325100163dfSAndrzej Pietrasiewicz * drm_connector_init_with_ddc - Init a preallocated connector 326100163dfSAndrzej Pietrasiewicz * @dev: DRM device 327100163dfSAndrzej Pietrasiewicz * @connector: the connector to init 328100163dfSAndrzej Pietrasiewicz * @funcs: callbacks for this connector 329100163dfSAndrzej Pietrasiewicz * @connector_type: user visible type of the connector 330100163dfSAndrzej Pietrasiewicz * @ddc: pointer to the associated ddc adapter 331100163dfSAndrzej Pietrasiewicz * 332100163dfSAndrzej Pietrasiewicz * Initialises a preallocated connector. Connectors should be 333100163dfSAndrzej Pietrasiewicz * subclassed as part of driver connector objects. 334100163dfSAndrzej Pietrasiewicz * 335100163dfSAndrzej Pietrasiewicz * Ensures that the ddc field of the connector is correctly set. 336100163dfSAndrzej Pietrasiewicz * 337100163dfSAndrzej Pietrasiewicz * Returns: 338100163dfSAndrzej Pietrasiewicz * Zero on success, error code on failure. 339100163dfSAndrzej Pietrasiewicz */ 340100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev, 341100163dfSAndrzej Pietrasiewicz struct drm_connector *connector, 342100163dfSAndrzej Pietrasiewicz const struct drm_connector_funcs *funcs, 343100163dfSAndrzej Pietrasiewicz int connector_type, 344100163dfSAndrzej Pietrasiewicz struct i2c_adapter *ddc) 345100163dfSAndrzej Pietrasiewicz { 346100163dfSAndrzej Pietrasiewicz int ret; 347100163dfSAndrzej Pietrasiewicz 348100163dfSAndrzej Pietrasiewicz ret = drm_connector_init(dev, connector, funcs, connector_type); 349100163dfSAndrzej Pietrasiewicz if (ret) 350100163dfSAndrzej Pietrasiewicz return ret; 351100163dfSAndrzej Pietrasiewicz 352100163dfSAndrzej Pietrasiewicz /* provide ddc symlink in sysfs */ 353100163dfSAndrzej Pietrasiewicz connector->ddc = ddc; 354100163dfSAndrzej Pietrasiewicz 355100163dfSAndrzej Pietrasiewicz return ret; 356100163dfSAndrzej Pietrasiewicz } 357100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc); 358100163dfSAndrzej Pietrasiewicz 359100163dfSAndrzej Pietrasiewicz /** 3606b7e2d5cSGerd Hoffmann * drm_connector_attach_edid_property - attach edid property. 3616b7e2d5cSGerd Hoffmann * @connector: the connector 3626b7e2d5cSGerd Hoffmann * 3636b7e2d5cSGerd Hoffmann * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a 3646b7e2d5cSGerd Hoffmann * edid property attached by default. This function can be used to 3656b7e2d5cSGerd Hoffmann * explicitly enable the edid property in these cases. 3666b7e2d5cSGerd Hoffmann */ 3676b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector) 3686b7e2d5cSGerd Hoffmann { 3696b7e2d5cSGerd Hoffmann struct drm_mode_config *config = &connector->dev->mode_config; 3706b7e2d5cSGerd Hoffmann 3716b7e2d5cSGerd Hoffmann drm_object_attach_property(&connector->base, 3726b7e2d5cSGerd Hoffmann config->edid_property, 3736b7e2d5cSGerd Hoffmann 0); 3746b7e2d5cSGerd Hoffmann } 3756b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property); 3766b7e2d5cSGerd Hoffmann 3776b7e2d5cSGerd Hoffmann /** 378cde4c44dSDaniel Vetter * drm_connector_attach_encoder - attach a connector to an encoder 37952217195SDaniel Vetter * @connector: connector to attach 38052217195SDaniel Vetter * @encoder: encoder to attach @connector to 38152217195SDaniel Vetter * 38252217195SDaniel Vetter * This function links up a connector to an encoder. Note that the routing 38352217195SDaniel Vetter * restrictions between encoders and crtcs are exposed to userspace through the 38452217195SDaniel Vetter * possible_clones and possible_crtcs bitmasks. 38552217195SDaniel Vetter * 38652217195SDaniel Vetter * Returns: 38752217195SDaniel Vetter * Zero on success, negative errno on failure. 38852217195SDaniel Vetter */ 389cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector, 39052217195SDaniel Vetter struct drm_encoder *encoder) 39152217195SDaniel Vetter { 39252217195SDaniel Vetter /* 39352217195SDaniel Vetter * In the past, drivers have attempted to model the static association 39452217195SDaniel Vetter * of connector to encoder in simple connector/encoder devices using a 39552217195SDaniel Vetter * direct assignment of connector->encoder = encoder. This connection 39652217195SDaniel Vetter * is a logical one and the responsibility of the core, so drivers are 39752217195SDaniel Vetter * expected not to mess with this. 39852217195SDaniel Vetter * 39952217195SDaniel Vetter * Note that the error return should've been enough here, but a large 40052217195SDaniel Vetter * majority of drivers ignores the return value, so add in a big WARN 40152217195SDaniel Vetter * to get people's attention. 40252217195SDaniel Vetter */ 40352217195SDaniel Vetter if (WARN_ON(connector->encoder)) 40452217195SDaniel Vetter return -EINVAL; 40552217195SDaniel Vetter 40662afb4adSJosé Roberto de Souza connector->possible_encoders |= drm_encoder_mask(encoder); 40762afb4adSJosé Roberto de Souza 40852217195SDaniel Vetter return 0; 40952217195SDaniel Vetter } 410cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder); 41152217195SDaniel Vetter 41238cb8d96SVille Syrjälä /** 41362afb4adSJosé Roberto de Souza * drm_connector_has_possible_encoder - check if the connector and encoder are 41462afb4adSJosé Roberto de Souza * associated with each other 41538cb8d96SVille Syrjälä * @connector: the connector 41638cb8d96SVille Syrjälä * @encoder: the encoder 41738cb8d96SVille Syrjälä * 41838cb8d96SVille Syrjälä * Returns: 41938cb8d96SVille Syrjälä * True if @encoder is one of the possible encoders for @connector. 42038cb8d96SVille Syrjälä */ 42138cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector, 42238cb8d96SVille Syrjälä struct drm_encoder *encoder) 42338cb8d96SVille Syrjälä { 42462afb4adSJosé Roberto de Souza return connector->possible_encoders & drm_encoder_mask(encoder); 42538cb8d96SVille Syrjälä } 42638cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder); 42738cb8d96SVille Syrjälä 42852217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector, 42952217195SDaniel Vetter struct drm_display_mode *mode) 43052217195SDaniel Vetter { 43152217195SDaniel Vetter list_del(&mode->head); 43252217195SDaniel Vetter drm_mode_destroy(connector->dev, mode); 43352217195SDaniel Vetter } 43452217195SDaniel Vetter 43552217195SDaniel Vetter /** 43652217195SDaniel Vetter * drm_connector_cleanup - cleans up an initialised connector 43752217195SDaniel Vetter * @connector: connector to cleanup 43852217195SDaniel Vetter * 43952217195SDaniel Vetter * Cleans up the connector but doesn't free the object. 44052217195SDaniel Vetter */ 44152217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector) 44252217195SDaniel Vetter { 44352217195SDaniel Vetter struct drm_device *dev = connector->dev; 44452217195SDaniel Vetter struct drm_display_mode *mode, *t; 44552217195SDaniel Vetter 44652217195SDaniel Vetter /* The connector should have been removed from userspace long before 44752217195SDaniel Vetter * it is finally destroyed. 44852217195SDaniel Vetter */ 44939b50c60SLyude Paul if (WARN_ON(connector->registration_state == 45039b50c60SLyude Paul DRM_CONNECTOR_REGISTERED)) 45152217195SDaniel Vetter drm_connector_unregister(connector); 45252217195SDaniel Vetter 45352217195SDaniel Vetter if (connector->tile_group) { 45452217195SDaniel Vetter drm_mode_put_tile_group(dev, connector->tile_group); 45552217195SDaniel Vetter connector->tile_group = NULL; 45652217195SDaniel Vetter } 45752217195SDaniel Vetter 45852217195SDaniel Vetter list_for_each_entry_safe(mode, t, &connector->probed_modes, head) 45952217195SDaniel Vetter drm_mode_remove(connector, mode); 46052217195SDaniel Vetter 46152217195SDaniel Vetter list_for_each_entry_safe(mode, t, &connector->modes, head) 46252217195SDaniel Vetter drm_mode_remove(connector, mode); 46352217195SDaniel Vetter 4649a47dba1SChristophe JAILLET ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida, 46552217195SDaniel Vetter connector->connector_type_id); 46652217195SDaniel Vetter 4679a47dba1SChristophe JAILLET ida_simple_remove(&dev->mode_config.connector_ida, 46852217195SDaniel Vetter connector->index); 46952217195SDaniel Vetter 47052217195SDaniel Vetter kfree(connector->display_info.bus_formats); 47152217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 47252217195SDaniel Vetter kfree(connector->name); 47352217195SDaniel Vetter connector->name = NULL; 474613051daSDaniel Vetter spin_lock_irq(&dev->mode_config.connector_list_lock); 47552217195SDaniel Vetter list_del(&connector->head); 47652217195SDaniel Vetter dev->mode_config.num_connector--; 477613051daSDaniel Vetter spin_unlock_irq(&dev->mode_config.connector_list_lock); 47852217195SDaniel Vetter 47952217195SDaniel Vetter WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); 48052217195SDaniel Vetter if (connector->state && connector->funcs->atomic_destroy_state) 48152217195SDaniel Vetter connector->funcs->atomic_destroy_state(connector, 48252217195SDaniel Vetter connector->state); 48352217195SDaniel Vetter 484e73ab00eSDaniel Vetter mutex_destroy(&connector->mutex); 485e73ab00eSDaniel Vetter 48652217195SDaniel Vetter memset(connector, 0, sizeof(*connector)); 48752217195SDaniel Vetter } 48852217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup); 48952217195SDaniel Vetter 49052217195SDaniel Vetter /** 49152217195SDaniel Vetter * drm_connector_register - register a connector 49252217195SDaniel Vetter * @connector: the connector to register 49352217195SDaniel Vetter * 49469b22f51SDaniel Vetter * Register userspace interfaces for a connector. Only call this for connectors 49569b22f51SDaniel Vetter * which can be hotplugged after drm_dev_register() has been called already, 49669b22f51SDaniel Vetter * e.g. DP MST connectors. All other connectors will be registered automatically 49769b22f51SDaniel Vetter * when calling drm_dev_register(). 49852217195SDaniel Vetter * 49952217195SDaniel Vetter * Returns: 50052217195SDaniel Vetter * Zero on success, error code on failure. 50152217195SDaniel Vetter */ 50252217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector) 50352217195SDaniel Vetter { 504e73ab00eSDaniel Vetter int ret = 0; 50552217195SDaniel Vetter 506e6e7b48bSDaniel Vetter if (!connector->dev->registered) 507e6e7b48bSDaniel Vetter return 0; 508e6e7b48bSDaniel Vetter 509e73ab00eSDaniel Vetter mutex_lock(&connector->mutex); 51039b50c60SLyude Paul if (connector->registration_state != DRM_CONNECTOR_INITIALIZING) 511e73ab00eSDaniel Vetter goto unlock; 51252217195SDaniel Vetter 51352217195SDaniel Vetter ret = drm_sysfs_connector_add(connector); 51452217195SDaniel Vetter if (ret) 515e73ab00eSDaniel Vetter goto unlock; 51652217195SDaniel Vetter 517b792e640SGreg Kroah-Hartman drm_debugfs_connector_add(connector); 51852217195SDaniel Vetter 51952217195SDaniel Vetter if (connector->funcs->late_register) { 52052217195SDaniel Vetter ret = connector->funcs->late_register(connector); 52152217195SDaniel Vetter if (ret) 52252217195SDaniel Vetter goto err_debugfs; 52352217195SDaniel Vetter } 52452217195SDaniel Vetter 52552217195SDaniel Vetter drm_mode_object_register(connector->dev, &connector->base); 52652217195SDaniel Vetter 52739b50c60SLyude Paul connector->registration_state = DRM_CONNECTOR_REGISTERED; 528968d81a6SJeykumar Sankaran 529968d81a6SJeykumar Sankaran /* Let userspace know we have a new connector */ 530968d81a6SJeykumar Sankaran drm_sysfs_hotplug_event(connector->dev); 531968d81a6SJeykumar Sankaran 532e73ab00eSDaniel Vetter goto unlock; 53352217195SDaniel Vetter 53452217195SDaniel Vetter err_debugfs: 53552217195SDaniel Vetter drm_debugfs_connector_remove(connector); 53652217195SDaniel Vetter drm_sysfs_connector_remove(connector); 537e73ab00eSDaniel Vetter unlock: 538e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 53952217195SDaniel Vetter return ret; 54052217195SDaniel Vetter } 54152217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register); 54252217195SDaniel Vetter 54352217195SDaniel Vetter /** 54452217195SDaniel Vetter * drm_connector_unregister - unregister a connector 54552217195SDaniel Vetter * @connector: the connector to unregister 54652217195SDaniel Vetter * 54769b22f51SDaniel Vetter * Unregister userspace interfaces for a connector. Only call this for 54869b22f51SDaniel Vetter * connectors which have registered explicitly by calling drm_dev_register(), 54969b22f51SDaniel Vetter * since connectors are unregistered automatically when drm_dev_unregister() is 55069b22f51SDaniel Vetter * called. 55152217195SDaniel Vetter */ 55252217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector) 55352217195SDaniel Vetter { 554e73ab00eSDaniel Vetter mutex_lock(&connector->mutex); 55539b50c60SLyude Paul if (connector->registration_state != DRM_CONNECTOR_REGISTERED) { 556e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 55752217195SDaniel Vetter return; 558e73ab00eSDaniel Vetter } 55952217195SDaniel Vetter 56052217195SDaniel Vetter if (connector->funcs->early_unregister) 56152217195SDaniel Vetter connector->funcs->early_unregister(connector); 56252217195SDaniel Vetter 56352217195SDaniel Vetter drm_sysfs_connector_remove(connector); 56452217195SDaniel Vetter drm_debugfs_connector_remove(connector); 56552217195SDaniel Vetter 56639b50c60SLyude Paul connector->registration_state = DRM_CONNECTOR_UNREGISTERED; 567e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 56852217195SDaniel Vetter } 56952217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister); 57052217195SDaniel Vetter 57152217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev) 57252217195SDaniel Vetter { 57352217195SDaniel Vetter struct drm_connector *connector; 574613051daSDaniel Vetter struct drm_connector_list_iter conn_iter; 57552217195SDaniel Vetter 576b982dab1SThierry Reding drm_connector_list_iter_begin(dev, &conn_iter); 577613051daSDaniel Vetter drm_for_each_connector_iter(connector, &conn_iter) 57852217195SDaniel Vetter drm_connector_unregister(connector); 579b982dab1SThierry Reding drm_connector_list_iter_end(&conn_iter); 58052217195SDaniel Vetter } 58152217195SDaniel Vetter 58252217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev) 58352217195SDaniel Vetter { 58452217195SDaniel Vetter struct drm_connector *connector; 585613051daSDaniel Vetter struct drm_connector_list_iter conn_iter; 586613051daSDaniel Vetter int ret = 0; 58752217195SDaniel Vetter 588b982dab1SThierry Reding drm_connector_list_iter_begin(dev, &conn_iter); 589613051daSDaniel Vetter drm_for_each_connector_iter(connector, &conn_iter) { 59052217195SDaniel Vetter ret = drm_connector_register(connector); 59152217195SDaniel Vetter if (ret) 592613051daSDaniel Vetter break; 59352217195SDaniel Vetter } 594b982dab1SThierry Reding drm_connector_list_iter_end(&conn_iter); 59552217195SDaniel Vetter 596613051daSDaniel Vetter if (ret) 59752217195SDaniel Vetter drm_connector_unregister_all(dev); 59852217195SDaniel Vetter return ret; 59952217195SDaniel Vetter } 60052217195SDaniel Vetter 60152217195SDaniel Vetter /** 60252217195SDaniel Vetter * drm_get_connector_status_name - return a string for connector status 60352217195SDaniel Vetter * @status: connector status to compute name of 60452217195SDaniel Vetter * 60552217195SDaniel Vetter * In contrast to the other drm_get_*_name functions this one here returns a 60652217195SDaniel Vetter * const pointer and hence is threadsafe. 60752217195SDaniel Vetter */ 60852217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status) 60952217195SDaniel Vetter { 61052217195SDaniel Vetter if (status == connector_status_connected) 61152217195SDaniel Vetter return "connected"; 61252217195SDaniel Vetter else if (status == connector_status_disconnected) 61352217195SDaniel Vetter return "disconnected"; 61452217195SDaniel Vetter else 61552217195SDaniel Vetter return "unknown"; 61652217195SDaniel Vetter } 61752217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name); 61852217195SDaniel Vetter 6196140cf20SJani Nikula /** 6206140cf20SJani Nikula * drm_get_connector_force_name - return a string for connector force 6216140cf20SJani Nikula * @force: connector force to get name of 6226140cf20SJani Nikula * 6236140cf20SJani Nikula * Returns: const pointer to name. 6246140cf20SJani Nikula */ 6256140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force) 6266140cf20SJani Nikula { 6276140cf20SJani Nikula switch (force) { 6286140cf20SJani Nikula case DRM_FORCE_UNSPECIFIED: 6296140cf20SJani Nikula return "unspecified"; 6306140cf20SJani Nikula case DRM_FORCE_OFF: 6316140cf20SJani Nikula return "off"; 6326140cf20SJani Nikula case DRM_FORCE_ON: 6336140cf20SJani Nikula return "on"; 6346140cf20SJani Nikula case DRM_FORCE_ON_DIGITAL: 6356140cf20SJani Nikula return "digital"; 6366140cf20SJani Nikula default: 6376140cf20SJani Nikula return "unknown"; 6386140cf20SJani Nikula } 6396140cf20SJani Nikula } 6406140cf20SJani Nikula 641613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP 642613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = { 643613051daSDaniel Vetter .name = "drm_connector_list_iter" 644613051daSDaniel Vetter }; 645613051daSDaniel Vetter #endif 646613051daSDaniel Vetter 647613051daSDaniel Vetter /** 648b982dab1SThierry Reding * drm_connector_list_iter_begin - initialize a connector_list iterator 649613051daSDaniel Vetter * @dev: DRM device 650613051daSDaniel Vetter * @iter: connector_list iterator 651613051daSDaniel Vetter * 652d574528aSDaniel Vetter * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter 653b982dab1SThierry Reding * must always be cleaned up again by calling drm_connector_list_iter_end(). 654613051daSDaniel Vetter * Iteration itself happens using drm_connector_list_iter_next() or 655613051daSDaniel Vetter * drm_for_each_connector_iter(). 656613051daSDaniel Vetter */ 657b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev, 658613051daSDaniel Vetter struct drm_connector_list_iter *iter) 659613051daSDaniel Vetter { 660613051daSDaniel Vetter iter->dev = dev; 661613051daSDaniel Vetter iter->conn = NULL; 662613051daSDaniel Vetter lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_); 663613051daSDaniel Vetter } 664b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin); 665613051daSDaniel Vetter 666a703c550SDaniel Vetter /* 667a703c550SDaniel Vetter * Extra-safe connector put function that works in any context. Should only be 668a703c550SDaniel Vetter * used from the connector_iter functions, where we never really expect to 669a703c550SDaniel Vetter * actually release the connector when dropping our final reference. 670a703c550SDaniel Vetter */ 671a703c550SDaniel Vetter static void 672ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn) 673a703c550SDaniel Vetter { 674ea497bb9SDaniel Vetter struct drm_mode_config *config = &conn->dev->mode_config; 675ea497bb9SDaniel Vetter 676ea497bb9SDaniel Vetter lockdep_assert_held(&config->connector_list_lock); 677ea497bb9SDaniel Vetter 678ea497bb9SDaniel Vetter if (!refcount_dec_and_test(&conn->base.refcount.refcount)) 679ea497bb9SDaniel Vetter return; 680ea497bb9SDaniel Vetter 681ea497bb9SDaniel Vetter llist_add(&conn->free_node, &config->connector_free_list); 682ea497bb9SDaniel Vetter schedule_work(&config->connector_free_work); 683a703c550SDaniel Vetter } 684a703c550SDaniel Vetter 685613051daSDaniel Vetter /** 686613051daSDaniel Vetter * drm_connector_list_iter_next - return next connector 6874f45c778SLyude Paul * @iter: connector_list iterator 688613051daSDaniel Vetter * 689613051daSDaniel Vetter * Returns the next connector for @iter, or NULL when the list walk has 690613051daSDaniel Vetter * completed. 691613051daSDaniel Vetter */ 692613051daSDaniel Vetter struct drm_connector * 693613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter) 694613051daSDaniel Vetter { 695613051daSDaniel Vetter struct drm_connector *old_conn = iter->conn; 696613051daSDaniel Vetter struct drm_mode_config *config = &iter->dev->mode_config; 697613051daSDaniel Vetter struct list_head *lhead; 698613051daSDaniel Vetter unsigned long flags; 699613051daSDaniel Vetter 700613051daSDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 701613051daSDaniel Vetter lhead = old_conn ? &old_conn->head : &config->connector_list; 702613051daSDaniel Vetter 703613051daSDaniel Vetter do { 704613051daSDaniel Vetter if (lhead->next == &config->connector_list) { 705613051daSDaniel Vetter iter->conn = NULL; 706613051daSDaniel Vetter break; 707613051daSDaniel Vetter } 708613051daSDaniel Vetter 709613051daSDaniel Vetter lhead = lhead->next; 710613051daSDaniel Vetter iter->conn = list_entry(lhead, struct drm_connector, head); 711613051daSDaniel Vetter 712613051daSDaniel Vetter /* loop until it's not a zombie connector */ 713613051daSDaniel Vetter } while (!kref_get_unless_zero(&iter->conn->base.refcount)); 714613051daSDaniel Vetter 715613051daSDaniel Vetter if (old_conn) 716ea497bb9SDaniel Vetter __drm_connector_put_safe(old_conn); 717ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 718613051daSDaniel Vetter 719613051daSDaniel Vetter return iter->conn; 720613051daSDaniel Vetter } 721613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next); 722613051daSDaniel Vetter 723613051daSDaniel Vetter /** 724b982dab1SThierry Reding * drm_connector_list_iter_end - tear down a connector_list iterator 725613051daSDaniel Vetter * @iter: connector_list iterator 726613051daSDaniel Vetter * 727613051daSDaniel Vetter * Tears down @iter and releases any resources (like &drm_connector references) 728613051daSDaniel Vetter * acquired while walking the list. This must always be called, both when the 729613051daSDaniel Vetter * iteration completes fully or when it was aborted without walking the entire 730613051daSDaniel Vetter * list. 731613051daSDaniel Vetter */ 732b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter) 733613051daSDaniel Vetter { 734ea497bb9SDaniel Vetter struct drm_mode_config *config = &iter->dev->mode_config; 735ea497bb9SDaniel Vetter unsigned long flags; 736ea497bb9SDaniel Vetter 737613051daSDaniel Vetter iter->dev = NULL; 738ea497bb9SDaniel Vetter if (iter->conn) { 739ea497bb9SDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 740ea497bb9SDaniel Vetter __drm_connector_put_safe(iter->conn); 741ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 742ea497bb9SDaniel Vetter } 7435facae4fSQian Cai lock_release(&connector_list_iter_dep_map, _RET_IP_); 744613051daSDaniel Vetter } 745b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end); 746613051daSDaniel Vetter 74752217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { 74852217195SDaniel Vetter { SubPixelUnknown, "Unknown" }, 74952217195SDaniel Vetter { SubPixelHorizontalRGB, "Horizontal RGB" }, 75052217195SDaniel Vetter { SubPixelHorizontalBGR, "Horizontal BGR" }, 75152217195SDaniel Vetter { SubPixelVerticalRGB, "Vertical RGB" }, 75252217195SDaniel Vetter { SubPixelVerticalBGR, "Vertical BGR" }, 75352217195SDaniel Vetter { SubPixelNone, "None" }, 75452217195SDaniel Vetter }; 75552217195SDaniel Vetter 75652217195SDaniel Vetter /** 75752217195SDaniel Vetter * drm_get_subpixel_order_name - return a string for a given subpixel enum 75852217195SDaniel Vetter * @order: enum of subpixel_order 75952217195SDaniel Vetter * 76052217195SDaniel Vetter * Note you could abuse this and return something out of bounds, but that 76152217195SDaniel Vetter * would be a caller error. No unscrubbed user data should make it here. 76252217195SDaniel Vetter */ 76352217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order) 76452217195SDaniel Vetter { 76552217195SDaniel Vetter return drm_subpixel_enum_list[order].name; 76652217195SDaniel Vetter } 76752217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name); 76852217195SDaniel Vetter 76952217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = { 77052217195SDaniel Vetter { DRM_MODE_DPMS_ON, "On" }, 77152217195SDaniel Vetter { DRM_MODE_DPMS_STANDBY, "Standby" }, 77252217195SDaniel Vetter { DRM_MODE_DPMS_SUSPEND, "Suspend" }, 77352217195SDaniel Vetter { DRM_MODE_DPMS_OFF, "Off" } 77452217195SDaniel Vetter }; 77552217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) 77652217195SDaniel Vetter 77740ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = { 77840ee6fbeSManasi Navare { DRM_MODE_LINK_STATUS_GOOD, "Good" }, 77940ee6fbeSManasi Navare { DRM_MODE_LINK_STATUS_BAD, "Bad" }, 78040ee6fbeSManasi Navare }; 78140ee6fbeSManasi Navare 782b3c6c8bfSDaniel Vetter /** 783b3c6c8bfSDaniel Vetter * drm_display_info_set_bus_formats - set the supported bus formats 784b3c6c8bfSDaniel Vetter * @info: display info to store bus formats in 785b3c6c8bfSDaniel Vetter * @formats: array containing the supported bus formats 786b3c6c8bfSDaniel Vetter * @num_formats: the number of entries in the fmts array 787b3c6c8bfSDaniel Vetter * 788b3c6c8bfSDaniel Vetter * Store the supported bus formats in display info structure. 789b3c6c8bfSDaniel Vetter * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for 790b3c6c8bfSDaniel Vetter * a full list of available formats. 791b3c6c8bfSDaniel Vetter */ 792b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info, 793b3c6c8bfSDaniel Vetter const u32 *formats, 794b3c6c8bfSDaniel Vetter unsigned int num_formats) 795b3c6c8bfSDaniel Vetter { 796b3c6c8bfSDaniel Vetter u32 *fmts = NULL; 797b3c6c8bfSDaniel Vetter 798b3c6c8bfSDaniel Vetter if (!formats && num_formats) 799b3c6c8bfSDaniel Vetter return -EINVAL; 800b3c6c8bfSDaniel Vetter 801b3c6c8bfSDaniel Vetter if (formats && num_formats) { 802b3c6c8bfSDaniel Vetter fmts = kmemdup(formats, sizeof(*formats) * num_formats, 803b3c6c8bfSDaniel Vetter GFP_KERNEL); 804b3c6c8bfSDaniel Vetter if (!fmts) 805b3c6c8bfSDaniel Vetter return -ENOMEM; 806b3c6c8bfSDaniel Vetter } 807b3c6c8bfSDaniel Vetter 808b3c6c8bfSDaniel Vetter kfree(info->bus_formats); 809b3c6c8bfSDaniel Vetter info->bus_formats = fmts; 810b3c6c8bfSDaniel Vetter info->num_bus_formats = num_formats; 811b3c6c8bfSDaniel Vetter 812b3c6c8bfSDaniel Vetter return 0; 813b3c6c8bfSDaniel Vetter } 814b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats); 815b3c6c8bfSDaniel Vetter 81652217195SDaniel Vetter /* Optional connector properties. */ 81752217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { 81852217195SDaniel Vetter { DRM_MODE_SCALE_NONE, "None" }, 81952217195SDaniel Vetter { DRM_MODE_SCALE_FULLSCREEN, "Full" }, 82052217195SDaniel Vetter { DRM_MODE_SCALE_CENTER, "Center" }, 82152217195SDaniel Vetter { DRM_MODE_SCALE_ASPECT, "Full aspect" }, 82252217195SDaniel Vetter }; 82352217195SDaniel Vetter 82452217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { 82552217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, 82652217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, 82752217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, 82852217195SDaniel Vetter }; 82952217195SDaniel Vetter 83050525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = { 83150525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" }, 83250525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" }, 83350525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" }, 83450525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" }, 83550525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_GAME, "Game" }, 83650525c33SStanislav Lisovskiy }; 83750525c33SStanislav Lisovskiy 8388d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = { 8398d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" }, 8408d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" }, 8418d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" }, 8428d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" }, 8438d70f395SHans de Goede }; 8448d70f395SHans de Goede 84552217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { 84652217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 84752217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 84852217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 84952217195SDaniel Vetter }; 85052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) 85152217195SDaniel Vetter 85252217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { 853*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 85452217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 85552217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 85652217195SDaniel Vetter }; 85752217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, 85852217195SDaniel Vetter drm_dvi_i_subconnector_enum_list) 85952217195SDaniel Vetter 86052217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { 86152217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 86252217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 86352217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 86452217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 86552217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 86652217195SDaniel Vetter }; 86752217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) 86852217195SDaniel Vetter 86952217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { 870*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 87152217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 87252217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 87352217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 87452217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 87552217195SDaniel Vetter }; 87652217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, 87752217195SDaniel Vetter drm_tv_subconnector_enum_list) 87852217195SDaniel Vetter 879*e5b92773SOleg Vasilev static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = { 880*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 881*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */ 882*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */ 883*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */ 884*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */ 885*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */ 886*e5b92773SOleg Vasilev { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */ 887*e5b92773SOleg Vasilev }; 888*e5b92773SOleg Vasilev 889*e5b92773SOleg Vasilev DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name, 890*e5b92773SOleg Vasilev drm_dp_subconnector_enum_list) 891*e5b92773SOleg Vasilev 892d2c6a405SUma Shankar static const struct drm_prop_enum_list hdmi_colorspaces[] = { 893d2c6a405SUma Shankar /* For Default case, driver will set the colorspace */ 894d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_DEFAULT, "Default" }, 895d2c6a405SUma Shankar /* Standard Definition Colorimetry based on CEA 861 */ 896d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" }, 897d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" }, 898d2c6a405SUma Shankar /* Standard Definition Colorimetry based on IEC 61966-2-4 */ 899d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" }, 900d2c6a405SUma Shankar /* High Definition Colorimetry based on IEC 61966-2-4 */ 901d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" }, 902d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-1/Amendment 1 */ 903d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" }, 904d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-5 [33] */ 905d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" }, 906d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-5 */ 907d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" }, 908d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 909d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" }, 910d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 911d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" }, 912d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 913d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" }, 914d2c6a405SUma Shankar /* Added as part of Additional Colorimetry Extension in 861.G */ 915d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" }, 916d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" }, 917d2c6a405SUma Shankar }; 918d2c6a405SUma Shankar 91945cf0e91SGwan-gyeong Mun /* 92045cf0e91SGwan-gyeong Mun * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry 92145cf0e91SGwan-gyeong Mun * Format Table 2-120 92245cf0e91SGwan-gyeong Mun */ 92345cf0e91SGwan-gyeong Mun static const struct drm_prop_enum_list dp_colorspaces[] = { 92445cf0e91SGwan-gyeong Mun /* For Default case, driver will set the colorspace */ 92545cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_DEFAULT, "Default" }, 92645cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" }, 92745cf0e91SGwan-gyeong Mun /* Colorimetry based on scRGB (IEC 61966-2-2) */ 92845cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" }, 92945cf0e91SGwan-gyeong Mun /* Colorimetry based on IEC 61966-2-5 */ 93045cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" }, 93145cf0e91SGwan-gyeong Mun /* Colorimetry based on SMPTE RP 431-2 */ 93245cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" }, 93345cf0e91SGwan-gyeong Mun /* Colorimetry based on ITU-R BT.2020 */ 93445cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" }, 93545cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" }, 93645cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" }, 93745cf0e91SGwan-gyeong Mun /* Standard Definition Colorimetry based on IEC 61966-2-4 */ 93845cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" }, 93945cf0e91SGwan-gyeong Mun /* High Definition Colorimetry based on IEC 61966-2-4 */ 94045cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" }, 94145cf0e91SGwan-gyeong Mun /* Colorimetry based on IEC 61966-2-1/Amendment 1 */ 94245cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" }, 94345cf0e91SGwan-gyeong Mun /* Colorimetry based on IEC 61966-2-5 [33] */ 94445cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" }, 94545cf0e91SGwan-gyeong Mun /* Colorimetry based on ITU-R BT.2020 */ 94645cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" }, 94745cf0e91SGwan-gyeong Mun /* Colorimetry based on ITU-R BT.2020 */ 94845cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" }, 94945cf0e91SGwan-gyeong Mun }; 95045cf0e91SGwan-gyeong Mun 9514ada6f22SDaniel Vetter /** 9524ada6f22SDaniel Vetter * DOC: standard connector properties 9534ada6f22SDaniel Vetter * 9544ada6f22SDaniel Vetter * DRM connectors have a few standardized properties: 9554ada6f22SDaniel Vetter * 9564ada6f22SDaniel Vetter * EDID: 9574ada6f22SDaniel Vetter * Blob property which contains the current EDID read from the sink. This 9584ada6f22SDaniel Vetter * is useful to parse sink identification information like vendor, model 9594ada6f22SDaniel Vetter * and serial. Drivers should update this property by calling 960c555f023SDaniel Vetter * drm_connector_update_edid_property(), usually after having parsed 9614ada6f22SDaniel Vetter * the EDID using drm_add_edid_modes(). Userspace cannot change this 9624ada6f22SDaniel Vetter * property. 9634ada6f22SDaniel Vetter * DPMS: 9644ada6f22SDaniel Vetter * Legacy property for setting the power state of the connector. For atomic 9654ada6f22SDaniel Vetter * drivers this is only provided for backwards compatibility with existing 9664ada6f22SDaniel Vetter * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the 9674ada6f22SDaniel Vetter * connector is linked to. Drivers should never set this property directly, 968d574528aSDaniel Vetter * it is handled by the DRM core by calling the &drm_connector_funcs.dpms 969144a7999SDaniel Vetter * callback. For atomic drivers the remapping to the "ACTIVE" property is 9701e3e4caeSSimon Ser * implemented in the DRM core. 971d0d1aee5SDaniel Vetter * 972d0d1aee5SDaniel Vetter * Note that this property cannot be set through the MODE_ATOMIC ioctl, 973d0d1aee5SDaniel Vetter * userspace must use "ACTIVE" on the CRTC instead. 974d0d1aee5SDaniel Vetter * 975d0d1aee5SDaniel Vetter * WARNING: 976d0d1aee5SDaniel Vetter * 977d0d1aee5SDaniel Vetter * For userspace also running on legacy drivers the "DPMS" semantics are a 978d0d1aee5SDaniel Vetter * lot more complicated. First, userspace cannot rely on the "DPMS" value 979d0d1aee5SDaniel Vetter * returned by the GETCONNECTOR actually reflecting reality, because many 980d0d1aee5SDaniel Vetter * drivers fail to update it. For atomic drivers this is taken care of in 981d0d1aee5SDaniel Vetter * drm_atomic_helper_update_legacy_modeset_state(). 982d0d1aee5SDaniel Vetter * 983d0d1aee5SDaniel Vetter * The second issue is that the DPMS state is only well-defined when the 984d0d1aee5SDaniel Vetter * connector is connected to a CRTC. In atomic the DRM core enforces that 985d0d1aee5SDaniel Vetter * "ACTIVE" is off in such a case, no such checks exists for "DPMS". 986d0d1aee5SDaniel Vetter * 987d0d1aee5SDaniel Vetter * Finally, when enabling an output using the legacy SETCONFIG ioctl then 988d0d1aee5SDaniel Vetter * "DPMS" is forced to ON. But see above, that might not be reflected in 989d0d1aee5SDaniel Vetter * the software value on legacy drivers. 990d0d1aee5SDaniel Vetter * 991d0d1aee5SDaniel Vetter * Summarizing: Only set "DPMS" when the connector is known to be enabled, 992d0d1aee5SDaniel Vetter * assume that a successful SETCONFIG call also sets "DPMS" to on, and 993d0d1aee5SDaniel Vetter * never read back the value of "DPMS" because it can be incorrect. 9944ada6f22SDaniel Vetter * PATH: 9954ada6f22SDaniel Vetter * Connector path property to identify how this sink is physically 9964ada6f22SDaniel Vetter * connected. Used by DP MST. This should be set by calling 99797e14fbeSDaniel Vetter * drm_connector_set_path_property(), in the case of DP MST with the 9984ada6f22SDaniel Vetter * path property the MST manager created. Userspace cannot change this 9994ada6f22SDaniel Vetter * property. 10004ada6f22SDaniel Vetter * TILE: 10014ada6f22SDaniel Vetter * Connector tile group property to indicate how a set of DRM connector 10024ada6f22SDaniel Vetter * compose together into one logical screen. This is used by both high-res 10034ada6f22SDaniel Vetter * external screens (often only using a single cable, but exposing multiple 10044ada6f22SDaniel Vetter * DP MST sinks), or high-res integrated panels (like dual-link DSI) which 10054ada6f22SDaniel Vetter * are not gen-locked. Note that for tiled panels which are genlocked, like 10064ada6f22SDaniel Vetter * dual-link LVDS or dual-link DSI, the driver should try to not expose the 100784e543bcSAntonio Borneo * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers 100897e14fbeSDaniel Vetter * should update this value using drm_connector_set_tile_property(). 10094ada6f22SDaniel Vetter * Userspace cannot change this property. 101040ee6fbeSManasi Navare * link-status: 1011716719a3SSean Paul * Connector link-status property to indicate the status of link. The 1012716719a3SSean Paul * default value of link-status is "GOOD". If something fails during or 1013716719a3SSean Paul * after modeset, the kernel driver may set this to "BAD" and issue a 1014716719a3SSean Paul * hotplug uevent. Drivers should update this value using 101597e14fbeSDaniel Vetter * drm_connector_set_link_status_property(). 1016a66da873SSimon Ser * 1017a66da873SSimon Ser * When user-space receives the hotplug uevent and detects a "BAD" 1018a66da873SSimon Ser * link-status, the sink doesn't receive pixels anymore (e.g. the screen 1019a66da873SSimon Ser * becomes completely black). The list of available modes may have 1020a66da873SSimon Ser * changed. User-space is expected to pick a new mode if the current one 1021a66da873SSimon Ser * has disappeared and perform a new modeset with link-status set to 1022a66da873SSimon Ser * "GOOD" to re-enable the connector. 1023a66da873SSimon Ser * 1024a66da873SSimon Ser * If multiple connectors share the same CRTC and one of them gets a "BAD" 1025a66da873SSimon Ser * link-status, the other are unaffected (ie. the sinks still continue to 1026a66da873SSimon Ser * receive pixels). 1027a66da873SSimon Ser * 1028a66da873SSimon Ser * When user-space performs an atomic commit on a connector with a "BAD" 1029a66da873SSimon Ser * link-status without resetting the property to "GOOD", the sink may 1030a66da873SSimon Ser * still not receive pixels. When user-space performs an atomic commit 1031a66da873SSimon Ser * which resets the link-status property to "GOOD" without the 1032a66da873SSimon Ser * ALLOW_MODESET flag set, it might fail because a modeset is required. 1033a66da873SSimon Ser * 1034a66da873SSimon Ser * User-space can only change link-status to "GOOD", changing it to "BAD" 1035a66da873SSimon Ser * is a no-op. 1036a66da873SSimon Ser * 1037a66da873SSimon Ser * For backwards compatibility with non-atomic userspace the kernel 1038a66da873SSimon Ser * tries to automatically set the link-status back to "GOOD" in the 1039a66da873SSimon Ser * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar 1040a66da873SSimon Ser * to how it might fail if a different screen has been connected in the 1041a66da873SSimon Ser * interim. 104266660d4cSDave Airlie * non_desktop: 104366660d4cSDave Airlie * Indicates the output should be ignored for purposes of displaying a 104466660d4cSDave Airlie * standard desktop environment or console. This is most likely because 104566660d4cSDave Airlie * the output device is not rectilinear. 104624557865SSean Paul * Content Protection: 104724557865SSean Paul * This property is used by userspace to request the kernel protect future 104824557865SSean Paul * content communicated over the link. When requested, kernel will apply 104924557865SSean Paul * the appropriate means of protection (most often HDCP), and use the 105024557865SSean Paul * property to tell userspace the protection is active. 105124557865SSean Paul * 105224557865SSean Paul * Drivers can set this up by calling 105324557865SSean Paul * drm_connector_attach_content_protection_property() on initialization. 105424557865SSean Paul * 105524557865SSean Paul * The value of this property can be one of the following: 105624557865SSean Paul * 1057bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0 105824557865SSean Paul * The link is not protected, content is transmitted in the clear. 1059bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1 106024557865SSean Paul * Userspace has requested content protection, but the link is not 106124557865SSean Paul * currently protected. When in this state, kernel should enable 106224557865SSean Paul * Content Protection as soon as possible. 1063bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2 106424557865SSean Paul * Userspace has requested content protection, and the link is 106524557865SSean Paul * protected. Only the driver can set the property to this value. 106624557865SSean Paul * If userspace attempts to set to ENABLED, kernel will return 106724557865SSean Paul * -EINVAL. 106824557865SSean Paul * 106924557865SSean Paul * A few guidelines: 107024557865SSean Paul * 107124557865SSean Paul * - DESIRED state should be preserved until userspace de-asserts it by 107224557865SSean Paul * setting the property to UNDESIRED. This means ENABLED should only 107324557865SSean Paul * transition to UNDESIRED when the user explicitly requests it. 107424557865SSean Paul * - If the state is DESIRED, kernel should attempt to re-authenticate the 107524557865SSean Paul * link whenever possible. This includes across disable/enable, dpms, 107624557865SSean Paul * hotplug, downstream device changes, link status failures, etc.. 1077bb5a45d4SRamalingam C * - Kernel sends uevent with the connector id and property id through 1078bb5a45d4SRamalingam C * @drm_hdcp_update_content_protection, upon below kernel triggered 1079bb5a45d4SRamalingam C * scenarios: 108012db36bcSSean Paul * 108112db36bcSSean Paul * - DESIRED -> ENABLED (authentication success) 108212db36bcSSean Paul * - ENABLED -> DESIRED (termination of authentication) 1083bb5a45d4SRamalingam C * - Please note no uevents for userspace triggered property state changes, 1084bb5a45d4SRamalingam C * which can't fail such as 108512db36bcSSean Paul * 108612db36bcSSean Paul * - DESIRED/ENABLED -> UNDESIRED 108712db36bcSSean Paul * - UNDESIRED -> DESIRED 1088bb5a45d4SRamalingam C * - Userspace is responsible for polling the property or listen to uevents 1089bb5a45d4SRamalingam C * to determine when the value transitions from ENABLED to DESIRED. 1090bb5a45d4SRamalingam C * This signifies the link is no longer protected and userspace should 1091bb5a45d4SRamalingam C * take appropriate action (whatever that might be). 10924ada6f22SDaniel Vetter * 10937672dbbaSRamalingam C * HDCP Content Type: 10947672dbbaSRamalingam C * This Enum property is used by the userspace to declare the content type 10957672dbbaSRamalingam C * of the display stream, to kernel. Here display stream stands for any 10967672dbbaSRamalingam C * display content that userspace intended to display through HDCP 10977672dbbaSRamalingam C * encryption. 10987672dbbaSRamalingam C * 10997672dbbaSRamalingam C * Content Type of a stream is decided by the owner of the stream, as 11007672dbbaSRamalingam C * "HDCP Type0" or "HDCP Type1". 11017672dbbaSRamalingam C * 11027672dbbaSRamalingam C * The value of the property can be one of the below: 11037672dbbaSRamalingam C * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0 11047672dbbaSRamalingam C * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1 11057672dbbaSRamalingam C * 11067672dbbaSRamalingam C * When kernel starts the HDCP authentication (see "Content Protection" 11077672dbbaSRamalingam C * for details), it uses the content type in "HDCP Content Type" 11087672dbbaSRamalingam C * for performing the HDCP authentication with the display sink. 11097672dbbaSRamalingam C * 11107672dbbaSRamalingam C * Please note in HDCP spec versions, a link can be authenticated with 11117672dbbaSRamalingam C * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be 11127672dbbaSRamalingam C * authenticated with HDCP1.4 only for Content Type 0(though it is implicit 11137672dbbaSRamalingam C * in nature. As there is no reference for Content Type in HDCP1.4). 11147672dbbaSRamalingam C * 11157672dbbaSRamalingam C * HDCP2.2 authentication protocol itself takes the "Content Type" as a 11167672dbbaSRamalingam C * parameter, which is a input for the DP HDCP2.2 encryption algo. 11177672dbbaSRamalingam C * 11187672dbbaSRamalingam C * In case of Type 0 content protection request, kernel driver can choose 11197672dbbaSRamalingam C * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for 11207672dbbaSRamalingam C * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send 11217672dbbaSRamalingam C * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link). 11227672dbbaSRamalingam C * But if the content is classified as "HDCP Type 1", above mentioned 11237672dbbaSRamalingam C * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't 11247672dbbaSRamalingam C * authenticate the HDCP1.4 capable sink for "HDCP Type 1". 11257672dbbaSRamalingam C * 11267672dbbaSRamalingam C * Please note userspace can be ignorant of the HDCP versions used by the 11277672dbbaSRamalingam C * kernel driver to achieve the "HDCP Content Type". 11287672dbbaSRamalingam C * 11297672dbbaSRamalingam C * At current scenario, classifying a content as Type 1 ensures that the 11307672dbbaSRamalingam C * content will be displayed only through the HDCP2.2 encrypted link. 11317672dbbaSRamalingam C * 11327672dbbaSRamalingam C * Note that the HDCP Content Type property is introduced at HDCP 2.2, and 11337672dbbaSRamalingam C * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2 11347672dbbaSRamalingam C * (hence supporting Type 0 and Type 1). Based on how next versions of 11357672dbbaSRamalingam C * HDCP specs are defined content Type could be used for higher versions 11367672dbbaSRamalingam C * too. 11377672dbbaSRamalingam C * 11387672dbbaSRamalingam C * If content type is changed when "Content Protection" is not UNDESIRED, 11397672dbbaSRamalingam C * then kernel will disable the HDCP and re-enable with new type in the 11407672dbbaSRamalingam C * same atomic commit. And when "Content Protection" is ENABLED, it means 11417672dbbaSRamalingam C * that link is HDCP authenticated and encrypted, for the transmission of 11427672dbbaSRamalingam C * the Type of stream mentioned at "HDCP Content Type". 11437672dbbaSRamalingam C * 1144a09db883SUma Shankar * HDR_OUTPUT_METADATA: 1145a09db883SUma Shankar * Connector property to enable userspace to send HDR Metadata to 1146a09db883SUma Shankar * driver. This metadata is based on the composition and blending 1147a09db883SUma Shankar * policies decided by user, taking into account the hardware and 1148a09db883SUma Shankar * sink capabilities. The driver gets this metadata and creates a 1149a09db883SUma Shankar * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI, 1150a09db883SUma Shankar * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then 1151a09db883SUma Shankar * sent to sink. This notifies the sink of the upcoming frame's Color 1152a09db883SUma Shankar * Encoding and Luminance parameters. 1153a09db883SUma Shankar * 1154a09db883SUma Shankar * Userspace first need to detect the HDR capabilities of sink by 1155a09db883SUma Shankar * reading and parsing the EDID. Details of HDR metadata for HDMI 1156a09db883SUma Shankar * are added in CTA 861.G spec. For DP , its defined in VESA DP 1157a09db883SUma Shankar * Standard v1.4. It needs to then get the metadata information 1158a09db883SUma Shankar * of the video/game/app content which are encoded in HDR (basically 1159a09db883SUma Shankar * using HDR transfer functions). With this information it needs to 1160a09db883SUma Shankar * decide on a blending policy and compose the relevant 1161a09db883SUma Shankar * layers/overlays into a common format. Once this blending is done, 1162a09db883SUma Shankar * userspace will be aware of the metadata of the composed frame to 1163a09db883SUma Shankar * be send to sink. It then uses this property to communicate this 1164a09db883SUma Shankar * metadata to driver which then make a Infoframe packet and sends 1165a09db883SUma Shankar * to sink based on the type of encoder connected. 1166a09db883SUma Shankar * 1167a09db883SUma Shankar * Userspace will be responsible to do Tone mapping operation in case: 1168a09db883SUma Shankar * - Some layers are HDR and others are SDR 1169a09db883SUma Shankar * - HDR layers luminance is not same as sink 11709f9b2559SSean Paul * 1171a09db883SUma Shankar * It will even need to do colorspace conversion and get all layers 1172a09db883SUma Shankar * to one common colorspace for blending. It can use either GL, Media 117384e543bcSAntonio Borneo * or display engine to get this done based on the capabilities of the 1174a09db883SUma Shankar * associated hardware. 1175a09db883SUma Shankar * 1176a09db883SUma Shankar * Driver expects metadata to be put in &struct hdr_output_metadata 1177a09db883SUma Shankar * structure from userspace. This is received as blob and stored in 1178a09db883SUma Shankar * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the 1179a09db883SUma Shankar * sink metadata in &struct hdr_sink_metadata, as 1180a09db883SUma Shankar * &drm_connector.hdr_sink_metadata. Driver uses 1181a09db883SUma Shankar * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata, 1182a09db883SUma Shankar * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of 1183a09db883SUma Shankar * HDMI encoder. 1184a09db883SUma Shankar * 118547e22ff1SRadhakrishna Sripada * max bpc: 118647e22ff1SRadhakrishna Sripada * This range property is used by userspace to limit the bit depth. When 118747e22ff1SRadhakrishna Sripada * used the driver would limit the bpc in accordance with the valid range 118847e22ff1SRadhakrishna Sripada * supported by the hardware and sink. Drivers to use the function 118947e22ff1SRadhakrishna Sripada * drm_connector_attach_max_bpc_property() to create and attach the 119047e22ff1SRadhakrishna Sripada * property to the connector during initialization. 119147e22ff1SRadhakrishna Sripada * 11924ada6f22SDaniel Vetter * Connectors also have one standardized atomic property: 11934ada6f22SDaniel Vetter * 11944ada6f22SDaniel Vetter * CRTC_ID: 11954ada6f22SDaniel Vetter * Mode object ID of the &drm_crtc this connector should be connected to. 11968d70f395SHans de Goede * 11978d70f395SHans de Goede * Connectors for LCD panels may also have one standardized property: 11988d70f395SHans de Goede * 11998d70f395SHans de Goede * panel orientation: 12008d70f395SHans de Goede * On some devices the LCD panel is mounted in the casing in such a way 12018d70f395SHans de Goede * that the up/top side of the panel does not match with the top side of 12028d70f395SHans de Goede * the device. Userspace can use this property to check for this. 12038d70f395SHans de Goede * Note that input coordinates from touchscreens (input devices with 12048d70f395SHans de Goede * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel 12058d70f395SHans de Goede * coordinates, so if userspace rotates the picture to adjust for 12068d70f395SHans de Goede * the orientation it must also apply the same transformation to the 1207bbeba09fSDaniel Vetter * touchscreen input coordinates. This property is initialized by calling 120869654c63SDerek Basehore * drm_connector_set_panel_orientation() or 120969654c63SDerek Basehore * drm_connector_set_panel_orientation_with_quirk() 1210bbeba09fSDaniel Vetter * 1211bbeba09fSDaniel Vetter * scaling mode: 1212bbeba09fSDaniel Vetter * This property defines how a non-native mode is upscaled to the native 1213bbeba09fSDaniel Vetter * mode of an LCD panel: 1214bbeba09fSDaniel Vetter * 1215bbeba09fSDaniel Vetter * None: 1216bbeba09fSDaniel Vetter * No upscaling happens, scaling is left to the panel. Not all 1217bbeba09fSDaniel Vetter * drivers expose this mode. 1218bbeba09fSDaniel Vetter * Full: 1219bbeba09fSDaniel Vetter * The output is upscaled to the full resolution of the panel, 1220bbeba09fSDaniel Vetter * ignoring the aspect ratio. 1221bbeba09fSDaniel Vetter * Center: 1222bbeba09fSDaniel Vetter * No upscaling happens, the output is centered within the native 1223bbeba09fSDaniel Vetter * resolution the panel. 1224bbeba09fSDaniel Vetter * Full aspect: 1225bbeba09fSDaniel Vetter * The output is upscaled to maximize either the width or height 1226bbeba09fSDaniel Vetter * while retaining the aspect ratio. 1227bbeba09fSDaniel Vetter * 1228bbeba09fSDaniel Vetter * This property should be set up by calling 1229bbeba09fSDaniel Vetter * drm_connector_attach_scaling_mode_property(). Note that drivers 1230bbeba09fSDaniel Vetter * can also expose this property to external outputs, in which case they 1231bbeba09fSDaniel Vetter * must support "None", which should be the default (since external screens 1232bbeba09fSDaniel Vetter * have a built-in scaler). 1233*e5b92773SOleg Vasilev * 1234*e5b92773SOleg Vasilev * subconnector: 1235*e5b92773SOleg Vasilev * This property is used by DVI-I, TVout and DisplayPort to indicate different 1236*e5b92773SOleg Vasilev * connector subtypes. Enum values more or less match with those from main 1237*e5b92773SOleg Vasilev * connector types. 1238*e5b92773SOleg Vasilev * For DVI-I and TVout there is also a matching property "select subconnector" 1239*e5b92773SOleg Vasilev * allowing to switch between signal types. 1240*e5b92773SOleg Vasilev * DP subconnector corresponds to a downstream port. 12414ada6f22SDaniel Vetter */ 12424ada6f22SDaniel Vetter 124352217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev) 124452217195SDaniel Vetter { 124552217195SDaniel Vetter struct drm_property *prop; 124652217195SDaniel Vetter 124752217195SDaniel Vetter prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | 124852217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 124952217195SDaniel Vetter "EDID", 0); 125052217195SDaniel Vetter if (!prop) 125152217195SDaniel Vetter return -ENOMEM; 125252217195SDaniel Vetter dev->mode_config.edid_property = prop; 125352217195SDaniel Vetter 125452217195SDaniel Vetter prop = drm_property_create_enum(dev, 0, 125552217195SDaniel Vetter "DPMS", drm_dpms_enum_list, 125652217195SDaniel Vetter ARRAY_SIZE(drm_dpms_enum_list)); 125752217195SDaniel Vetter if (!prop) 125852217195SDaniel Vetter return -ENOMEM; 125952217195SDaniel Vetter dev->mode_config.dpms_property = prop; 126052217195SDaniel Vetter 126152217195SDaniel Vetter prop = drm_property_create(dev, 126252217195SDaniel Vetter DRM_MODE_PROP_BLOB | 126352217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 126452217195SDaniel Vetter "PATH", 0); 126552217195SDaniel Vetter if (!prop) 126652217195SDaniel Vetter return -ENOMEM; 126752217195SDaniel Vetter dev->mode_config.path_property = prop; 126852217195SDaniel Vetter 126952217195SDaniel Vetter prop = drm_property_create(dev, 127052217195SDaniel Vetter DRM_MODE_PROP_BLOB | 127152217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 127252217195SDaniel Vetter "TILE", 0); 127352217195SDaniel Vetter if (!prop) 127452217195SDaniel Vetter return -ENOMEM; 127552217195SDaniel Vetter dev->mode_config.tile_property = prop; 127652217195SDaniel Vetter 127740ee6fbeSManasi Navare prop = drm_property_create_enum(dev, 0, "link-status", 127840ee6fbeSManasi Navare drm_link_status_enum_list, 127940ee6fbeSManasi Navare ARRAY_SIZE(drm_link_status_enum_list)); 128040ee6fbeSManasi Navare if (!prop) 128140ee6fbeSManasi Navare return -ENOMEM; 128240ee6fbeSManasi Navare dev->mode_config.link_status_property = prop; 128340ee6fbeSManasi Navare 128466660d4cSDave Airlie prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop"); 128566660d4cSDave Airlie if (!prop) 128666660d4cSDave Airlie return -ENOMEM; 128766660d4cSDave Airlie dev->mode_config.non_desktop_property = prop; 128866660d4cSDave Airlie 1289fbb5d035SUma Shankar prop = drm_property_create(dev, DRM_MODE_PROP_BLOB, 1290fbb5d035SUma Shankar "HDR_OUTPUT_METADATA", 0); 1291fbb5d035SUma Shankar if (!prop) 1292fbb5d035SUma Shankar return -ENOMEM; 1293fbb5d035SUma Shankar dev->mode_config.hdr_output_metadata_property = prop; 1294fbb5d035SUma Shankar 129552217195SDaniel Vetter return 0; 129652217195SDaniel Vetter } 129752217195SDaniel Vetter 129852217195SDaniel Vetter /** 129952217195SDaniel Vetter * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties 130052217195SDaniel Vetter * @dev: DRM device 130152217195SDaniel Vetter * 130252217195SDaniel Vetter * Called by a driver the first time a DVI-I connector is made. 130352217195SDaniel Vetter */ 130452217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev) 130552217195SDaniel Vetter { 130652217195SDaniel Vetter struct drm_property *dvi_i_selector; 130752217195SDaniel Vetter struct drm_property *dvi_i_subconnector; 130852217195SDaniel Vetter 130952217195SDaniel Vetter if (dev->mode_config.dvi_i_select_subconnector_property) 131052217195SDaniel Vetter return 0; 131152217195SDaniel Vetter 131252217195SDaniel Vetter dvi_i_selector = 131352217195SDaniel Vetter drm_property_create_enum(dev, 0, 131452217195SDaniel Vetter "select subconnector", 131552217195SDaniel Vetter drm_dvi_i_select_enum_list, 131652217195SDaniel Vetter ARRAY_SIZE(drm_dvi_i_select_enum_list)); 131752217195SDaniel Vetter dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; 131852217195SDaniel Vetter 131952217195SDaniel Vetter dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 132052217195SDaniel Vetter "subconnector", 132152217195SDaniel Vetter drm_dvi_i_subconnector_enum_list, 132252217195SDaniel Vetter ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); 132352217195SDaniel Vetter dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; 132452217195SDaniel Vetter 132552217195SDaniel Vetter return 0; 132652217195SDaniel Vetter } 132752217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); 132852217195SDaniel Vetter 132952217195SDaniel Vetter /** 1330*e5b92773SOleg Vasilev * drm_connector_attach_dp_subconnector_property - create subconnector property for DP 1331*e5b92773SOleg Vasilev * @connector: drm_connector to attach property 1332*e5b92773SOleg Vasilev * 1333*e5b92773SOleg Vasilev * Called by a driver when DP connector is created. 1334*e5b92773SOleg Vasilev */ 1335*e5b92773SOleg Vasilev void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector) 1336*e5b92773SOleg Vasilev { 1337*e5b92773SOleg Vasilev struct drm_mode_config *mode_config = &connector->dev->mode_config; 1338*e5b92773SOleg Vasilev 1339*e5b92773SOleg Vasilev if (!mode_config->dp_subconnector_property) 1340*e5b92773SOleg Vasilev mode_config->dp_subconnector_property = 1341*e5b92773SOleg Vasilev drm_property_create_enum(connector->dev, 1342*e5b92773SOleg Vasilev DRM_MODE_PROP_IMMUTABLE, 1343*e5b92773SOleg Vasilev "subconnector", 1344*e5b92773SOleg Vasilev drm_dp_subconnector_enum_list, 1345*e5b92773SOleg Vasilev ARRAY_SIZE(drm_dp_subconnector_enum_list)); 1346*e5b92773SOleg Vasilev 1347*e5b92773SOleg Vasilev drm_object_attach_property(&connector->base, 1348*e5b92773SOleg Vasilev mode_config->dp_subconnector_property, 1349*e5b92773SOleg Vasilev DRM_MODE_SUBCONNECTOR_Unknown); 1350*e5b92773SOleg Vasilev } 1351*e5b92773SOleg Vasilev EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property); 1352*e5b92773SOleg Vasilev 1353*e5b92773SOleg Vasilev /** 135450525c33SStanislav Lisovskiy * DOC: HDMI connector properties 135550525c33SStanislav Lisovskiy * 135650525c33SStanislav Lisovskiy * content type (HDMI specific): 135750525c33SStanislav Lisovskiy * Indicates content type setting to be used in HDMI infoframes to indicate 13581e55a53aSMatt Roper * content type for the external device, so that it adjusts its display 135950525c33SStanislav Lisovskiy * settings accordingly. 136050525c33SStanislav Lisovskiy * 136150525c33SStanislav Lisovskiy * The value of this property can be one of the following: 136250525c33SStanislav Lisovskiy * 136350525c33SStanislav Lisovskiy * No Data: 136450525c33SStanislav Lisovskiy * Content type is unknown 136550525c33SStanislav Lisovskiy * Graphics: 136650525c33SStanislav Lisovskiy * Content type is graphics 136750525c33SStanislav Lisovskiy * Photo: 136850525c33SStanislav Lisovskiy * Content type is photo 136950525c33SStanislav Lisovskiy * Cinema: 137050525c33SStanislav Lisovskiy * Content type is cinema 137150525c33SStanislav Lisovskiy * Game: 137250525c33SStanislav Lisovskiy * Content type is game 137350525c33SStanislav Lisovskiy * 137450525c33SStanislav Lisovskiy * Drivers can set up this property by calling 137550525c33SStanislav Lisovskiy * drm_connector_attach_content_type_property(). Decoding to 1376ba609631SDaniel Vetter * infoframe values is done through drm_hdmi_avi_infoframe_content_type(). 137750525c33SStanislav Lisovskiy */ 137850525c33SStanislav Lisovskiy 137950525c33SStanislav Lisovskiy /** 138050525c33SStanislav Lisovskiy * drm_connector_attach_content_type_property - attach content-type property 138150525c33SStanislav Lisovskiy * @connector: connector to attach content type property on. 138250525c33SStanislav Lisovskiy * 138350525c33SStanislav Lisovskiy * Called by a driver the first time a HDMI connector is made. 138450525c33SStanislav Lisovskiy */ 138550525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector) 138650525c33SStanislav Lisovskiy { 138750525c33SStanislav Lisovskiy if (!drm_mode_create_content_type_property(connector->dev)) 138850525c33SStanislav Lisovskiy drm_object_attach_property(&connector->base, 138950525c33SStanislav Lisovskiy connector->dev->mode_config.content_type_property, 139050525c33SStanislav Lisovskiy DRM_MODE_CONTENT_TYPE_NO_DATA); 139150525c33SStanislav Lisovskiy return 0; 139250525c33SStanislav Lisovskiy } 139350525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property); 139450525c33SStanislav Lisovskiy 139550525c33SStanislav Lisovskiy 139650525c33SStanislav Lisovskiy /** 139750525c33SStanislav Lisovskiy * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe 139850525c33SStanislav Lisovskiy * content type information, based 139950525c33SStanislav Lisovskiy * on correspondent DRM property. 140050525c33SStanislav Lisovskiy * @frame: HDMI AVI infoframe 140150525c33SStanislav Lisovskiy * @conn_state: DRM display connector state 140250525c33SStanislav Lisovskiy * 140350525c33SStanislav Lisovskiy */ 140450525c33SStanislav Lisovskiy void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame, 140550525c33SStanislav Lisovskiy const struct drm_connector_state *conn_state) 140650525c33SStanislav Lisovskiy { 140750525c33SStanislav Lisovskiy switch (conn_state->content_type) { 140850525c33SStanislav Lisovskiy case DRM_MODE_CONTENT_TYPE_GRAPHICS: 140950525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS; 141050525c33SStanislav Lisovskiy break; 141150525c33SStanislav Lisovskiy case DRM_MODE_CONTENT_TYPE_CINEMA: 141250525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_CINEMA; 141350525c33SStanislav Lisovskiy break; 141450525c33SStanislav Lisovskiy case DRM_MODE_CONTENT_TYPE_GAME: 141550525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_GAME; 141650525c33SStanislav Lisovskiy break; 141750525c33SStanislav Lisovskiy case DRM_MODE_CONTENT_TYPE_PHOTO: 141850525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_PHOTO; 141950525c33SStanislav Lisovskiy break; 142050525c33SStanislav Lisovskiy default: 142150525c33SStanislav Lisovskiy /* Graphics is the default(0) */ 142250525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS; 142350525c33SStanislav Lisovskiy } 142450525c33SStanislav Lisovskiy 142550525c33SStanislav Lisovskiy frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA; 142650525c33SStanislav Lisovskiy } 142750525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type); 142850525c33SStanislav Lisovskiy 142950525c33SStanislav Lisovskiy /** 14306c4f52dcSBoris Brezillon * drm_mode_attach_tv_margin_properties - attach TV connector margin properties 14316c4f52dcSBoris Brezillon * @connector: DRM connector 14326c4f52dcSBoris Brezillon * 14336c4f52dcSBoris Brezillon * Called by a driver when it needs to attach TV margin props to a connector. 14346c4f52dcSBoris Brezillon * Typically used on SDTV and HDMI connectors. 14356c4f52dcSBoris Brezillon */ 14366c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector) 14376c4f52dcSBoris Brezillon { 14386c4f52dcSBoris Brezillon struct drm_device *dev = connector->dev; 14396c4f52dcSBoris Brezillon 14406c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 14416c4f52dcSBoris Brezillon dev->mode_config.tv_left_margin_property, 14426c4f52dcSBoris Brezillon 0); 14436c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 14446c4f52dcSBoris Brezillon dev->mode_config.tv_right_margin_property, 14456c4f52dcSBoris Brezillon 0); 14466c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 14476c4f52dcSBoris Brezillon dev->mode_config.tv_top_margin_property, 14486c4f52dcSBoris Brezillon 0); 14496c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 14506c4f52dcSBoris Brezillon dev->mode_config.tv_bottom_margin_property, 14516c4f52dcSBoris Brezillon 0); 14526c4f52dcSBoris Brezillon } 14536c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties); 14546c4f52dcSBoris Brezillon 14556c4f52dcSBoris Brezillon /** 14566c4f52dcSBoris Brezillon * drm_mode_create_tv_margin_properties - create TV connector margin properties 14576c4f52dcSBoris Brezillon * @dev: DRM device 14586c4f52dcSBoris Brezillon * 14596c4f52dcSBoris Brezillon * Called by a driver's HDMI connector initialization routine, this function 14606c4f52dcSBoris Brezillon * creates the TV margin properties for a given device. No need to call this 14616c4f52dcSBoris Brezillon * function for an SDTV connector, it's already called from 14626c4f52dcSBoris Brezillon * drm_mode_create_tv_properties(). 14636c4f52dcSBoris Brezillon */ 14646c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev) 14656c4f52dcSBoris Brezillon { 14666c4f52dcSBoris Brezillon if (dev->mode_config.tv_left_margin_property) 14676c4f52dcSBoris Brezillon return 0; 14686c4f52dcSBoris Brezillon 14696c4f52dcSBoris Brezillon dev->mode_config.tv_left_margin_property = 14706c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "left margin", 0, 100); 14716c4f52dcSBoris Brezillon if (!dev->mode_config.tv_left_margin_property) 14726c4f52dcSBoris Brezillon return -ENOMEM; 14736c4f52dcSBoris Brezillon 14746c4f52dcSBoris Brezillon dev->mode_config.tv_right_margin_property = 14756c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "right margin", 0, 100); 14766c4f52dcSBoris Brezillon if (!dev->mode_config.tv_right_margin_property) 14776c4f52dcSBoris Brezillon return -ENOMEM; 14786c4f52dcSBoris Brezillon 14796c4f52dcSBoris Brezillon dev->mode_config.tv_top_margin_property = 14806c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "top margin", 0, 100); 14816c4f52dcSBoris Brezillon if (!dev->mode_config.tv_top_margin_property) 14826c4f52dcSBoris Brezillon return -ENOMEM; 14836c4f52dcSBoris Brezillon 14846c4f52dcSBoris Brezillon dev->mode_config.tv_bottom_margin_property = 14856c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "bottom margin", 0, 100); 14866c4f52dcSBoris Brezillon if (!dev->mode_config.tv_bottom_margin_property) 14876c4f52dcSBoris Brezillon return -ENOMEM; 14886c4f52dcSBoris Brezillon 14896c4f52dcSBoris Brezillon return 0; 14906c4f52dcSBoris Brezillon } 14916c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties); 14926c4f52dcSBoris Brezillon 14936c4f52dcSBoris Brezillon /** 1494eda6887fSBoris Brezillon * drm_mode_create_tv_properties - create TV specific connector properties 149552217195SDaniel Vetter * @dev: DRM device 149652217195SDaniel Vetter * @num_modes: number of different TV formats (modes) supported 149752217195SDaniel Vetter * @modes: array of pointers to strings containing name of each format 149852217195SDaniel Vetter * 149952217195SDaniel Vetter * Called by a driver's TV initialization routine, this function creates 150052217195SDaniel Vetter * the TV specific connector properties for a given device. Caller is 150152217195SDaniel Vetter * responsible for allocating a list of format names and passing them to 150252217195SDaniel Vetter * this routine. 150352217195SDaniel Vetter */ 150452217195SDaniel Vetter int drm_mode_create_tv_properties(struct drm_device *dev, 150552217195SDaniel Vetter unsigned int num_modes, 150652217195SDaniel Vetter const char * const modes[]) 150752217195SDaniel Vetter { 150852217195SDaniel Vetter struct drm_property *tv_selector; 150952217195SDaniel Vetter struct drm_property *tv_subconnector; 151052217195SDaniel Vetter unsigned int i; 151152217195SDaniel Vetter 151252217195SDaniel Vetter if (dev->mode_config.tv_select_subconnector_property) 151352217195SDaniel Vetter return 0; 151452217195SDaniel Vetter 151552217195SDaniel Vetter /* 151652217195SDaniel Vetter * Basic connector properties 151752217195SDaniel Vetter */ 151852217195SDaniel Vetter tv_selector = drm_property_create_enum(dev, 0, 151952217195SDaniel Vetter "select subconnector", 152052217195SDaniel Vetter drm_tv_select_enum_list, 152152217195SDaniel Vetter ARRAY_SIZE(drm_tv_select_enum_list)); 152252217195SDaniel Vetter if (!tv_selector) 152352217195SDaniel Vetter goto nomem; 152452217195SDaniel Vetter 152552217195SDaniel Vetter dev->mode_config.tv_select_subconnector_property = tv_selector; 152652217195SDaniel Vetter 152752217195SDaniel Vetter tv_subconnector = 152852217195SDaniel Vetter drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 152952217195SDaniel Vetter "subconnector", 153052217195SDaniel Vetter drm_tv_subconnector_enum_list, 153152217195SDaniel Vetter ARRAY_SIZE(drm_tv_subconnector_enum_list)); 153252217195SDaniel Vetter if (!tv_subconnector) 153352217195SDaniel Vetter goto nomem; 153452217195SDaniel Vetter dev->mode_config.tv_subconnector_property = tv_subconnector; 153552217195SDaniel Vetter 153652217195SDaniel Vetter /* 153752217195SDaniel Vetter * Other, TV specific properties: margins & TV modes. 153852217195SDaniel Vetter */ 15396c4f52dcSBoris Brezillon if (drm_mode_create_tv_margin_properties(dev)) 154052217195SDaniel Vetter goto nomem; 154152217195SDaniel Vetter 154252217195SDaniel Vetter dev->mode_config.tv_mode_property = 154352217195SDaniel Vetter drm_property_create(dev, DRM_MODE_PROP_ENUM, 154452217195SDaniel Vetter "mode", num_modes); 154552217195SDaniel Vetter if (!dev->mode_config.tv_mode_property) 154652217195SDaniel Vetter goto nomem; 154752217195SDaniel Vetter 154852217195SDaniel Vetter for (i = 0; i < num_modes; i++) 154930e9db6dSVille Syrjälä drm_property_add_enum(dev->mode_config.tv_mode_property, 155052217195SDaniel Vetter i, modes[i]); 155152217195SDaniel Vetter 155252217195SDaniel Vetter dev->mode_config.tv_brightness_property = 155352217195SDaniel Vetter drm_property_create_range(dev, 0, "brightness", 0, 100); 155452217195SDaniel Vetter if (!dev->mode_config.tv_brightness_property) 155552217195SDaniel Vetter goto nomem; 155652217195SDaniel Vetter 155752217195SDaniel Vetter dev->mode_config.tv_contrast_property = 155852217195SDaniel Vetter drm_property_create_range(dev, 0, "contrast", 0, 100); 155952217195SDaniel Vetter if (!dev->mode_config.tv_contrast_property) 156052217195SDaniel Vetter goto nomem; 156152217195SDaniel Vetter 156252217195SDaniel Vetter dev->mode_config.tv_flicker_reduction_property = 156352217195SDaniel Vetter drm_property_create_range(dev, 0, "flicker reduction", 0, 100); 156452217195SDaniel Vetter if (!dev->mode_config.tv_flicker_reduction_property) 156552217195SDaniel Vetter goto nomem; 156652217195SDaniel Vetter 156752217195SDaniel Vetter dev->mode_config.tv_overscan_property = 156852217195SDaniel Vetter drm_property_create_range(dev, 0, "overscan", 0, 100); 156952217195SDaniel Vetter if (!dev->mode_config.tv_overscan_property) 157052217195SDaniel Vetter goto nomem; 157152217195SDaniel Vetter 157252217195SDaniel Vetter dev->mode_config.tv_saturation_property = 157352217195SDaniel Vetter drm_property_create_range(dev, 0, "saturation", 0, 100); 157452217195SDaniel Vetter if (!dev->mode_config.tv_saturation_property) 157552217195SDaniel Vetter goto nomem; 157652217195SDaniel Vetter 157752217195SDaniel Vetter dev->mode_config.tv_hue_property = 157852217195SDaniel Vetter drm_property_create_range(dev, 0, "hue", 0, 100); 157952217195SDaniel Vetter if (!dev->mode_config.tv_hue_property) 158052217195SDaniel Vetter goto nomem; 158152217195SDaniel Vetter 158252217195SDaniel Vetter return 0; 158352217195SDaniel Vetter nomem: 158452217195SDaniel Vetter return -ENOMEM; 158552217195SDaniel Vetter } 158652217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tv_properties); 158752217195SDaniel Vetter 158852217195SDaniel Vetter /** 158952217195SDaniel Vetter * drm_mode_create_scaling_mode_property - create scaling mode property 159052217195SDaniel Vetter * @dev: DRM device 159152217195SDaniel Vetter * 159252217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 159352217195SDaniel Vetter * connectors. 15948f6e1e22SMaarten Lankhorst * 15958f6e1e22SMaarten Lankhorst * Atomic drivers should use drm_connector_attach_scaling_mode_property() 15968f6e1e22SMaarten Lankhorst * instead to correctly assign &drm_connector_state.picture_aspect_ratio 15978f6e1e22SMaarten Lankhorst * in the atomic state. 159852217195SDaniel Vetter */ 159952217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev) 160052217195SDaniel Vetter { 160152217195SDaniel Vetter struct drm_property *scaling_mode; 160252217195SDaniel Vetter 160352217195SDaniel Vetter if (dev->mode_config.scaling_mode_property) 160452217195SDaniel Vetter return 0; 160552217195SDaniel Vetter 160652217195SDaniel Vetter scaling_mode = 160752217195SDaniel Vetter drm_property_create_enum(dev, 0, "scaling mode", 160852217195SDaniel Vetter drm_scaling_mode_enum_list, 160952217195SDaniel Vetter ARRAY_SIZE(drm_scaling_mode_enum_list)); 161052217195SDaniel Vetter 161152217195SDaniel Vetter dev->mode_config.scaling_mode_property = scaling_mode; 161252217195SDaniel Vetter 161352217195SDaniel Vetter return 0; 161452217195SDaniel Vetter } 161552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); 161652217195SDaniel Vetter 161752217195SDaniel Vetter /** 1618ab7a664fSNicholas Kazlauskas * DOC: Variable refresh properties 1619ab7a664fSNicholas Kazlauskas * 1620ab7a664fSNicholas Kazlauskas * Variable refresh rate capable displays can dynamically adjust their 1621ab7a664fSNicholas Kazlauskas * refresh rate by extending the duration of their vertical front porch 1622ab7a664fSNicholas Kazlauskas * until page flip or timeout occurs. This can reduce or remove stuttering 1623ab7a664fSNicholas Kazlauskas * and latency in scenarios where the page flip does not align with the 1624ab7a664fSNicholas Kazlauskas * vblank interval. 1625ab7a664fSNicholas Kazlauskas * 1626ab7a664fSNicholas Kazlauskas * An example scenario would be an application flipping at a constant rate 1627ab7a664fSNicholas Kazlauskas * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank 1628ab7a664fSNicholas Kazlauskas * interval and the same contents will be displayed twice. This can be 1629ab7a664fSNicholas Kazlauskas * observed as stuttering for content with motion. 1630ab7a664fSNicholas Kazlauskas * 1631ab7a664fSNicholas Kazlauskas * If variable refresh rate was active on a display that supported a 1632ab7a664fSNicholas Kazlauskas * variable refresh range from 35Hz to 60Hz no stuttering would be observable 1633ab7a664fSNicholas Kazlauskas * for the example scenario. The minimum supported variable refresh rate of 1634ab7a664fSNicholas Kazlauskas * 35Hz is below the page flip frequency and the vertical front porch can 1635ab7a664fSNicholas Kazlauskas * be extended until the page flip occurs. The vblank interval will be 1636ab7a664fSNicholas Kazlauskas * directly aligned to the page flip rate. 1637ab7a664fSNicholas Kazlauskas * 1638ab7a664fSNicholas Kazlauskas * Not all userspace content is suitable for use with variable refresh rate. 1639ab7a664fSNicholas Kazlauskas * Large and frequent changes in vertical front porch duration may worsen 1640ab7a664fSNicholas Kazlauskas * perceived stuttering for input sensitive applications. 1641ab7a664fSNicholas Kazlauskas * 1642ab7a664fSNicholas Kazlauskas * Panel brightness will also vary with vertical front porch duration. Some 1643ab7a664fSNicholas Kazlauskas * panels may have noticeable differences in brightness between the minimum 1644ab7a664fSNicholas Kazlauskas * vertical front porch duration and the maximum vertical front porch duration. 1645ab7a664fSNicholas Kazlauskas * Large and frequent changes in vertical front porch duration may produce 1646ab7a664fSNicholas Kazlauskas * observable flickering for such panels. 1647ab7a664fSNicholas Kazlauskas * 1648ab7a664fSNicholas Kazlauskas * Userspace control for variable refresh rate is supported via properties 1649ab7a664fSNicholas Kazlauskas * on the &drm_connector and &drm_crtc objects. 1650ab7a664fSNicholas Kazlauskas * 1651ab7a664fSNicholas Kazlauskas * "vrr_capable": 1652ab7a664fSNicholas Kazlauskas * Optional &drm_connector boolean property that drivers should attach 1653ab7a664fSNicholas Kazlauskas * with drm_connector_attach_vrr_capable_property() on connectors that 1654ab7a664fSNicholas Kazlauskas * could support variable refresh rates. Drivers should update the 1655ab7a664fSNicholas Kazlauskas * property value by calling drm_connector_set_vrr_capable_property(). 1656ab7a664fSNicholas Kazlauskas * 1657ab7a664fSNicholas Kazlauskas * Absence of the property should indicate absence of support. 1658ab7a664fSNicholas Kazlauskas * 165977086014SDaniel Vetter * "VRR_ENABLED": 1660ab7a664fSNicholas Kazlauskas * Default &drm_crtc boolean property that notifies the driver that the 1661ab7a664fSNicholas Kazlauskas * content on the CRTC is suitable for variable refresh rate presentation. 1662ab7a664fSNicholas Kazlauskas * The driver will take this property as a hint to enable variable 1663ab7a664fSNicholas Kazlauskas * refresh rate support if the receiver supports it, ie. if the 1664ab7a664fSNicholas Kazlauskas * "vrr_capable" property is true on the &drm_connector object. The 1665ab7a664fSNicholas Kazlauskas * vertical front porch duration will be extended until page-flip or 1666ab7a664fSNicholas Kazlauskas * timeout when enabled. 1667ab7a664fSNicholas Kazlauskas * 1668ab7a664fSNicholas Kazlauskas * The minimum vertical front porch duration is defined as the vertical 1669ab7a664fSNicholas Kazlauskas * front porch duration for the current mode. 1670ab7a664fSNicholas Kazlauskas * 1671ab7a664fSNicholas Kazlauskas * The maximum vertical front porch duration is greater than or equal to 1672ab7a664fSNicholas Kazlauskas * the minimum vertical front porch duration. The duration is derived 1673ab7a664fSNicholas Kazlauskas * from the minimum supported variable refresh rate for the connector. 1674ab7a664fSNicholas Kazlauskas * 1675ab7a664fSNicholas Kazlauskas * The driver may place further restrictions within these minimum 1676ab7a664fSNicholas Kazlauskas * and maximum bounds. 1677ab7a664fSNicholas Kazlauskas */ 1678ab7a664fSNicholas Kazlauskas 1679ab7a664fSNicholas Kazlauskas /** 1680ba1b0f6cSNicholas Kazlauskas * drm_connector_attach_vrr_capable_property - creates the 1681ba1b0f6cSNicholas Kazlauskas * vrr_capable property 1682ba1b0f6cSNicholas Kazlauskas * @connector: connector to create the vrr_capable property on. 1683ba1b0f6cSNicholas Kazlauskas * 1684ba1b0f6cSNicholas Kazlauskas * This is used by atomic drivers to add support for querying 1685ba1b0f6cSNicholas Kazlauskas * variable refresh rate capability for a connector. 1686ba1b0f6cSNicholas Kazlauskas * 1687ba1b0f6cSNicholas Kazlauskas * Returns: 168884e543bcSAntonio Borneo * Zero on success, negative errno on failure. 1689ba1b0f6cSNicholas Kazlauskas */ 1690ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property( 1691ba1b0f6cSNicholas Kazlauskas struct drm_connector *connector) 1692ba1b0f6cSNicholas Kazlauskas { 1693ba1b0f6cSNicholas Kazlauskas struct drm_device *dev = connector->dev; 1694ba1b0f6cSNicholas Kazlauskas struct drm_property *prop; 1695ba1b0f6cSNicholas Kazlauskas 1696ba1b0f6cSNicholas Kazlauskas if (!connector->vrr_capable_property) { 1697ba1b0f6cSNicholas Kazlauskas prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, 1698ba1b0f6cSNicholas Kazlauskas "vrr_capable"); 1699ba1b0f6cSNicholas Kazlauskas if (!prop) 1700ba1b0f6cSNicholas Kazlauskas return -ENOMEM; 1701ba1b0f6cSNicholas Kazlauskas 1702ba1b0f6cSNicholas Kazlauskas connector->vrr_capable_property = prop; 1703ba1b0f6cSNicholas Kazlauskas drm_object_attach_property(&connector->base, prop, 0); 1704ba1b0f6cSNicholas Kazlauskas } 1705ba1b0f6cSNicholas Kazlauskas 1706ba1b0f6cSNicholas Kazlauskas return 0; 1707ba1b0f6cSNicholas Kazlauskas } 1708ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property); 1709ba1b0f6cSNicholas Kazlauskas 1710ba1b0f6cSNicholas Kazlauskas /** 17118f6e1e22SMaarten Lankhorst * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property 17128f6e1e22SMaarten Lankhorst * @connector: connector to attach scaling mode property on. 17138f6e1e22SMaarten Lankhorst * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*). 17148f6e1e22SMaarten Lankhorst * 17158f6e1e22SMaarten Lankhorst * This is used to add support for scaling mode to atomic drivers. 17168f6e1e22SMaarten Lankhorst * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio 17178f6e1e22SMaarten Lankhorst * and can be used from &drm_connector_helper_funcs->atomic_check for validation. 17188f6e1e22SMaarten Lankhorst * 17198f6e1e22SMaarten Lankhorst * This is the atomic version of drm_mode_create_scaling_mode_property(). 17208f6e1e22SMaarten Lankhorst * 17218f6e1e22SMaarten Lankhorst * Returns: 17228f6e1e22SMaarten Lankhorst * Zero on success, negative errno on failure. 17238f6e1e22SMaarten Lankhorst */ 17248f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector, 17258f6e1e22SMaarten Lankhorst u32 scaling_mode_mask) 17268f6e1e22SMaarten Lankhorst { 17278f6e1e22SMaarten Lankhorst struct drm_device *dev = connector->dev; 17288f6e1e22SMaarten Lankhorst struct drm_property *scaling_mode_property; 172930e9db6dSVille Syrjälä int i; 17308f6e1e22SMaarten Lankhorst const unsigned valid_scaling_mode_mask = 17318f6e1e22SMaarten Lankhorst (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1; 17328f6e1e22SMaarten Lankhorst 17338f6e1e22SMaarten Lankhorst if (WARN_ON(hweight32(scaling_mode_mask) < 2 || 17348f6e1e22SMaarten Lankhorst scaling_mode_mask & ~valid_scaling_mode_mask)) 17358f6e1e22SMaarten Lankhorst return -EINVAL; 17368f6e1e22SMaarten Lankhorst 17378f6e1e22SMaarten Lankhorst scaling_mode_property = 17388f6e1e22SMaarten Lankhorst drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode", 17398f6e1e22SMaarten Lankhorst hweight32(scaling_mode_mask)); 17408f6e1e22SMaarten Lankhorst 17418f6e1e22SMaarten Lankhorst if (!scaling_mode_property) 17428f6e1e22SMaarten Lankhorst return -ENOMEM; 17438f6e1e22SMaarten Lankhorst 17448f6e1e22SMaarten Lankhorst for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) { 17458f6e1e22SMaarten Lankhorst int ret; 17468f6e1e22SMaarten Lankhorst 17478f6e1e22SMaarten Lankhorst if (!(BIT(i) & scaling_mode_mask)) 17488f6e1e22SMaarten Lankhorst continue; 17498f6e1e22SMaarten Lankhorst 175030e9db6dSVille Syrjälä ret = drm_property_add_enum(scaling_mode_property, 17518f6e1e22SMaarten Lankhorst drm_scaling_mode_enum_list[i].type, 17528f6e1e22SMaarten Lankhorst drm_scaling_mode_enum_list[i].name); 17538f6e1e22SMaarten Lankhorst 17548f6e1e22SMaarten Lankhorst if (ret) { 17558f6e1e22SMaarten Lankhorst drm_property_destroy(dev, scaling_mode_property); 17568f6e1e22SMaarten Lankhorst 17578f6e1e22SMaarten Lankhorst return ret; 17588f6e1e22SMaarten Lankhorst } 17598f6e1e22SMaarten Lankhorst } 17608f6e1e22SMaarten Lankhorst 17618f6e1e22SMaarten Lankhorst drm_object_attach_property(&connector->base, 17628f6e1e22SMaarten Lankhorst scaling_mode_property, 0); 17638f6e1e22SMaarten Lankhorst 17648f6e1e22SMaarten Lankhorst connector->scaling_mode_property = scaling_mode_property; 17658f6e1e22SMaarten Lankhorst 17668f6e1e22SMaarten Lankhorst return 0; 17678f6e1e22SMaarten Lankhorst } 17688f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property); 17698f6e1e22SMaarten Lankhorst 17708f6e1e22SMaarten Lankhorst /** 177152217195SDaniel Vetter * drm_mode_create_aspect_ratio_property - create aspect ratio property 177252217195SDaniel Vetter * @dev: DRM device 177352217195SDaniel Vetter * 177452217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 177552217195SDaniel Vetter * connectors. 177652217195SDaniel Vetter * 177752217195SDaniel Vetter * Returns: 177852217195SDaniel Vetter * Zero on success, negative errno on failure. 177952217195SDaniel Vetter */ 178052217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev) 178152217195SDaniel Vetter { 178252217195SDaniel Vetter if (dev->mode_config.aspect_ratio_property) 178352217195SDaniel Vetter return 0; 178452217195SDaniel Vetter 178552217195SDaniel Vetter dev->mode_config.aspect_ratio_property = 178652217195SDaniel Vetter drm_property_create_enum(dev, 0, "aspect ratio", 178752217195SDaniel Vetter drm_aspect_ratio_enum_list, 178852217195SDaniel Vetter ARRAY_SIZE(drm_aspect_ratio_enum_list)); 178952217195SDaniel Vetter 179052217195SDaniel Vetter if (dev->mode_config.aspect_ratio_property == NULL) 179152217195SDaniel Vetter return -ENOMEM; 179252217195SDaniel Vetter 179352217195SDaniel Vetter return 0; 179452217195SDaniel Vetter } 179552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); 179652217195SDaniel Vetter 179752217195SDaniel Vetter /** 1798d2c6a405SUma Shankar * DOC: standard connector properties 1799d2c6a405SUma Shankar * 1800d2c6a405SUma Shankar * Colorspace: 1801d2c6a405SUma Shankar * This property helps select a suitable colorspace based on the sink 1802d2c6a405SUma Shankar * capability. Modern sink devices support wider gamut like BT2020. 1803d2c6a405SUma Shankar * This helps switch to BT2020 mode if the BT2020 encoded video stream 1804d2c6a405SUma Shankar * is being played by the user, same for any other colorspace. Thereby 1805d2c6a405SUma Shankar * giving a good visual experience to users. 1806d2c6a405SUma Shankar * 1807d2c6a405SUma Shankar * The expectation from userspace is that it should parse the EDID 1808d2c6a405SUma Shankar * and get supported colorspaces. Use this property and switch to the 1809d2c6a405SUma Shankar * one supported. Sink supported colorspaces should be retrieved by 1810d2c6a405SUma Shankar * userspace from EDID and driver will not explicitly expose them. 1811d2c6a405SUma Shankar * 1812d2c6a405SUma Shankar * Basically the expectation from userspace is: 1813d2c6a405SUma Shankar * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink 1814d2c6a405SUma Shankar * colorspace 1815d2c6a405SUma Shankar * - Set this new property to let the sink know what it 1816d2c6a405SUma Shankar * converted the CRTC output to. 1817d2c6a405SUma Shankar * - This property is just to inform sink what colorspace 1818d2c6a405SUma Shankar * source is trying to drive. 1819d2c6a405SUma Shankar * 18208806cd3aSGwan-gyeong Mun * Because between HDMI and DP have different colorspaces, 182145cf0e91SGwan-gyeong Mun * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and 182245cf0e91SGwan-gyeong Mun * drm_mode_create_dp_colorspace_property() is used for DP connector. 1823d2c6a405SUma Shankar */ 18248806cd3aSGwan-gyeong Mun 18258806cd3aSGwan-gyeong Mun /** 18268806cd3aSGwan-gyeong Mun * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property 18278806cd3aSGwan-gyeong Mun * @connector: connector to create the Colorspace property on. 18288806cd3aSGwan-gyeong Mun * 18298806cd3aSGwan-gyeong Mun * Called by a driver the first time it's needed, must be attached to desired 18308806cd3aSGwan-gyeong Mun * HDMI connectors. 18318806cd3aSGwan-gyeong Mun * 18328806cd3aSGwan-gyeong Mun * Returns: 183384e543bcSAntonio Borneo * Zero on success, negative errno on failure. 18348806cd3aSGwan-gyeong Mun */ 18358806cd3aSGwan-gyeong Mun int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector) 1836d2c6a405SUma Shankar { 1837d2c6a405SUma Shankar struct drm_device *dev = connector->dev; 1838d2c6a405SUma Shankar 18398806cd3aSGwan-gyeong Mun if (connector->colorspace_property) 18408806cd3aSGwan-gyeong Mun return 0; 18418806cd3aSGwan-gyeong Mun 18428806cd3aSGwan-gyeong Mun connector->colorspace_property = 18438806cd3aSGwan-gyeong Mun drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace", 1844d2c6a405SUma Shankar hdmi_colorspaces, 1845d2c6a405SUma Shankar ARRAY_SIZE(hdmi_colorspaces)); 18468806cd3aSGwan-gyeong Mun 18478806cd3aSGwan-gyeong Mun if (!connector->colorspace_property) 1848d2c6a405SUma Shankar return -ENOMEM; 1849d2c6a405SUma Shankar 1850d2c6a405SUma Shankar return 0; 1851d2c6a405SUma Shankar } 18528806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property); 1853d2c6a405SUma Shankar 1854d2c6a405SUma Shankar /** 185545cf0e91SGwan-gyeong Mun * drm_mode_create_dp_colorspace_property - create dp colorspace property 185645cf0e91SGwan-gyeong Mun * @connector: connector to create the Colorspace property on. 185745cf0e91SGwan-gyeong Mun * 185845cf0e91SGwan-gyeong Mun * Called by a driver the first time it's needed, must be attached to desired 185945cf0e91SGwan-gyeong Mun * DP connectors. 186045cf0e91SGwan-gyeong Mun * 186145cf0e91SGwan-gyeong Mun * Returns: 186284e543bcSAntonio Borneo * Zero on success, negative errno on failure. 186345cf0e91SGwan-gyeong Mun */ 186445cf0e91SGwan-gyeong Mun int drm_mode_create_dp_colorspace_property(struct drm_connector *connector) 186545cf0e91SGwan-gyeong Mun { 186645cf0e91SGwan-gyeong Mun struct drm_device *dev = connector->dev; 186745cf0e91SGwan-gyeong Mun 186845cf0e91SGwan-gyeong Mun if (connector->colorspace_property) 186945cf0e91SGwan-gyeong Mun return 0; 187045cf0e91SGwan-gyeong Mun 187145cf0e91SGwan-gyeong Mun connector->colorspace_property = 187245cf0e91SGwan-gyeong Mun drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace", 187345cf0e91SGwan-gyeong Mun dp_colorspaces, 187445cf0e91SGwan-gyeong Mun ARRAY_SIZE(dp_colorspaces)); 187545cf0e91SGwan-gyeong Mun 187645cf0e91SGwan-gyeong Mun if (!connector->colorspace_property) 187745cf0e91SGwan-gyeong Mun return -ENOMEM; 187845cf0e91SGwan-gyeong Mun 187945cf0e91SGwan-gyeong Mun return 0; 188045cf0e91SGwan-gyeong Mun } 188145cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property); 188252217195SDaniel Vetter 188397e14fbeSDaniel Vetter /** 188452217195SDaniel Vetter * drm_mode_create_content_type_property - create content type property 188552217195SDaniel Vetter * @dev: DRM device 188697e14fbeSDaniel Vetter * 188752217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 188852217195SDaniel Vetter * connectors. 188952217195SDaniel Vetter * 189052217195SDaniel Vetter * Returns: 189152217195SDaniel Vetter * Zero on success, negative errno on failure. 189252217195SDaniel Vetter */ 189352217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev) 189452217195SDaniel Vetter { 189552217195SDaniel Vetter if (dev->mode_config.content_type_property) 189697e14fbeSDaniel Vetter return 0; 189752217195SDaniel Vetter 189852217195SDaniel Vetter dev->mode_config.content_type_property = 189952217195SDaniel Vetter drm_property_create_enum(dev, 0, "content type", 190052217195SDaniel Vetter drm_content_type_enum_list, 190152217195SDaniel Vetter ARRAY_SIZE(drm_content_type_enum_list)); 190252217195SDaniel Vetter 190352217195SDaniel Vetter if (dev->mode_config.content_type_property == NULL) 190452217195SDaniel Vetter return -ENOMEM; 190552217195SDaniel Vetter 190652217195SDaniel Vetter return 0; 190752217195SDaniel Vetter } 190852217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property); 190952217195SDaniel Vetter 191052217195SDaniel Vetter /** 191152217195SDaniel Vetter * drm_mode_create_suggested_offset_properties - create suggests offset properties 191252217195SDaniel Vetter * @dev: DRM device 191352217195SDaniel Vetter * 191484e543bcSAntonio Borneo * Create the suggested x/y offset property for connectors. 191552217195SDaniel Vetter */ 191652217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev) 191752217195SDaniel Vetter { 191852217195SDaniel Vetter if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) 191952217195SDaniel Vetter return 0; 192052217195SDaniel Vetter 192152217195SDaniel Vetter dev->mode_config.suggested_x_property = 192252217195SDaniel Vetter drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); 192352217195SDaniel Vetter 192452217195SDaniel Vetter dev->mode_config.suggested_y_property = 192552217195SDaniel Vetter drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); 192652217195SDaniel Vetter 192752217195SDaniel Vetter if (dev->mode_config.suggested_x_property == NULL || 192852217195SDaniel Vetter dev->mode_config.suggested_y_property == NULL) 192952217195SDaniel Vetter return -ENOMEM; 193052217195SDaniel Vetter return 0; 193152217195SDaniel Vetter } 193252217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); 193352217195SDaniel Vetter 193452217195SDaniel Vetter /** 193552217195SDaniel Vetter * drm_connector_set_path_property - set tile property on connector 193652217195SDaniel Vetter * @connector: connector to set property on. 193752217195SDaniel Vetter * @path: path to use for property; must not be NULL. 193852217195SDaniel Vetter * 193952217195SDaniel Vetter * This creates a property to expose to userspace to specify a 194052217195SDaniel Vetter * connector path. This is mainly used for DisplayPort MST where 194152217195SDaniel Vetter * connectors have a topology and we want to allow userspace to give 194252217195SDaniel Vetter * them more meaningful names. 194352217195SDaniel Vetter * 194452217195SDaniel Vetter * Returns: 194552217195SDaniel Vetter * Zero on success, negative errno on failure. 194652217195SDaniel Vetter */ 194752217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector, 194852217195SDaniel Vetter const char *path) 194952217195SDaniel Vetter { 195052217195SDaniel Vetter struct drm_device *dev = connector->dev; 195152217195SDaniel Vetter int ret; 195252217195SDaniel Vetter 195352217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 195452217195SDaniel Vetter &connector->path_blob_ptr, 195552217195SDaniel Vetter strlen(path) + 1, 195652217195SDaniel Vetter path, 195752217195SDaniel Vetter &connector->base, 195852217195SDaniel Vetter dev->mode_config.path_property); 195952217195SDaniel Vetter return ret; 196052217195SDaniel Vetter } 196152217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property); 196252217195SDaniel Vetter 196352217195SDaniel Vetter /** 196452217195SDaniel Vetter * drm_connector_set_tile_property - set tile property on connector 196552217195SDaniel Vetter * @connector: connector to set property on. 196652217195SDaniel Vetter * 196752217195SDaniel Vetter * This looks up the tile information for a connector, and creates a 196852217195SDaniel Vetter * property for userspace to parse if it exists. The property is of 196952217195SDaniel Vetter * the form of 8 integers using ':' as a separator. 19702de3a078SManasi Navare * This is used for dual port tiled displays with DisplayPort SST 19712de3a078SManasi Navare * or DisplayPort MST connectors. 197252217195SDaniel Vetter * 197352217195SDaniel Vetter * Returns: 197452217195SDaniel Vetter * Zero on success, errno on failure. 197552217195SDaniel Vetter */ 197652217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector) 197752217195SDaniel Vetter { 197852217195SDaniel Vetter struct drm_device *dev = connector->dev; 197952217195SDaniel Vetter char tile[256]; 198052217195SDaniel Vetter int ret; 198152217195SDaniel Vetter 198252217195SDaniel Vetter if (!connector->has_tile) { 198352217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 198452217195SDaniel Vetter &connector->tile_blob_ptr, 198552217195SDaniel Vetter 0, 198652217195SDaniel Vetter NULL, 198752217195SDaniel Vetter &connector->base, 198852217195SDaniel Vetter dev->mode_config.tile_property); 198952217195SDaniel Vetter return ret; 199052217195SDaniel Vetter } 199152217195SDaniel Vetter 199252217195SDaniel Vetter snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", 199352217195SDaniel Vetter connector->tile_group->id, connector->tile_is_single_monitor, 199452217195SDaniel Vetter connector->num_h_tile, connector->num_v_tile, 199552217195SDaniel Vetter connector->tile_h_loc, connector->tile_v_loc, 199652217195SDaniel Vetter connector->tile_h_size, connector->tile_v_size); 199752217195SDaniel Vetter 199852217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 199952217195SDaniel Vetter &connector->tile_blob_ptr, 200052217195SDaniel Vetter strlen(tile) + 1, 200152217195SDaniel Vetter tile, 200252217195SDaniel Vetter &connector->base, 200352217195SDaniel Vetter dev->mode_config.tile_property); 200452217195SDaniel Vetter return ret; 200552217195SDaniel Vetter } 200697e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property); 200752217195SDaniel Vetter 200852217195SDaniel Vetter /** 2009c555f023SDaniel Vetter * drm_connector_update_edid_property - update the edid property of a connector 201052217195SDaniel Vetter * @connector: drm connector 201152217195SDaniel Vetter * @edid: new value of the edid property 201252217195SDaniel Vetter * 201352217195SDaniel Vetter * This function creates a new blob modeset object and assigns its id to the 201452217195SDaniel Vetter * connector's edid property. 20152de3a078SManasi Navare * Since we also parse tile information from EDID's displayID block, we also 20162de3a078SManasi Navare * set the connector's tile property here. See drm_connector_set_tile_property() 20172de3a078SManasi Navare * for more details. 201852217195SDaniel Vetter * 201952217195SDaniel Vetter * Returns: 202052217195SDaniel Vetter * Zero on success, negative errno on failure. 202152217195SDaniel Vetter */ 2022c555f023SDaniel Vetter int drm_connector_update_edid_property(struct drm_connector *connector, 202352217195SDaniel Vetter const struct edid *edid) 202452217195SDaniel Vetter { 202552217195SDaniel Vetter struct drm_device *dev = connector->dev; 202652217195SDaniel Vetter size_t size = 0; 202752217195SDaniel Vetter int ret; 20285186421cSStanislav Lisovskiy const struct edid *old_edid; 202952217195SDaniel Vetter 203052217195SDaniel Vetter /* ignore requests to set edid when overridden */ 203152217195SDaniel Vetter if (connector->override_edid) 203252217195SDaniel Vetter return 0; 203352217195SDaniel Vetter 203452217195SDaniel Vetter if (edid) 203552217195SDaniel Vetter size = EDID_LENGTH * (1 + edid->extensions); 203652217195SDaniel Vetter 2037170178feSKeith Packard /* Set the display info, using edid if available, otherwise 203884e543bcSAntonio Borneo * resetting the values to defaults. This duplicates the work 2039170178feSKeith Packard * done in drm_add_edid_modes, but that function is not 2040170178feSKeith Packard * consistently called before this one in all drivers and the 2041170178feSKeith Packard * computation is cheap enough that it seems better to 2042170178feSKeith Packard * duplicate it rather than attempt to ensure some arbitrary 2043170178feSKeith Packard * ordering of calls. 2044170178feSKeith Packard */ 2045170178feSKeith Packard if (edid) 2046170178feSKeith Packard drm_add_display_info(connector, edid); 2047170178feSKeith Packard else 2048170178feSKeith Packard drm_reset_display_info(connector); 2049170178feSKeith Packard 2050092c367aSVille Syrjälä drm_update_tile_info(connector, edid); 2051092c367aSVille Syrjälä 20525186421cSStanislav Lisovskiy if (connector->edid_blob_ptr) { 20535186421cSStanislav Lisovskiy old_edid = (const struct edid *)connector->edid_blob_ptr->data; 20545186421cSStanislav Lisovskiy if (old_edid) { 20555186421cSStanislav Lisovskiy if (!drm_edid_are_equal(edid, old_edid)) { 20565186421cSStanislav Lisovskiy DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Edid was changed.\n", 20575186421cSStanislav Lisovskiy connector->base.id, connector->name); 20585186421cSStanislav Lisovskiy 20595186421cSStanislav Lisovskiy connector->epoch_counter += 1; 20605186421cSStanislav Lisovskiy DRM_DEBUG_KMS("Updating change counter to %llu\n", 20615186421cSStanislav Lisovskiy connector->epoch_counter); 20625186421cSStanislav Lisovskiy } 20635186421cSStanislav Lisovskiy } 20645186421cSStanislav Lisovskiy } 20655186421cSStanislav Lisovskiy 206666660d4cSDave Airlie drm_object_property_set_value(&connector->base, 206766660d4cSDave Airlie dev->mode_config.non_desktop_property, 206866660d4cSDave Airlie connector->display_info.non_desktop); 206966660d4cSDave Airlie 207052217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 207152217195SDaniel Vetter &connector->edid_blob_ptr, 207252217195SDaniel Vetter size, 207352217195SDaniel Vetter edid, 207452217195SDaniel Vetter &connector->base, 207552217195SDaniel Vetter dev->mode_config.edid_property); 20762de3a078SManasi Navare if (ret) 207752217195SDaniel Vetter return ret; 20782de3a078SManasi Navare return drm_connector_set_tile_property(connector); 207952217195SDaniel Vetter } 2080c555f023SDaniel Vetter EXPORT_SYMBOL(drm_connector_update_edid_property); 208152217195SDaniel Vetter 208240ee6fbeSManasi Navare /** 208397e14fbeSDaniel Vetter * drm_connector_set_link_status_property - Set link status property of a connector 208440ee6fbeSManasi Navare * @connector: drm connector 208540ee6fbeSManasi Navare * @link_status: new value of link status property (0: Good, 1: Bad) 208640ee6fbeSManasi Navare * 208740ee6fbeSManasi Navare * In usual working scenario, this link status property will always be set to 208840ee6fbeSManasi Navare * "GOOD". If something fails during or after a mode set, the kernel driver 208940ee6fbeSManasi Navare * may set this link status property to "BAD". The caller then needs to send a 209040ee6fbeSManasi Navare * hotplug uevent for userspace to re-check the valid modes through 209140ee6fbeSManasi Navare * GET_CONNECTOR_IOCTL and retry modeset. 209240ee6fbeSManasi Navare * 209340ee6fbeSManasi Navare * Note: Drivers cannot rely on userspace to support this property and 209440ee6fbeSManasi Navare * issue a modeset. As such, they may choose to handle issues (like 209540ee6fbeSManasi Navare * re-training a link) without userspace's intervention. 209640ee6fbeSManasi Navare * 209740ee6fbeSManasi Navare * The reason for adding this property is to handle link training failures, but 209840ee6fbeSManasi Navare * it is not limited to DP or link training. For example, if we implement 209940ee6fbeSManasi Navare * asynchronous setcrtc, this property can be used to report any failures in that. 210040ee6fbeSManasi Navare */ 210197e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector, 210240ee6fbeSManasi Navare uint64_t link_status) 210340ee6fbeSManasi Navare { 210440ee6fbeSManasi Navare struct drm_device *dev = connector->dev; 210540ee6fbeSManasi Navare 210640ee6fbeSManasi Navare drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 210740ee6fbeSManasi Navare connector->state->link_status = link_status; 210840ee6fbeSManasi Navare drm_modeset_unlock(&dev->mode_config.connection_mutex); 210940ee6fbeSManasi Navare } 211097e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property); 211140ee6fbeSManasi Navare 21128d70f395SHans de Goede /** 211347e22ff1SRadhakrishna Sripada * drm_connector_attach_max_bpc_property - attach "max bpc" property 211447e22ff1SRadhakrishna Sripada * @connector: connector to attach max bpc property on. 211547e22ff1SRadhakrishna Sripada * @min: The minimum bit depth supported by the connector. 211647e22ff1SRadhakrishna Sripada * @max: The maximum bit depth supported by the connector. 211747e22ff1SRadhakrishna Sripada * 211847e22ff1SRadhakrishna Sripada * This is used to add support for limiting the bit depth on a connector. 211947e22ff1SRadhakrishna Sripada * 212047e22ff1SRadhakrishna Sripada * Returns: 212147e22ff1SRadhakrishna Sripada * Zero on success, negative errno on failure. 212247e22ff1SRadhakrishna Sripada */ 212347e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector, 212447e22ff1SRadhakrishna Sripada int min, int max) 212547e22ff1SRadhakrishna Sripada { 212647e22ff1SRadhakrishna Sripada struct drm_device *dev = connector->dev; 212747e22ff1SRadhakrishna Sripada struct drm_property *prop; 212847e22ff1SRadhakrishna Sripada 212947e22ff1SRadhakrishna Sripada prop = connector->max_bpc_property; 213047e22ff1SRadhakrishna Sripada if (!prop) { 213147e22ff1SRadhakrishna Sripada prop = drm_property_create_range(dev, 0, "max bpc", min, max); 213247e22ff1SRadhakrishna Sripada if (!prop) 213347e22ff1SRadhakrishna Sripada return -ENOMEM; 213447e22ff1SRadhakrishna Sripada 213547e22ff1SRadhakrishna Sripada connector->max_bpc_property = prop; 213647e22ff1SRadhakrishna Sripada } 213747e22ff1SRadhakrishna Sripada 213847e22ff1SRadhakrishna Sripada drm_object_attach_property(&connector->base, prop, max); 213947e22ff1SRadhakrishna Sripada connector->state->max_requested_bpc = max; 214047e22ff1SRadhakrishna Sripada connector->state->max_bpc = max; 214147e22ff1SRadhakrishna Sripada 214247e22ff1SRadhakrishna Sripada return 0; 214347e22ff1SRadhakrishna Sripada } 214447e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property); 214547e22ff1SRadhakrishna Sripada 214647e22ff1SRadhakrishna Sripada /** 2147ba1b0f6cSNicholas Kazlauskas * drm_connector_set_vrr_capable_property - sets the variable refresh rate 2148ba1b0f6cSNicholas Kazlauskas * capable property for a connector 2149ba1b0f6cSNicholas Kazlauskas * @connector: drm connector 2150ba1b0f6cSNicholas Kazlauskas * @capable: True if the connector is variable refresh rate capable 2151ba1b0f6cSNicholas Kazlauskas * 2152ba1b0f6cSNicholas Kazlauskas * Should be used by atomic drivers to update the indicated support for 2153ba1b0f6cSNicholas Kazlauskas * variable refresh rate over a connector. 2154ba1b0f6cSNicholas Kazlauskas */ 2155ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property( 2156ba1b0f6cSNicholas Kazlauskas struct drm_connector *connector, bool capable) 2157ba1b0f6cSNicholas Kazlauskas { 2158ba1b0f6cSNicholas Kazlauskas drm_object_property_set_value(&connector->base, 2159ba1b0f6cSNicholas Kazlauskas connector->vrr_capable_property, 2160ba1b0f6cSNicholas Kazlauskas capable); 2161ba1b0f6cSNicholas Kazlauskas } 2162ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property); 2163ba1b0f6cSNicholas Kazlauskas 2164ba1b0f6cSNicholas Kazlauskas /** 216584e543bcSAntonio Borneo * drm_connector_set_panel_orientation - sets the connector's panel_orientation 216669654c63SDerek Basehore * @connector: connector for which to set the panel-orientation property. 216769654c63SDerek Basehore * @panel_orientation: drm_panel_orientation value to set 21688d70f395SHans de Goede * 216969654c63SDerek Basehore * This function sets the connector's panel_orientation and attaches 217069654c63SDerek Basehore * a "panel orientation" property to the connector. 21718d70f395SHans de Goede * 217269654c63SDerek Basehore * Calling this function on a connector where the panel_orientation has 217369654c63SDerek Basehore * already been set is a no-op (e.g. the orientation has been overridden with 217469654c63SDerek Basehore * a kernel commandline option). 217569654c63SDerek Basehore * 217669654c63SDerek Basehore * It is allowed to call this function with a panel_orientation of 217769654c63SDerek Basehore * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op. 21788d70f395SHans de Goede * 21798d70f395SHans de Goede * Returns: 21808d70f395SHans de Goede * Zero on success, negative errno on failure. 21818d70f395SHans de Goede */ 218269654c63SDerek Basehore int drm_connector_set_panel_orientation( 218369654c63SDerek Basehore struct drm_connector *connector, 218469654c63SDerek Basehore enum drm_panel_orientation panel_orientation) 21858d70f395SHans de Goede { 21868d70f395SHans de Goede struct drm_device *dev = connector->dev; 21878d70f395SHans de Goede struct drm_display_info *info = &connector->display_info; 21888d70f395SHans de Goede struct drm_property *prop; 21898d70f395SHans de Goede 219069654c63SDerek Basehore /* Already set? */ 219169654c63SDerek Basehore if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 21928d70f395SHans de Goede return 0; 21938d70f395SHans de Goede 219469654c63SDerek Basehore /* Don't attach the property if the orientation is unknown */ 219569654c63SDerek Basehore if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 219669654c63SDerek Basehore return 0; 219769654c63SDerek Basehore 219869654c63SDerek Basehore info->panel_orientation = panel_orientation; 219969654c63SDerek Basehore 22008d70f395SHans de Goede prop = dev->mode_config.panel_orientation_property; 22018d70f395SHans de Goede if (!prop) { 22028d70f395SHans de Goede prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 22038d70f395SHans de Goede "panel orientation", 22048d70f395SHans de Goede drm_panel_orientation_enum_list, 22058d70f395SHans de Goede ARRAY_SIZE(drm_panel_orientation_enum_list)); 22068d70f395SHans de Goede if (!prop) 22078d70f395SHans de Goede return -ENOMEM; 22088d70f395SHans de Goede 22098d70f395SHans de Goede dev->mode_config.panel_orientation_property = prop; 22108d70f395SHans de Goede } 22118d70f395SHans de Goede 22128d70f395SHans de Goede drm_object_attach_property(&connector->base, prop, 22138d70f395SHans de Goede info->panel_orientation); 22148d70f395SHans de Goede return 0; 22158d70f395SHans de Goede } 221669654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation); 221769654c63SDerek Basehore 221869654c63SDerek Basehore /** 221969654c63SDerek Basehore * drm_connector_set_panel_orientation_with_quirk - 222084e543bcSAntonio Borneo * set the connector's panel_orientation after checking for quirks 222169654c63SDerek Basehore * @connector: connector for which to init the panel-orientation property. 222269654c63SDerek Basehore * @panel_orientation: drm_panel_orientation value to set 222369654c63SDerek Basehore * @width: width in pixels of the panel, used for panel quirk detection 222469654c63SDerek Basehore * @height: height in pixels of the panel, used for panel quirk detection 222569654c63SDerek Basehore * 222669654c63SDerek Basehore * Like drm_connector_set_panel_orientation(), but with a check for platform 222769654c63SDerek Basehore * specific (e.g. DMI based) quirks overriding the passed in panel_orientation. 222869654c63SDerek Basehore * 222969654c63SDerek Basehore * Returns: 223069654c63SDerek Basehore * Zero on success, negative errno on failure. 223169654c63SDerek Basehore */ 223269654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk( 223369654c63SDerek Basehore struct drm_connector *connector, 223469654c63SDerek Basehore enum drm_panel_orientation panel_orientation, 223569654c63SDerek Basehore int width, int height) 223669654c63SDerek Basehore { 223769654c63SDerek Basehore int orientation_quirk; 223869654c63SDerek Basehore 223969654c63SDerek Basehore orientation_quirk = drm_get_panel_orientation_quirk(width, height); 224069654c63SDerek Basehore if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 224169654c63SDerek Basehore panel_orientation = orientation_quirk; 224269654c63SDerek Basehore 224369654c63SDerek Basehore return drm_connector_set_panel_orientation(connector, 224469654c63SDerek Basehore panel_orientation); 224569654c63SDerek Basehore } 224669654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk); 22478d70f395SHans de Goede 224897e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj, 224952217195SDaniel Vetter struct drm_property *property, 225052217195SDaniel Vetter uint64_t value) 225152217195SDaniel Vetter { 225252217195SDaniel Vetter int ret = -EINVAL; 225352217195SDaniel Vetter struct drm_connector *connector = obj_to_connector(obj); 225452217195SDaniel Vetter 225552217195SDaniel Vetter /* Do DPMS ourselves */ 225652217195SDaniel Vetter if (property == connector->dev->mode_config.dpms_property) { 225752217195SDaniel Vetter ret = (*connector->funcs->dpms)(connector, (int)value); 225852217195SDaniel Vetter } else if (connector->funcs->set_property) 225952217195SDaniel Vetter ret = connector->funcs->set_property(connector, property, value); 226052217195SDaniel Vetter 2261144a7999SDaniel Vetter if (!ret) 226252217195SDaniel Vetter drm_object_property_set_value(&connector->base, property, value); 226352217195SDaniel Vetter return ret; 226452217195SDaniel Vetter } 226552217195SDaniel Vetter 226697e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev, 226752217195SDaniel Vetter void *data, struct drm_file *file_priv) 226852217195SDaniel Vetter { 226952217195SDaniel Vetter struct drm_mode_connector_set_property *conn_set_prop = data; 227052217195SDaniel Vetter struct drm_mode_obj_set_property obj_set_prop = { 227152217195SDaniel Vetter .value = conn_set_prop->value, 227252217195SDaniel Vetter .prop_id = conn_set_prop->prop_id, 227352217195SDaniel Vetter .obj_id = conn_set_prop->connector_id, 227452217195SDaniel Vetter .obj_type = DRM_MODE_OBJECT_CONNECTOR 227552217195SDaniel Vetter }; 227652217195SDaniel Vetter 227752217195SDaniel Vetter /* It does all the locking and checking we need */ 227852217195SDaniel Vetter return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv); 227952217195SDaniel Vetter } 228052217195SDaniel Vetter 228152217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) 228252217195SDaniel Vetter { 228352217195SDaniel Vetter /* For atomic drivers only state objects are synchronously updated and 228452217195SDaniel Vetter * protected by modeset locks, so check those first. */ 228552217195SDaniel Vetter if (connector->state) 228652217195SDaniel Vetter return connector->state->best_encoder; 228752217195SDaniel Vetter return connector->encoder; 228852217195SDaniel Vetter } 228952217195SDaniel Vetter 2290c3ff0cdbSAnkit Nautiyal static bool 2291c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode, 2292c3ff0cdbSAnkit Nautiyal const struct list_head *export_list, 229352217195SDaniel Vetter const struct drm_file *file_priv) 229452217195SDaniel Vetter { 229552217195SDaniel Vetter /* 229652217195SDaniel Vetter * If user-space hasn't configured the driver to expose the stereo 3D 229752217195SDaniel Vetter * modes, don't expose them. 229852217195SDaniel Vetter */ 229952217195SDaniel Vetter if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) 230052217195SDaniel Vetter return false; 2301c3ff0cdbSAnkit Nautiyal /* 2302c3ff0cdbSAnkit Nautiyal * If user-space hasn't configured the driver to expose the modes 2303c3ff0cdbSAnkit Nautiyal * with aspect-ratio, don't expose them. However if such a mode 2304c3ff0cdbSAnkit Nautiyal * is unique, let it be exposed, but reset the aspect-ratio flags 2305c3ff0cdbSAnkit Nautiyal * while preparing the list of user-modes. 2306c3ff0cdbSAnkit Nautiyal */ 2307c3ff0cdbSAnkit Nautiyal if (!file_priv->aspect_ratio_allowed) { 2308c3ff0cdbSAnkit Nautiyal struct drm_display_mode *mode_itr; 2309c3ff0cdbSAnkit Nautiyal 2310c3ff0cdbSAnkit Nautiyal list_for_each_entry(mode_itr, export_list, export_head) 2311c3ff0cdbSAnkit Nautiyal if (drm_mode_match(mode_itr, mode, 2312c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_TIMINGS | 2313c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_CLOCK | 2314c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_FLAGS | 2315c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_3D_FLAGS)) 2316c3ff0cdbSAnkit Nautiyal return false; 2317c3ff0cdbSAnkit Nautiyal } 231852217195SDaniel Vetter 231952217195SDaniel Vetter return true; 232052217195SDaniel Vetter } 232152217195SDaniel Vetter 232252217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data, 232352217195SDaniel Vetter struct drm_file *file_priv) 232452217195SDaniel Vetter { 232552217195SDaniel Vetter struct drm_mode_get_connector *out_resp = data; 232652217195SDaniel Vetter struct drm_connector *connector; 232752217195SDaniel Vetter struct drm_encoder *encoder; 232852217195SDaniel Vetter struct drm_display_mode *mode; 232952217195SDaniel Vetter int mode_count = 0; 233052217195SDaniel Vetter int encoders_count = 0; 233152217195SDaniel Vetter int ret = 0; 233252217195SDaniel Vetter int copied = 0; 233352217195SDaniel Vetter struct drm_mode_modeinfo u_mode; 233452217195SDaniel Vetter struct drm_mode_modeinfo __user *mode_ptr; 233552217195SDaniel Vetter uint32_t __user *encoder_ptr; 2336c3ff0cdbSAnkit Nautiyal LIST_HEAD(export_list); 233752217195SDaniel Vetter 233852217195SDaniel Vetter if (!drm_core_check_feature(dev, DRIVER_MODESET)) 233969fdf420SChris Wilson return -EOPNOTSUPP; 234052217195SDaniel Vetter 234152217195SDaniel Vetter memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); 234252217195SDaniel Vetter 2343418da172SKeith Packard connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id); 234491eefc05SDaniel Vetter if (!connector) 234591eefc05SDaniel Vetter return -ENOENT; 234652217195SDaniel Vetter 234762afb4adSJosé Roberto de Souza encoders_count = hweight32(connector->possible_encoders); 234891eefc05SDaniel Vetter 234991eefc05SDaniel Vetter if ((out_resp->count_encoders >= encoders_count) && encoders_count) { 235091eefc05SDaniel Vetter copied = 0; 235191eefc05SDaniel Vetter encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); 235283aefbb8SVille Syrjälä 235362afb4adSJosé Roberto de Souza drm_connector_for_each_possible_encoder(connector, encoder) { 235483aefbb8SVille Syrjälä if (put_user(encoder->base.id, encoder_ptr + copied)) { 235591eefc05SDaniel Vetter ret = -EFAULT; 2356e94ac351SDaniel Vetter goto out; 235791eefc05SDaniel Vetter } 235891eefc05SDaniel Vetter copied++; 235991eefc05SDaniel Vetter } 236091eefc05SDaniel Vetter } 236191eefc05SDaniel Vetter out_resp->count_encoders = encoders_count; 236291eefc05SDaniel Vetter 236391eefc05SDaniel Vetter out_resp->connector_id = connector->base.id; 236491eefc05SDaniel Vetter out_resp->connector_type = connector->connector_type; 236591eefc05SDaniel Vetter out_resp->connector_type_id = connector->connector_type_id; 236691eefc05SDaniel Vetter 236791eefc05SDaniel Vetter mutex_lock(&dev->mode_config.mutex); 236891eefc05SDaniel Vetter if (out_resp->count_modes == 0) { 236991eefc05SDaniel Vetter connector->funcs->fill_modes(connector, 237091eefc05SDaniel Vetter dev->mode_config.max_width, 237191eefc05SDaniel Vetter dev->mode_config.max_height); 237291eefc05SDaniel Vetter } 237391eefc05SDaniel Vetter 237491eefc05SDaniel Vetter out_resp->mm_width = connector->display_info.width_mm; 237591eefc05SDaniel Vetter out_resp->mm_height = connector->display_info.height_mm; 237691eefc05SDaniel Vetter out_resp->subpixel = connector->display_info.subpixel_order; 237791eefc05SDaniel Vetter out_resp->connection = connector->status; 237891eefc05SDaniel Vetter 237991eefc05SDaniel Vetter /* delayed so we get modes regardless of pre-fill_modes state */ 238091eefc05SDaniel Vetter list_for_each_entry(mode, &connector->modes, head) 2381c3ff0cdbSAnkit Nautiyal if (drm_mode_expose_to_userspace(mode, &export_list, 2382c3ff0cdbSAnkit Nautiyal file_priv)) { 2383c3ff0cdbSAnkit Nautiyal list_add_tail(&mode->export_head, &export_list); 238491eefc05SDaniel Vetter mode_count++; 2385c3ff0cdbSAnkit Nautiyal } 238691eefc05SDaniel Vetter 238752217195SDaniel Vetter /* 238852217195SDaniel Vetter * This ioctl is called twice, once to determine how much space is 238952217195SDaniel Vetter * needed, and the 2nd time to fill it. 2390c3ff0cdbSAnkit Nautiyal * The modes that need to be exposed to the user are maintained in the 2391c3ff0cdbSAnkit Nautiyal * 'export_list'. When the ioctl is called first time to determine the, 2392c3ff0cdbSAnkit Nautiyal * space, the export_list gets filled, to find the no.of modes. In the 2393c3ff0cdbSAnkit Nautiyal * 2nd time, the user modes are filled, one by one from the export_list. 239452217195SDaniel Vetter */ 239552217195SDaniel Vetter if ((out_resp->count_modes >= mode_count) && mode_count) { 239652217195SDaniel Vetter copied = 0; 239752217195SDaniel Vetter mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; 2398c3ff0cdbSAnkit Nautiyal list_for_each_entry(mode, &export_list, export_head) { 239952217195SDaniel Vetter drm_mode_convert_to_umode(&u_mode, mode); 2400c3ff0cdbSAnkit Nautiyal /* 2401c3ff0cdbSAnkit Nautiyal * Reset aspect ratio flags of user-mode, if modes with 2402c3ff0cdbSAnkit Nautiyal * aspect-ratio are not supported. 2403c3ff0cdbSAnkit Nautiyal */ 2404c3ff0cdbSAnkit Nautiyal if (!file_priv->aspect_ratio_allowed) 2405c3ff0cdbSAnkit Nautiyal u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK; 240652217195SDaniel Vetter if (copy_to_user(mode_ptr + copied, 240752217195SDaniel Vetter &u_mode, sizeof(u_mode))) { 240852217195SDaniel Vetter ret = -EFAULT; 2409e94ac351SDaniel Vetter mutex_unlock(&dev->mode_config.mutex); 2410e94ac351SDaniel Vetter 241152217195SDaniel Vetter goto out; 241252217195SDaniel Vetter } 241352217195SDaniel Vetter copied++; 241452217195SDaniel Vetter } 241552217195SDaniel Vetter } 241652217195SDaniel Vetter out_resp->count_modes = mode_count; 241752217195SDaniel Vetter mutex_unlock(&dev->mode_config.mutex); 2418e94ac351SDaniel Vetter 2419e94ac351SDaniel Vetter drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 2420e94ac351SDaniel Vetter encoder = drm_connector_get_encoder(connector); 2421e94ac351SDaniel Vetter if (encoder) 2422e94ac351SDaniel Vetter out_resp->encoder_id = encoder->base.id; 2423e94ac351SDaniel Vetter else 2424e94ac351SDaniel Vetter out_resp->encoder_id = 0; 2425e94ac351SDaniel Vetter 2426e94ac351SDaniel Vetter /* Only grab properties after probing, to make sure EDID and other 2427e94ac351SDaniel Vetter * properties reflect the latest status. */ 2428e94ac351SDaniel Vetter ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic, 2429e94ac351SDaniel Vetter (uint32_t __user *)(unsigned long)(out_resp->props_ptr), 2430e94ac351SDaniel Vetter (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), 2431e94ac351SDaniel Vetter &out_resp->count_props); 2432e94ac351SDaniel Vetter drm_modeset_unlock(&dev->mode_config.connection_mutex); 2433e94ac351SDaniel Vetter 2434e94ac351SDaniel Vetter out: 2435ad093607SThierry Reding drm_connector_put(connector); 243652217195SDaniel Vetter 243752217195SDaniel Vetter return ret; 243852217195SDaniel Vetter } 243952217195SDaniel Vetter 24409498c19bSDaniel Vetter 24419498c19bSDaniel Vetter /** 24429498c19bSDaniel Vetter * DOC: Tile group 24439498c19bSDaniel Vetter * 24449498c19bSDaniel Vetter * Tile groups are used to represent tiled monitors with a unique integer 24459498c19bSDaniel Vetter * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle, 24469498c19bSDaniel Vetter * we store this in a tile group, so we have a common identifier for all tiles 24479498c19bSDaniel Vetter * in a monitor group. The property is called "TILE". Drivers can manage tile 24489498c19bSDaniel Vetter * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and 24499498c19bSDaniel Vetter * drm_mode_get_tile_group(). But this is only needed for internal panels where 24509498c19bSDaniel Vetter * the tile group information is exposed through a non-standard way. 24519498c19bSDaniel Vetter */ 24529498c19bSDaniel Vetter 24539498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref) 24549498c19bSDaniel Vetter { 24559498c19bSDaniel Vetter struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); 24569498c19bSDaniel Vetter struct drm_device *dev = tg->dev; 2457948de842SSuraj Upadhyay 24589498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 24599498c19bSDaniel Vetter idr_remove(&dev->mode_config.tile_idr, tg->id); 24609498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 24619498c19bSDaniel Vetter kfree(tg); 24629498c19bSDaniel Vetter } 24639498c19bSDaniel Vetter 24649498c19bSDaniel Vetter /** 24659498c19bSDaniel Vetter * drm_mode_put_tile_group - drop a reference to a tile group. 24669498c19bSDaniel Vetter * @dev: DRM device 24679498c19bSDaniel Vetter * @tg: tile group to drop reference to. 24689498c19bSDaniel Vetter * 24699498c19bSDaniel Vetter * drop reference to tile group and free if 0. 24709498c19bSDaniel Vetter */ 24719498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev, 24729498c19bSDaniel Vetter struct drm_tile_group *tg) 24739498c19bSDaniel Vetter { 24749498c19bSDaniel Vetter kref_put(&tg->refcount, drm_tile_group_free); 24759498c19bSDaniel Vetter } 24769498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group); 24779498c19bSDaniel Vetter 24789498c19bSDaniel Vetter /** 24799498c19bSDaniel Vetter * drm_mode_get_tile_group - get a reference to an existing tile group 24809498c19bSDaniel Vetter * @dev: DRM device 24819498c19bSDaniel Vetter * @topology: 8-bytes unique per monitor. 24829498c19bSDaniel Vetter * 24839498c19bSDaniel Vetter * Use the unique bytes to get a reference to an existing tile group. 24849498c19bSDaniel Vetter * 24859498c19bSDaniel Vetter * RETURNS: 24869498c19bSDaniel Vetter * tile group or NULL if not found. 24879498c19bSDaniel Vetter */ 24889498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 2489267ea759SVille Syrjälä const char topology[8]) 24909498c19bSDaniel Vetter { 24919498c19bSDaniel Vetter struct drm_tile_group *tg; 24929498c19bSDaniel Vetter int id; 2493948de842SSuraj Upadhyay 24949498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 24959498c19bSDaniel Vetter idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { 24969498c19bSDaniel Vetter if (!memcmp(tg->group_data, topology, 8)) { 24979498c19bSDaniel Vetter if (!kref_get_unless_zero(&tg->refcount)) 24989498c19bSDaniel Vetter tg = NULL; 24999498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 25009498c19bSDaniel Vetter return tg; 25019498c19bSDaniel Vetter } 25029498c19bSDaniel Vetter } 25039498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 25049498c19bSDaniel Vetter return NULL; 25059498c19bSDaniel Vetter } 25069498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group); 25079498c19bSDaniel Vetter 25089498c19bSDaniel Vetter /** 25099498c19bSDaniel Vetter * drm_mode_create_tile_group - create a tile group from a displayid description 25109498c19bSDaniel Vetter * @dev: DRM device 25119498c19bSDaniel Vetter * @topology: 8-bytes unique per monitor. 25129498c19bSDaniel Vetter * 25139498c19bSDaniel Vetter * Create a tile group for the unique monitor, and get a unique 25149498c19bSDaniel Vetter * identifier for the tile group. 25159498c19bSDaniel Vetter * 25169498c19bSDaniel Vetter * RETURNS: 2517705c8160SDan Carpenter * new tile group or NULL. 25189498c19bSDaniel Vetter */ 25199498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 2520267ea759SVille Syrjälä const char topology[8]) 25219498c19bSDaniel Vetter { 25229498c19bSDaniel Vetter struct drm_tile_group *tg; 25239498c19bSDaniel Vetter int ret; 25249498c19bSDaniel Vetter 25259498c19bSDaniel Vetter tg = kzalloc(sizeof(*tg), GFP_KERNEL); 25269498c19bSDaniel Vetter if (!tg) 2527705c8160SDan Carpenter return NULL; 25289498c19bSDaniel Vetter 25299498c19bSDaniel Vetter kref_init(&tg->refcount); 25309498c19bSDaniel Vetter memcpy(tg->group_data, topology, 8); 25319498c19bSDaniel Vetter tg->dev = dev; 25329498c19bSDaniel Vetter 25339498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 25349498c19bSDaniel Vetter ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); 25359498c19bSDaniel Vetter if (ret >= 0) { 25369498c19bSDaniel Vetter tg->id = ret; 25379498c19bSDaniel Vetter } else { 25389498c19bSDaniel Vetter kfree(tg); 2539705c8160SDan Carpenter tg = NULL; 25409498c19bSDaniel Vetter } 25419498c19bSDaniel Vetter 25429498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 25439498c19bSDaniel Vetter return tg; 25449498c19bSDaniel Vetter } 25459498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group); 2546