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> 3099f45e32SDaniel Vetter 3199f45e32SDaniel Vetter #include <linux/uaccess.h> 3252217195SDaniel Vetter 3352217195SDaniel Vetter #include "drm_crtc_internal.h" 3452217195SDaniel Vetter #include "drm_internal.h" 3552217195SDaniel Vetter 36ae2a6da8SDaniel Vetter /** 37ae2a6da8SDaniel Vetter * DOC: overview 38ae2a6da8SDaniel Vetter * 39ae2a6da8SDaniel Vetter * In DRM connectors are the general abstraction for display sinks, and include 40*84e543bcSAntonio Borneo * also fixed panels or anything else that can display pixels in some form. As 41ae2a6da8SDaniel Vetter * opposed to all other KMS objects representing hardware (like CRTC, encoder or 42ae2a6da8SDaniel Vetter * plane abstractions) connectors can be hotplugged and unplugged at runtime. 43ad093607SThierry Reding * Hence they are reference-counted using drm_connector_get() and 44ad093607SThierry Reding * drm_connector_put(). 45ae2a6da8SDaniel Vetter * 46d574528aSDaniel Vetter * KMS driver must create, initialize, register and attach at a &struct 47d574528aSDaniel Vetter * drm_connector for each such sink. The instance is created as other KMS 48aec97460SDaniel Vetter * objects and initialized by setting the following fields. The connector is 49aec97460SDaniel Vetter * initialized with a call to drm_connector_init() with a pointer to the 50aec97460SDaniel Vetter * &struct drm_connector_funcs and a connector type, and then exposed to 51aec97460SDaniel Vetter * userspace with a call to drm_connector_register(). 52ae2a6da8SDaniel Vetter * 53ae2a6da8SDaniel Vetter * Connectors must be attached to an encoder to be used. For devices that map 54ae2a6da8SDaniel Vetter * connectors to encoders 1:1, the connector should be attached at 55cde4c44dSDaniel Vetter * initialization time with a call to drm_connector_attach_encoder(). The 56d574528aSDaniel Vetter * driver must also set the &drm_connector.encoder field to point to the 57ae2a6da8SDaniel Vetter * attached encoder. 58ae2a6da8SDaniel Vetter * 59ae2a6da8SDaniel Vetter * For connectors which are not fixed (like built-in panels) the driver needs to 60ae2a6da8SDaniel Vetter * support hotplug notifications. The simplest way to do that is by using the 61ae2a6da8SDaniel Vetter * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have 62ae2a6da8SDaniel Vetter * hardware support for hotplug interrupts. Connectors with hardware hotplug 63ae2a6da8SDaniel Vetter * support can instead use e.g. drm_helper_hpd_irq_event(). 64ae2a6da8SDaniel Vetter */ 65ae2a6da8SDaniel Vetter 6652217195SDaniel Vetter struct drm_conn_prop_enum_list { 6752217195SDaniel Vetter int type; 6852217195SDaniel Vetter const char *name; 6952217195SDaniel Vetter struct ida ida; 7052217195SDaniel Vetter }; 7152217195SDaniel Vetter 7252217195SDaniel Vetter /* 7352217195SDaniel Vetter * Connector and encoder types. 7452217195SDaniel Vetter */ 7552217195SDaniel Vetter static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { 7652217195SDaniel Vetter { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, 7752217195SDaniel Vetter { DRM_MODE_CONNECTOR_VGA, "VGA" }, 7852217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, 7952217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, 8052217195SDaniel Vetter { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, 8152217195SDaniel Vetter { DRM_MODE_CONNECTOR_Composite, "Composite" }, 8252217195SDaniel Vetter { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, 8352217195SDaniel Vetter { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, 8452217195SDaniel Vetter { DRM_MODE_CONNECTOR_Component, "Component" }, 8552217195SDaniel Vetter { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, 8652217195SDaniel Vetter { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, 8752217195SDaniel Vetter { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, 8852217195SDaniel Vetter { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, 8952217195SDaniel Vetter { DRM_MODE_CONNECTOR_TV, "TV" }, 9052217195SDaniel Vetter { DRM_MODE_CONNECTOR_eDP, "eDP" }, 9152217195SDaniel Vetter { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, 9252217195SDaniel Vetter { DRM_MODE_CONNECTOR_DSI, "DSI" }, 9352217195SDaniel Vetter { DRM_MODE_CONNECTOR_DPI, "DPI" }, 94935774cdSBrian Starkey { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, 95fc06bf1dSNoralf Trønnes { DRM_MODE_CONNECTOR_SPI, "SPI" }, 9652217195SDaniel Vetter }; 9752217195SDaniel Vetter 9852217195SDaniel Vetter void drm_connector_ida_init(void) 9952217195SDaniel Vetter { 10052217195SDaniel Vetter int i; 10152217195SDaniel Vetter 10252217195SDaniel Vetter for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 10352217195SDaniel Vetter ida_init(&drm_connector_enum_list[i].ida); 10452217195SDaniel Vetter } 10552217195SDaniel Vetter 10652217195SDaniel Vetter void drm_connector_ida_destroy(void) 10752217195SDaniel Vetter { 10852217195SDaniel Vetter int i; 10952217195SDaniel Vetter 11052217195SDaniel Vetter for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 11152217195SDaniel Vetter ida_destroy(&drm_connector_enum_list[i].ida); 11252217195SDaniel Vetter } 11352217195SDaniel Vetter 11452217195SDaniel Vetter /** 115b35f90f2SLaurent Pinchart * drm_get_connector_type_name - return a string for connector type 116b35f90f2SLaurent Pinchart * @type: The connector type (DRM_MODE_CONNECTOR_*) 117b35f90f2SLaurent Pinchart * 118b35f90f2SLaurent Pinchart * Returns: the name of the connector type, or NULL if the type is not valid. 119b35f90f2SLaurent Pinchart */ 120b35f90f2SLaurent Pinchart const char *drm_get_connector_type_name(unsigned int type) 121b35f90f2SLaurent Pinchart { 122b35f90f2SLaurent Pinchart if (type < ARRAY_SIZE(drm_connector_enum_list)) 123b35f90f2SLaurent Pinchart return drm_connector_enum_list[type].name; 124b35f90f2SLaurent Pinchart 125b35f90f2SLaurent Pinchart return NULL; 126b35f90f2SLaurent Pinchart } 127b35f90f2SLaurent Pinchart EXPORT_SYMBOL(drm_get_connector_type_name); 128b35f90f2SLaurent Pinchart 129b35f90f2SLaurent Pinchart /** 13052217195SDaniel Vetter * drm_connector_get_cmdline_mode - reads the user's cmdline mode 131*84e543bcSAntonio Borneo * @connector: connector to query 13252217195SDaniel Vetter * 133ae2a6da8SDaniel Vetter * The kernel supports per-connector configuration of its consoles through 13452217195SDaniel Vetter * use of the video= parameter. This function parses that option and 13552217195SDaniel Vetter * extracts the user's specified mode (or enable/disable status) for a 13652217195SDaniel Vetter * particular connector. This is typically only used during the early fbdev 13752217195SDaniel Vetter * setup. 13852217195SDaniel Vetter */ 13952217195SDaniel Vetter static void drm_connector_get_cmdline_mode(struct drm_connector *connector) 14052217195SDaniel Vetter { 14152217195SDaniel Vetter struct drm_cmdline_mode *mode = &connector->cmdline_mode; 14252217195SDaniel Vetter char *option = NULL; 14352217195SDaniel Vetter 14452217195SDaniel Vetter if (fb_get_options(connector->name, &option)) 14552217195SDaniel Vetter return; 14652217195SDaniel Vetter 14752217195SDaniel Vetter if (!drm_mode_parse_command_line_for_connector(option, 14852217195SDaniel Vetter connector, 14952217195SDaniel Vetter mode)) 15052217195SDaniel Vetter return; 15152217195SDaniel Vetter 15252217195SDaniel Vetter if (mode->force) { 1536140cf20SJani Nikula DRM_INFO("forcing %s connector %s\n", connector->name, 1546140cf20SJani Nikula drm_get_connector_force_name(mode->force)); 15552217195SDaniel Vetter connector->force = mode->force; 15652217195SDaniel Vetter } 15752217195SDaniel Vetter 1580980939dSHans de Goede if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) { 1590980939dSHans de Goede DRM_INFO("cmdline forces connector %s panel_orientation to %d\n", 1600980939dSHans de Goede connector->name, mode->panel_orientation); 1610980939dSHans de Goede drm_connector_set_panel_orientation(connector, 1620980939dSHans de Goede mode->panel_orientation); 1630980939dSHans de Goede } 1640980939dSHans de Goede 1653aeeb13dSMaxime Ripard DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n", 16650b0946dSMaxime Ripard connector->name, mode->name, 16752217195SDaniel Vetter mode->xres, mode->yres, 16852217195SDaniel Vetter mode->refresh_specified ? mode->refresh : 60, 16952217195SDaniel Vetter mode->rb ? " reduced blanking" : "", 17052217195SDaniel Vetter mode->margins ? " with margins" : "", 17152217195SDaniel Vetter mode->interlace ? " interlaced" : ""); 17252217195SDaniel Vetter } 17352217195SDaniel Vetter 17452217195SDaniel Vetter static void drm_connector_free(struct kref *kref) 17552217195SDaniel Vetter { 17652217195SDaniel Vetter struct drm_connector *connector = 17752217195SDaniel Vetter container_of(kref, struct drm_connector, base.refcount); 17852217195SDaniel Vetter struct drm_device *dev = connector->dev; 17952217195SDaniel Vetter 18052217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 18152217195SDaniel Vetter connector->funcs->destroy(connector); 18252217195SDaniel Vetter } 18352217195SDaniel Vetter 184ea497bb9SDaniel Vetter void drm_connector_free_work_fn(struct work_struct *work) 185a703c550SDaniel Vetter { 186ea497bb9SDaniel Vetter struct drm_connector *connector, *n; 187ea497bb9SDaniel Vetter struct drm_device *dev = 188ea497bb9SDaniel Vetter container_of(work, struct drm_device, mode_config.connector_free_work); 189ea497bb9SDaniel Vetter struct drm_mode_config *config = &dev->mode_config; 190ea497bb9SDaniel Vetter unsigned long flags; 191ea497bb9SDaniel Vetter struct llist_node *freed; 192a703c550SDaniel Vetter 193ea497bb9SDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 194ea497bb9SDaniel Vetter freed = llist_del_all(&config->connector_free_list); 195ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 196ea497bb9SDaniel Vetter 197ea497bb9SDaniel Vetter llist_for_each_entry_safe(connector, n, freed, free_node) { 198a703c550SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 199a703c550SDaniel Vetter connector->funcs->destroy(connector); 200a703c550SDaniel Vetter } 201ea497bb9SDaniel Vetter } 202a703c550SDaniel Vetter 20352217195SDaniel Vetter /** 20452217195SDaniel Vetter * drm_connector_init - Init a preallocated connector 20552217195SDaniel Vetter * @dev: DRM device 20652217195SDaniel Vetter * @connector: the connector to init 20752217195SDaniel Vetter * @funcs: callbacks for this connector 20852217195SDaniel Vetter * @connector_type: user visible type of the connector 20952217195SDaniel Vetter * 21052217195SDaniel Vetter * Initialises a preallocated connector. Connectors should be 21152217195SDaniel Vetter * subclassed as part of driver connector objects. 21252217195SDaniel Vetter * 21352217195SDaniel Vetter * Returns: 21452217195SDaniel Vetter * Zero on success, error code on failure. 21552217195SDaniel Vetter */ 21652217195SDaniel Vetter int drm_connector_init(struct drm_device *dev, 21752217195SDaniel Vetter struct drm_connector *connector, 21852217195SDaniel Vetter const struct drm_connector_funcs *funcs, 21952217195SDaniel Vetter int connector_type) 22052217195SDaniel Vetter { 22152217195SDaniel Vetter struct drm_mode_config *config = &dev->mode_config; 22252217195SDaniel Vetter int ret; 22352217195SDaniel Vetter struct ida *connector_ida = 22452217195SDaniel Vetter &drm_connector_enum_list[connector_type].ida; 22552217195SDaniel Vetter 226ba1f665fSHaneen Mohammed WARN_ON(drm_drv_uses_atomic_modeset(dev) && 227ba1f665fSHaneen Mohammed (!funcs->atomic_destroy_state || 228ba1f665fSHaneen Mohammed !funcs->atomic_duplicate_state)); 229ba1f665fSHaneen Mohammed 2302135ea7aSThierry Reding ret = __drm_mode_object_add(dev, &connector->base, 23152217195SDaniel Vetter DRM_MODE_OBJECT_CONNECTOR, 23252217195SDaniel Vetter false, drm_connector_free); 23352217195SDaniel Vetter if (ret) 234613051daSDaniel Vetter return ret; 23552217195SDaniel Vetter 23652217195SDaniel Vetter connector->base.properties = &connector->properties; 23752217195SDaniel Vetter connector->dev = dev; 23852217195SDaniel Vetter connector->funcs = funcs; 23952217195SDaniel Vetter 2402a8d3eacSVille Syrjälä /* connector index is used with 32bit bitmasks */ 2412a8d3eacSVille Syrjälä ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL); 2422a8d3eacSVille Syrjälä if (ret < 0) { 2432a8d3eacSVille Syrjälä DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n", 2442a8d3eacSVille Syrjälä drm_connector_enum_list[connector_type].name, 2452a8d3eacSVille Syrjälä ret); 24652217195SDaniel Vetter goto out_put; 2472a8d3eacSVille Syrjälä } 24852217195SDaniel Vetter connector->index = ret; 24952217195SDaniel Vetter ret = 0; 25052217195SDaniel Vetter 25152217195SDaniel Vetter connector->connector_type = connector_type; 25252217195SDaniel Vetter connector->connector_type_id = 25352217195SDaniel Vetter ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); 25452217195SDaniel Vetter if (connector->connector_type_id < 0) { 25552217195SDaniel Vetter ret = connector->connector_type_id; 25652217195SDaniel Vetter goto out_put_id; 25752217195SDaniel Vetter } 25852217195SDaniel Vetter connector->name = 25952217195SDaniel Vetter kasprintf(GFP_KERNEL, "%s-%d", 26052217195SDaniel Vetter drm_connector_enum_list[connector_type].name, 26152217195SDaniel Vetter connector->connector_type_id); 26252217195SDaniel Vetter if (!connector->name) { 26352217195SDaniel Vetter ret = -ENOMEM; 26452217195SDaniel Vetter goto out_put_type_id; 26552217195SDaniel Vetter } 26652217195SDaniel Vetter 26752217195SDaniel Vetter INIT_LIST_HEAD(&connector->probed_modes); 26852217195SDaniel Vetter INIT_LIST_HEAD(&connector->modes); 269e73ab00eSDaniel Vetter mutex_init(&connector->mutex); 27052217195SDaniel Vetter connector->edid_blob_ptr = NULL; 2712de3a078SManasi Navare connector->tile_blob_ptr = NULL; 27252217195SDaniel Vetter connector->status = connector_status_unknown; 2738d70f395SHans de Goede connector->display_info.panel_orientation = 2748d70f395SHans de Goede DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 27552217195SDaniel Vetter 27652217195SDaniel Vetter drm_connector_get_cmdline_mode(connector); 27752217195SDaniel Vetter 27852217195SDaniel Vetter /* We should add connectors at the end to avoid upsetting the connector 27952217195SDaniel Vetter * index too much. */ 280613051daSDaniel Vetter spin_lock_irq(&config->connector_list_lock); 28152217195SDaniel Vetter list_add_tail(&connector->head, &config->connector_list); 28252217195SDaniel Vetter config->num_connector++; 283613051daSDaniel Vetter spin_unlock_irq(&config->connector_list_lock); 28452217195SDaniel Vetter 285935774cdSBrian Starkey if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL && 286935774cdSBrian Starkey connector_type != DRM_MODE_CONNECTOR_WRITEBACK) 2876b7e2d5cSGerd Hoffmann drm_connector_attach_edid_property(connector); 28852217195SDaniel Vetter 28952217195SDaniel Vetter drm_object_attach_property(&connector->base, 29052217195SDaniel Vetter config->dpms_property, 0); 29152217195SDaniel Vetter 29240ee6fbeSManasi Navare drm_object_attach_property(&connector->base, 29340ee6fbeSManasi Navare config->link_status_property, 29440ee6fbeSManasi Navare 0); 29540ee6fbeSManasi Navare 29666660d4cSDave Airlie drm_object_attach_property(&connector->base, 29766660d4cSDave Airlie config->non_desktop_property, 29866660d4cSDave Airlie 0); 2992de3a078SManasi Navare drm_object_attach_property(&connector->base, 3002de3a078SManasi Navare config->tile_property, 3012de3a078SManasi Navare 0); 30266660d4cSDave Airlie 30352217195SDaniel Vetter if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 30452217195SDaniel Vetter drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); 30552217195SDaniel Vetter } 30652217195SDaniel Vetter 30752217195SDaniel Vetter connector->debugfs_entry = NULL; 30852217195SDaniel Vetter out_put_type_id: 30952217195SDaniel Vetter if (ret) 310587680c1SChristophe JAILLET ida_simple_remove(connector_ida, connector->connector_type_id); 31152217195SDaniel Vetter out_put_id: 31252217195SDaniel Vetter if (ret) 313587680c1SChristophe JAILLET ida_simple_remove(&config->connector_ida, connector->index); 31452217195SDaniel Vetter out_put: 31552217195SDaniel Vetter if (ret) 31652217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 31752217195SDaniel Vetter 31852217195SDaniel Vetter return ret; 31952217195SDaniel Vetter } 32052217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_init); 32152217195SDaniel Vetter 32252217195SDaniel Vetter /** 323100163dfSAndrzej Pietrasiewicz * drm_connector_init_with_ddc - Init a preallocated connector 324100163dfSAndrzej Pietrasiewicz * @dev: DRM device 325100163dfSAndrzej Pietrasiewicz * @connector: the connector to init 326100163dfSAndrzej Pietrasiewicz * @funcs: callbacks for this connector 327100163dfSAndrzej Pietrasiewicz * @connector_type: user visible type of the connector 328100163dfSAndrzej Pietrasiewicz * @ddc: pointer to the associated ddc adapter 329100163dfSAndrzej Pietrasiewicz * 330100163dfSAndrzej Pietrasiewicz * Initialises a preallocated connector. Connectors should be 331100163dfSAndrzej Pietrasiewicz * subclassed as part of driver connector objects. 332100163dfSAndrzej Pietrasiewicz * 333100163dfSAndrzej Pietrasiewicz * Ensures that the ddc field of the connector is correctly set. 334100163dfSAndrzej Pietrasiewicz * 335100163dfSAndrzej Pietrasiewicz * Returns: 336100163dfSAndrzej Pietrasiewicz * Zero on success, error code on failure. 337100163dfSAndrzej Pietrasiewicz */ 338100163dfSAndrzej Pietrasiewicz int drm_connector_init_with_ddc(struct drm_device *dev, 339100163dfSAndrzej Pietrasiewicz struct drm_connector *connector, 340100163dfSAndrzej Pietrasiewicz const struct drm_connector_funcs *funcs, 341100163dfSAndrzej Pietrasiewicz int connector_type, 342100163dfSAndrzej Pietrasiewicz struct i2c_adapter *ddc) 343100163dfSAndrzej Pietrasiewicz { 344100163dfSAndrzej Pietrasiewicz int ret; 345100163dfSAndrzej Pietrasiewicz 346100163dfSAndrzej Pietrasiewicz ret = drm_connector_init(dev, connector, funcs, connector_type); 347100163dfSAndrzej Pietrasiewicz if (ret) 348100163dfSAndrzej Pietrasiewicz return ret; 349100163dfSAndrzej Pietrasiewicz 350100163dfSAndrzej Pietrasiewicz /* provide ddc symlink in sysfs */ 351100163dfSAndrzej Pietrasiewicz connector->ddc = ddc; 352100163dfSAndrzej Pietrasiewicz 353100163dfSAndrzej Pietrasiewicz return ret; 354100163dfSAndrzej Pietrasiewicz } 355100163dfSAndrzej Pietrasiewicz EXPORT_SYMBOL(drm_connector_init_with_ddc); 356100163dfSAndrzej Pietrasiewicz 357100163dfSAndrzej Pietrasiewicz /** 3586b7e2d5cSGerd Hoffmann * drm_connector_attach_edid_property - attach edid property. 3596b7e2d5cSGerd Hoffmann * @connector: the connector 3606b7e2d5cSGerd Hoffmann * 3616b7e2d5cSGerd Hoffmann * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a 3626b7e2d5cSGerd Hoffmann * edid property attached by default. This function can be used to 3636b7e2d5cSGerd Hoffmann * explicitly enable the edid property in these cases. 3646b7e2d5cSGerd Hoffmann */ 3656b7e2d5cSGerd Hoffmann void drm_connector_attach_edid_property(struct drm_connector *connector) 3666b7e2d5cSGerd Hoffmann { 3676b7e2d5cSGerd Hoffmann struct drm_mode_config *config = &connector->dev->mode_config; 3686b7e2d5cSGerd Hoffmann 3696b7e2d5cSGerd Hoffmann drm_object_attach_property(&connector->base, 3706b7e2d5cSGerd Hoffmann config->edid_property, 3716b7e2d5cSGerd Hoffmann 0); 3726b7e2d5cSGerd Hoffmann } 3736b7e2d5cSGerd Hoffmann EXPORT_SYMBOL(drm_connector_attach_edid_property); 3746b7e2d5cSGerd Hoffmann 3756b7e2d5cSGerd Hoffmann /** 376cde4c44dSDaniel Vetter * drm_connector_attach_encoder - attach a connector to an encoder 37752217195SDaniel Vetter * @connector: connector to attach 37852217195SDaniel Vetter * @encoder: encoder to attach @connector to 37952217195SDaniel Vetter * 38052217195SDaniel Vetter * This function links up a connector to an encoder. Note that the routing 38152217195SDaniel Vetter * restrictions between encoders and crtcs are exposed to userspace through the 38252217195SDaniel Vetter * possible_clones and possible_crtcs bitmasks. 38352217195SDaniel Vetter * 38452217195SDaniel Vetter * Returns: 38552217195SDaniel Vetter * Zero on success, negative errno on failure. 38652217195SDaniel Vetter */ 387cde4c44dSDaniel Vetter int drm_connector_attach_encoder(struct drm_connector *connector, 38852217195SDaniel Vetter struct drm_encoder *encoder) 38952217195SDaniel Vetter { 39052217195SDaniel Vetter /* 39152217195SDaniel Vetter * In the past, drivers have attempted to model the static association 39252217195SDaniel Vetter * of connector to encoder in simple connector/encoder devices using a 39352217195SDaniel Vetter * direct assignment of connector->encoder = encoder. This connection 39452217195SDaniel Vetter * is a logical one and the responsibility of the core, so drivers are 39552217195SDaniel Vetter * expected not to mess with this. 39652217195SDaniel Vetter * 39752217195SDaniel Vetter * Note that the error return should've been enough here, but a large 39852217195SDaniel Vetter * majority of drivers ignores the return value, so add in a big WARN 39952217195SDaniel Vetter * to get people's attention. 40052217195SDaniel Vetter */ 40152217195SDaniel Vetter if (WARN_ON(connector->encoder)) 40252217195SDaniel Vetter return -EINVAL; 40352217195SDaniel Vetter 40462afb4adSJosé Roberto de Souza connector->possible_encoders |= drm_encoder_mask(encoder); 40562afb4adSJosé Roberto de Souza 40652217195SDaniel Vetter return 0; 40752217195SDaniel Vetter } 408cde4c44dSDaniel Vetter EXPORT_SYMBOL(drm_connector_attach_encoder); 40952217195SDaniel Vetter 41038cb8d96SVille Syrjälä /** 41162afb4adSJosé Roberto de Souza * drm_connector_has_possible_encoder - check if the connector and encoder are 41262afb4adSJosé Roberto de Souza * associated with each other 41338cb8d96SVille Syrjälä * @connector: the connector 41438cb8d96SVille Syrjälä * @encoder: the encoder 41538cb8d96SVille Syrjälä * 41638cb8d96SVille Syrjälä * Returns: 41738cb8d96SVille Syrjälä * True if @encoder is one of the possible encoders for @connector. 41838cb8d96SVille Syrjälä */ 41938cb8d96SVille Syrjälä bool drm_connector_has_possible_encoder(struct drm_connector *connector, 42038cb8d96SVille Syrjälä struct drm_encoder *encoder) 42138cb8d96SVille Syrjälä { 42262afb4adSJosé Roberto de Souza return connector->possible_encoders & drm_encoder_mask(encoder); 42338cb8d96SVille Syrjälä } 42438cb8d96SVille Syrjälä EXPORT_SYMBOL(drm_connector_has_possible_encoder); 42538cb8d96SVille Syrjälä 42652217195SDaniel Vetter static void drm_mode_remove(struct drm_connector *connector, 42752217195SDaniel Vetter struct drm_display_mode *mode) 42852217195SDaniel Vetter { 42952217195SDaniel Vetter list_del(&mode->head); 43052217195SDaniel Vetter drm_mode_destroy(connector->dev, mode); 43152217195SDaniel Vetter } 43252217195SDaniel Vetter 43352217195SDaniel Vetter /** 43452217195SDaniel Vetter * drm_connector_cleanup - cleans up an initialised connector 43552217195SDaniel Vetter * @connector: connector to cleanup 43652217195SDaniel Vetter * 43752217195SDaniel Vetter * Cleans up the connector but doesn't free the object. 43852217195SDaniel Vetter */ 43952217195SDaniel Vetter void drm_connector_cleanup(struct drm_connector *connector) 44052217195SDaniel Vetter { 44152217195SDaniel Vetter struct drm_device *dev = connector->dev; 44252217195SDaniel Vetter struct drm_display_mode *mode, *t; 44352217195SDaniel Vetter 44452217195SDaniel Vetter /* The connector should have been removed from userspace long before 44552217195SDaniel Vetter * it is finally destroyed. 44652217195SDaniel Vetter */ 44739b50c60SLyude Paul if (WARN_ON(connector->registration_state == 44839b50c60SLyude Paul DRM_CONNECTOR_REGISTERED)) 44952217195SDaniel Vetter drm_connector_unregister(connector); 45052217195SDaniel Vetter 45152217195SDaniel Vetter if (connector->tile_group) { 45252217195SDaniel Vetter drm_mode_put_tile_group(dev, connector->tile_group); 45352217195SDaniel Vetter connector->tile_group = NULL; 45452217195SDaniel Vetter } 45552217195SDaniel Vetter 45652217195SDaniel Vetter list_for_each_entry_safe(mode, t, &connector->probed_modes, head) 45752217195SDaniel Vetter drm_mode_remove(connector, mode); 45852217195SDaniel Vetter 45952217195SDaniel Vetter list_for_each_entry_safe(mode, t, &connector->modes, head) 46052217195SDaniel Vetter drm_mode_remove(connector, mode); 46152217195SDaniel Vetter 4629a47dba1SChristophe JAILLET ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida, 46352217195SDaniel Vetter connector->connector_type_id); 46452217195SDaniel Vetter 4659a47dba1SChristophe JAILLET ida_simple_remove(&dev->mode_config.connector_ida, 46652217195SDaniel Vetter connector->index); 46752217195SDaniel Vetter 46852217195SDaniel Vetter kfree(connector->display_info.bus_formats); 46952217195SDaniel Vetter drm_mode_object_unregister(dev, &connector->base); 47052217195SDaniel Vetter kfree(connector->name); 47152217195SDaniel Vetter connector->name = NULL; 472613051daSDaniel Vetter spin_lock_irq(&dev->mode_config.connector_list_lock); 47352217195SDaniel Vetter list_del(&connector->head); 47452217195SDaniel Vetter dev->mode_config.num_connector--; 475613051daSDaniel Vetter spin_unlock_irq(&dev->mode_config.connector_list_lock); 47652217195SDaniel Vetter 47752217195SDaniel Vetter WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); 47852217195SDaniel Vetter if (connector->state && connector->funcs->atomic_destroy_state) 47952217195SDaniel Vetter connector->funcs->atomic_destroy_state(connector, 48052217195SDaniel Vetter connector->state); 48152217195SDaniel Vetter 482e73ab00eSDaniel Vetter mutex_destroy(&connector->mutex); 483e73ab00eSDaniel Vetter 48452217195SDaniel Vetter memset(connector, 0, sizeof(*connector)); 48552217195SDaniel Vetter } 48652217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_cleanup); 48752217195SDaniel Vetter 48852217195SDaniel Vetter /** 48952217195SDaniel Vetter * drm_connector_register - register a connector 49052217195SDaniel Vetter * @connector: the connector to register 49152217195SDaniel Vetter * 49269b22f51SDaniel Vetter * Register userspace interfaces for a connector. Only call this for connectors 49369b22f51SDaniel Vetter * which can be hotplugged after drm_dev_register() has been called already, 49469b22f51SDaniel Vetter * e.g. DP MST connectors. All other connectors will be registered automatically 49569b22f51SDaniel Vetter * when calling drm_dev_register(). 49652217195SDaniel Vetter * 49752217195SDaniel Vetter * Returns: 49852217195SDaniel Vetter * Zero on success, error code on failure. 49952217195SDaniel Vetter */ 50052217195SDaniel Vetter int drm_connector_register(struct drm_connector *connector) 50152217195SDaniel Vetter { 502e73ab00eSDaniel Vetter int ret = 0; 50352217195SDaniel Vetter 504e6e7b48bSDaniel Vetter if (!connector->dev->registered) 505e6e7b48bSDaniel Vetter return 0; 506e6e7b48bSDaniel Vetter 507e73ab00eSDaniel Vetter mutex_lock(&connector->mutex); 50839b50c60SLyude Paul if (connector->registration_state != DRM_CONNECTOR_INITIALIZING) 509e73ab00eSDaniel Vetter goto unlock; 51052217195SDaniel Vetter 51152217195SDaniel Vetter ret = drm_sysfs_connector_add(connector); 51252217195SDaniel Vetter if (ret) 513e73ab00eSDaniel Vetter goto unlock; 51452217195SDaniel Vetter 515b792e640SGreg Kroah-Hartman drm_debugfs_connector_add(connector); 51652217195SDaniel Vetter 51752217195SDaniel Vetter if (connector->funcs->late_register) { 51852217195SDaniel Vetter ret = connector->funcs->late_register(connector); 51952217195SDaniel Vetter if (ret) 52052217195SDaniel Vetter goto err_debugfs; 52152217195SDaniel Vetter } 52252217195SDaniel Vetter 52352217195SDaniel Vetter drm_mode_object_register(connector->dev, &connector->base); 52452217195SDaniel Vetter 52539b50c60SLyude Paul connector->registration_state = DRM_CONNECTOR_REGISTERED; 526e73ab00eSDaniel Vetter goto unlock; 52752217195SDaniel Vetter 52852217195SDaniel Vetter err_debugfs: 52952217195SDaniel Vetter drm_debugfs_connector_remove(connector); 53052217195SDaniel Vetter drm_sysfs_connector_remove(connector); 531e73ab00eSDaniel Vetter unlock: 532e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 53352217195SDaniel Vetter return ret; 53452217195SDaniel Vetter } 53552217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_register); 53652217195SDaniel Vetter 53752217195SDaniel Vetter /** 53852217195SDaniel Vetter * drm_connector_unregister - unregister a connector 53952217195SDaniel Vetter * @connector: the connector to unregister 54052217195SDaniel Vetter * 54169b22f51SDaniel Vetter * Unregister userspace interfaces for a connector. Only call this for 54269b22f51SDaniel Vetter * connectors which have registered explicitly by calling drm_dev_register(), 54369b22f51SDaniel Vetter * since connectors are unregistered automatically when drm_dev_unregister() is 54469b22f51SDaniel Vetter * called. 54552217195SDaniel Vetter */ 54652217195SDaniel Vetter void drm_connector_unregister(struct drm_connector *connector) 54752217195SDaniel Vetter { 548e73ab00eSDaniel Vetter mutex_lock(&connector->mutex); 54939b50c60SLyude Paul if (connector->registration_state != DRM_CONNECTOR_REGISTERED) { 550e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 55152217195SDaniel Vetter return; 552e73ab00eSDaniel Vetter } 55352217195SDaniel Vetter 55452217195SDaniel Vetter if (connector->funcs->early_unregister) 55552217195SDaniel Vetter connector->funcs->early_unregister(connector); 55652217195SDaniel Vetter 55752217195SDaniel Vetter drm_sysfs_connector_remove(connector); 55852217195SDaniel Vetter drm_debugfs_connector_remove(connector); 55952217195SDaniel Vetter 56039b50c60SLyude Paul connector->registration_state = DRM_CONNECTOR_UNREGISTERED; 561e73ab00eSDaniel Vetter mutex_unlock(&connector->mutex); 56252217195SDaniel Vetter } 56352217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_unregister); 56452217195SDaniel Vetter 56552217195SDaniel Vetter void drm_connector_unregister_all(struct drm_device *dev) 56652217195SDaniel Vetter { 56752217195SDaniel Vetter struct drm_connector *connector; 568613051daSDaniel Vetter struct drm_connector_list_iter conn_iter; 56952217195SDaniel Vetter 570b982dab1SThierry Reding drm_connector_list_iter_begin(dev, &conn_iter); 571613051daSDaniel Vetter drm_for_each_connector_iter(connector, &conn_iter) 57252217195SDaniel Vetter drm_connector_unregister(connector); 573b982dab1SThierry Reding drm_connector_list_iter_end(&conn_iter); 57452217195SDaniel Vetter } 57552217195SDaniel Vetter 57652217195SDaniel Vetter int drm_connector_register_all(struct drm_device *dev) 57752217195SDaniel Vetter { 57852217195SDaniel Vetter struct drm_connector *connector; 579613051daSDaniel Vetter struct drm_connector_list_iter conn_iter; 580613051daSDaniel Vetter int ret = 0; 58152217195SDaniel Vetter 582b982dab1SThierry Reding drm_connector_list_iter_begin(dev, &conn_iter); 583613051daSDaniel Vetter drm_for_each_connector_iter(connector, &conn_iter) { 58452217195SDaniel Vetter ret = drm_connector_register(connector); 58552217195SDaniel Vetter if (ret) 586613051daSDaniel Vetter break; 58752217195SDaniel Vetter } 588b982dab1SThierry Reding drm_connector_list_iter_end(&conn_iter); 58952217195SDaniel Vetter 590613051daSDaniel Vetter if (ret) 59152217195SDaniel Vetter drm_connector_unregister_all(dev); 59252217195SDaniel Vetter return ret; 59352217195SDaniel Vetter } 59452217195SDaniel Vetter 59552217195SDaniel Vetter /** 59652217195SDaniel Vetter * drm_get_connector_status_name - return a string for connector status 59752217195SDaniel Vetter * @status: connector status to compute name of 59852217195SDaniel Vetter * 59952217195SDaniel Vetter * In contrast to the other drm_get_*_name functions this one here returns a 60052217195SDaniel Vetter * const pointer and hence is threadsafe. 60152217195SDaniel Vetter */ 60252217195SDaniel Vetter const char *drm_get_connector_status_name(enum drm_connector_status status) 60352217195SDaniel Vetter { 60452217195SDaniel Vetter if (status == connector_status_connected) 60552217195SDaniel Vetter return "connected"; 60652217195SDaniel Vetter else if (status == connector_status_disconnected) 60752217195SDaniel Vetter return "disconnected"; 60852217195SDaniel Vetter else 60952217195SDaniel Vetter return "unknown"; 61052217195SDaniel Vetter } 61152217195SDaniel Vetter EXPORT_SYMBOL(drm_get_connector_status_name); 61252217195SDaniel Vetter 6136140cf20SJani Nikula /** 6146140cf20SJani Nikula * drm_get_connector_force_name - return a string for connector force 6156140cf20SJani Nikula * @force: connector force to get name of 6166140cf20SJani Nikula * 6176140cf20SJani Nikula * Returns: const pointer to name. 6186140cf20SJani Nikula */ 6196140cf20SJani Nikula const char *drm_get_connector_force_name(enum drm_connector_force force) 6206140cf20SJani Nikula { 6216140cf20SJani Nikula switch (force) { 6226140cf20SJani Nikula case DRM_FORCE_UNSPECIFIED: 6236140cf20SJani Nikula return "unspecified"; 6246140cf20SJani Nikula case DRM_FORCE_OFF: 6256140cf20SJani Nikula return "off"; 6266140cf20SJani Nikula case DRM_FORCE_ON: 6276140cf20SJani Nikula return "on"; 6286140cf20SJani Nikula case DRM_FORCE_ON_DIGITAL: 6296140cf20SJani Nikula return "digital"; 6306140cf20SJani Nikula default: 6316140cf20SJani Nikula return "unknown"; 6326140cf20SJani Nikula } 6336140cf20SJani Nikula } 6346140cf20SJani Nikula 635613051daSDaniel Vetter #ifdef CONFIG_LOCKDEP 636613051daSDaniel Vetter static struct lockdep_map connector_list_iter_dep_map = { 637613051daSDaniel Vetter .name = "drm_connector_list_iter" 638613051daSDaniel Vetter }; 639613051daSDaniel Vetter #endif 640613051daSDaniel Vetter 641613051daSDaniel Vetter /** 642b982dab1SThierry Reding * drm_connector_list_iter_begin - initialize a connector_list iterator 643613051daSDaniel Vetter * @dev: DRM device 644613051daSDaniel Vetter * @iter: connector_list iterator 645613051daSDaniel Vetter * 646d574528aSDaniel Vetter * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter 647b982dab1SThierry Reding * must always be cleaned up again by calling drm_connector_list_iter_end(). 648613051daSDaniel Vetter * Iteration itself happens using drm_connector_list_iter_next() or 649613051daSDaniel Vetter * drm_for_each_connector_iter(). 650613051daSDaniel Vetter */ 651b982dab1SThierry Reding void drm_connector_list_iter_begin(struct drm_device *dev, 652613051daSDaniel Vetter struct drm_connector_list_iter *iter) 653613051daSDaniel Vetter { 654613051daSDaniel Vetter iter->dev = dev; 655613051daSDaniel Vetter iter->conn = NULL; 656613051daSDaniel Vetter lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_); 657613051daSDaniel Vetter } 658b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_begin); 659613051daSDaniel Vetter 660a703c550SDaniel Vetter /* 661a703c550SDaniel Vetter * Extra-safe connector put function that works in any context. Should only be 662a703c550SDaniel Vetter * used from the connector_iter functions, where we never really expect to 663a703c550SDaniel Vetter * actually release the connector when dropping our final reference. 664a703c550SDaniel Vetter */ 665a703c550SDaniel Vetter static void 666ea497bb9SDaniel Vetter __drm_connector_put_safe(struct drm_connector *conn) 667a703c550SDaniel Vetter { 668ea497bb9SDaniel Vetter struct drm_mode_config *config = &conn->dev->mode_config; 669ea497bb9SDaniel Vetter 670ea497bb9SDaniel Vetter lockdep_assert_held(&config->connector_list_lock); 671ea497bb9SDaniel Vetter 672ea497bb9SDaniel Vetter if (!refcount_dec_and_test(&conn->base.refcount.refcount)) 673ea497bb9SDaniel Vetter return; 674ea497bb9SDaniel Vetter 675ea497bb9SDaniel Vetter llist_add(&conn->free_node, &config->connector_free_list); 676ea497bb9SDaniel Vetter schedule_work(&config->connector_free_work); 677a703c550SDaniel Vetter } 678a703c550SDaniel Vetter 679613051daSDaniel Vetter /** 680613051daSDaniel Vetter * drm_connector_list_iter_next - return next connector 6814f45c778SLyude Paul * @iter: connector_list iterator 682613051daSDaniel Vetter * 683613051daSDaniel Vetter * Returns the next connector for @iter, or NULL when the list walk has 684613051daSDaniel Vetter * completed. 685613051daSDaniel Vetter */ 686613051daSDaniel Vetter struct drm_connector * 687613051daSDaniel Vetter drm_connector_list_iter_next(struct drm_connector_list_iter *iter) 688613051daSDaniel Vetter { 689613051daSDaniel Vetter struct drm_connector *old_conn = iter->conn; 690613051daSDaniel Vetter struct drm_mode_config *config = &iter->dev->mode_config; 691613051daSDaniel Vetter struct list_head *lhead; 692613051daSDaniel Vetter unsigned long flags; 693613051daSDaniel Vetter 694613051daSDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 695613051daSDaniel Vetter lhead = old_conn ? &old_conn->head : &config->connector_list; 696613051daSDaniel Vetter 697613051daSDaniel Vetter do { 698613051daSDaniel Vetter if (lhead->next == &config->connector_list) { 699613051daSDaniel Vetter iter->conn = NULL; 700613051daSDaniel Vetter break; 701613051daSDaniel Vetter } 702613051daSDaniel Vetter 703613051daSDaniel Vetter lhead = lhead->next; 704613051daSDaniel Vetter iter->conn = list_entry(lhead, struct drm_connector, head); 705613051daSDaniel Vetter 706613051daSDaniel Vetter /* loop until it's not a zombie connector */ 707613051daSDaniel Vetter } while (!kref_get_unless_zero(&iter->conn->base.refcount)); 708613051daSDaniel Vetter 709613051daSDaniel Vetter if (old_conn) 710ea497bb9SDaniel Vetter __drm_connector_put_safe(old_conn); 711ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 712613051daSDaniel Vetter 713613051daSDaniel Vetter return iter->conn; 714613051daSDaniel Vetter } 715613051daSDaniel Vetter EXPORT_SYMBOL(drm_connector_list_iter_next); 716613051daSDaniel Vetter 717613051daSDaniel Vetter /** 718b982dab1SThierry Reding * drm_connector_list_iter_end - tear down a connector_list iterator 719613051daSDaniel Vetter * @iter: connector_list iterator 720613051daSDaniel Vetter * 721613051daSDaniel Vetter * Tears down @iter and releases any resources (like &drm_connector references) 722613051daSDaniel Vetter * acquired while walking the list. This must always be called, both when the 723613051daSDaniel Vetter * iteration completes fully or when it was aborted without walking the entire 724613051daSDaniel Vetter * list. 725613051daSDaniel Vetter */ 726b982dab1SThierry Reding void drm_connector_list_iter_end(struct drm_connector_list_iter *iter) 727613051daSDaniel Vetter { 728ea497bb9SDaniel Vetter struct drm_mode_config *config = &iter->dev->mode_config; 729ea497bb9SDaniel Vetter unsigned long flags; 730ea497bb9SDaniel Vetter 731613051daSDaniel Vetter iter->dev = NULL; 732ea497bb9SDaniel Vetter if (iter->conn) { 733ea497bb9SDaniel Vetter spin_lock_irqsave(&config->connector_list_lock, flags); 734ea497bb9SDaniel Vetter __drm_connector_put_safe(iter->conn); 735ea497bb9SDaniel Vetter spin_unlock_irqrestore(&config->connector_list_lock, flags); 736ea497bb9SDaniel Vetter } 7375facae4fSQian Cai lock_release(&connector_list_iter_dep_map, _RET_IP_); 738613051daSDaniel Vetter } 739b982dab1SThierry Reding EXPORT_SYMBOL(drm_connector_list_iter_end); 740613051daSDaniel Vetter 74152217195SDaniel Vetter static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { 74252217195SDaniel Vetter { SubPixelUnknown, "Unknown" }, 74352217195SDaniel Vetter { SubPixelHorizontalRGB, "Horizontal RGB" }, 74452217195SDaniel Vetter { SubPixelHorizontalBGR, "Horizontal BGR" }, 74552217195SDaniel Vetter { SubPixelVerticalRGB, "Vertical RGB" }, 74652217195SDaniel Vetter { SubPixelVerticalBGR, "Vertical BGR" }, 74752217195SDaniel Vetter { SubPixelNone, "None" }, 74852217195SDaniel Vetter }; 74952217195SDaniel Vetter 75052217195SDaniel Vetter /** 75152217195SDaniel Vetter * drm_get_subpixel_order_name - return a string for a given subpixel enum 75252217195SDaniel Vetter * @order: enum of subpixel_order 75352217195SDaniel Vetter * 75452217195SDaniel Vetter * Note you could abuse this and return something out of bounds, but that 75552217195SDaniel Vetter * would be a caller error. No unscrubbed user data should make it here. 75652217195SDaniel Vetter */ 75752217195SDaniel Vetter const char *drm_get_subpixel_order_name(enum subpixel_order order) 75852217195SDaniel Vetter { 75952217195SDaniel Vetter return drm_subpixel_enum_list[order].name; 76052217195SDaniel Vetter } 76152217195SDaniel Vetter EXPORT_SYMBOL(drm_get_subpixel_order_name); 76252217195SDaniel Vetter 76352217195SDaniel Vetter static const struct drm_prop_enum_list drm_dpms_enum_list[] = { 76452217195SDaniel Vetter { DRM_MODE_DPMS_ON, "On" }, 76552217195SDaniel Vetter { DRM_MODE_DPMS_STANDBY, "Standby" }, 76652217195SDaniel Vetter { DRM_MODE_DPMS_SUSPEND, "Suspend" }, 76752217195SDaniel Vetter { DRM_MODE_DPMS_OFF, "Off" } 76852217195SDaniel Vetter }; 76952217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) 77052217195SDaniel Vetter 77140ee6fbeSManasi Navare static const struct drm_prop_enum_list drm_link_status_enum_list[] = { 77240ee6fbeSManasi Navare { DRM_MODE_LINK_STATUS_GOOD, "Good" }, 77340ee6fbeSManasi Navare { DRM_MODE_LINK_STATUS_BAD, "Bad" }, 77440ee6fbeSManasi Navare }; 77540ee6fbeSManasi Navare 776b3c6c8bfSDaniel Vetter /** 777b3c6c8bfSDaniel Vetter * drm_display_info_set_bus_formats - set the supported bus formats 778b3c6c8bfSDaniel Vetter * @info: display info to store bus formats in 779b3c6c8bfSDaniel Vetter * @formats: array containing the supported bus formats 780b3c6c8bfSDaniel Vetter * @num_formats: the number of entries in the fmts array 781b3c6c8bfSDaniel Vetter * 782b3c6c8bfSDaniel Vetter * Store the supported bus formats in display info structure. 783b3c6c8bfSDaniel Vetter * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for 784b3c6c8bfSDaniel Vetter * a full list of available formats. 785b3c6c8bfSDaniel Vetter */ 786b3c6c8bfSDaniel Vetter int drm_display_info_set_bus_formats(struct drm_display_info *info, 787b3c6c8bfSDaniel Vetter const u32 *formats, 788b3c6c8bfSDaniel Vetter unsigned int num_formats) 789b3c6c8bfSDaniel Vetter { 790b3c6c8bfSDaniel Vetter u32 *fmts = NULL; 791b3c6c8bfSDaniel Vetter 792b3c6c8bfSDaniel Vetter if (!formats && num_formats) 793b3c6c8bfSDaniel Vetter return -EINVAL; 794b3c6c8bfSDaniel Vetter 795b3c6c8bfSDaniel Vetter if (formats && num_formats) { 796b3c6c8bfSDaniel Vetter fmts = kmemdup(formats, sizeof(*formats) * num_formats, 797b3c6c8bfSDaniel Vetter GFP_KERNEL); 798b3c6c8bfSDaniel Vetter if (!fmts) 799b3c6c8bfSDaniel Vetter return -ENOMEM; 800b3c6c8bfSDaniel Vetter } 801b3c6c8bfSDaniel Vetter 802b3c6c8bfSDaniel Vetter kfree(info->bus_formats); 803b3c6c8bfSDaniel Vetter info->bus_formats = fmts; 804b3c6c8bfSDaniel Vetter info->num_bus_formats = num_formats; 805b3c6c8bfSDaniel Vetter 806b3c6c8bfSDaniel Vetter return 0; 807b3c6c8bfSDaniel Vetter } 808b3c6c8bfSDaniel Vetter EXPORT_SYMBOL(drm_display_info_set_bus_formats); 809b3c6c8bfSDaniel Vetter 81052217195SDaniel Vetter /* Optional connector properties. */ 81152217195SDaniel Vetter static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { 81252217195SDaniel Vetter { DRM_MODE_SCALE_NONE, "None" }, 81352217195SDaniel Vetter { DRM_MODE_SCALE_FULLSCREEN, "Full" }, 81452217195SDaniel Vetter { DRM_MODE_SCALE_CENTER, "Center" }, 81552217195SDaniel Vetter { DRM_MODE_SCALE_ASPECT, "Full aspect" }, 81652217195SDaniel Vetter }; 81752217195SDaniel Vetter 81852217195SDaniel Vetter static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { 81952217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, 82052217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, 82152217195SDaniel Vetter { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, 82252217195SDaniel Vetter }; 82352217195SDaniel Vetter 82450525c33SStanislav Lisovskiy static const struct drm_prop_enum_list drm_content_type_enum_list[] = { 82550525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" }, 82650525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" }, 82750525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" }, 82850525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" }, 82950525c33SStanislav Lisovskiy { DRM_MODE_CONTENT_TYPE_GAME, "Game" }, 83050525c33SStanislav Lisovskiy }; 83150525c33SStanislav Lisovskiy 8328d70f395SHans de Goede static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = { 8338d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" }, 8348d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" }, 8358d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" }, 8368d70f395SHans de Goede { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" }, 8378d70f395SHans de Goede }; 8388d70f395SHans de Goede 83952217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { 84052217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 84152217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 84252217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 84352217195SDaniel Vetter }; 84452217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) 84552217195SDaniel Vetter 84652217195SDaniel Vetter static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { 84752217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ 84852217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 84952217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 85052217195SDaniel Vetter }; 85152217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, 85252217195SDaniel Vetter drm_dvi_i_subconnector_enum_list) 85352217195SDaniel Vetter 85452217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { 85552217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 85652217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 85752217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 85852217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 85952217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 86052217195SDaniel Vetter }; 86152217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) 86252217195SDaniel Vetter 86352217195SDaniel Vetter static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { 86452217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ 86552217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 86652217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 86752217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 86852217195SDaniel Vetter { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 86952217195SDaniel Vetter }; 87052217195SDaniel Vetter DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, 87152217195SDaniel Vetter drm_tv_subconnector_enum_list) 87252217195SDaniel Vetter 873d2c6a405SUma Shankar static const struct drm_prop_enum_list hdmi_colorspaces[] = { 874d2c6a405SUma Shankar /* For Default case, driver will set the colorspace */ 875d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_DEFAULT, "Default" }, 876d2c6a405SUma Shankar /* Standard Definition Colorimetry based on CEA 861 */ 877d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" }, 878d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" }, 879d2c6a405SUma Shankar /* Standard Definition Colorimetry based on IEC 61966-2-4 */ 880d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" }, 881d2c6a405SUma Shankar /* High Definition Colorimetry based on IEC 61966-2-4 */ 882d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" }, 883d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-1/Amendment 1 */ 884d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" }, 885d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-5 [33] */ 886d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" }, 887d2c6a405SUma Shankar /* Colorimetry based on IEC 61966-2-5 */ 888d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" }, 889d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 890d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" }, 891d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 892d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" }, 893d2c6a405SUma Shankar /* Colorimetry based on ITU-R BT.2020 */ 894d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" }, 895d2c6a405SUma Shankar /* Added as part of Additional Colorimetry Extension in 861.G */ 896d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" }, 897d2c6a405SUma Shankar { DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" }, 898d2c6a405SUma Shankar }; 899d2c6a405SUma Shankar 90045cf0e91SGwan-gyeong Mun /* 90145cf0e91SGwan-gyeong Mun * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry 90245cf0e91SGwan-gyeong Mun * Format Table 2-120 90345cf0e91SGwan-gyeong Mun */ 90445cf0e91SGwan-gyeong Mun static const struct drm_prop_enum_list dp_colorspaces[] = { 90545cf0e91SGwan-gyeong Mun /* For Default case, driver will set the colorspace */ 90645cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_DEFAULT, "Default" }, 90745cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" }, 90845cf0e91SGwan-gyeong Mun /* Colorimetry based on scRGB (IEC 61966-2-2) */ 90945cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" }, 91045cf0e91SGwan-gyeong Mun /* Colorimetry based on IEC 61966-2-5 */ 91145cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" }, 91245cf0e91SGwan-gyeong Mun /* Colorimetry based on SMPTE RP 431-2 */ 91345cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" }, 91445cf0e91SGwan-gyeong Mun /* Colorimetry based on ITU-R BT.2020 */ 91545cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" }, 91645cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" }, 91745cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" }, 91845cf0e91SGwan-gyeong Mun /* Standard Definition Colorimetry based on IEC 61966-2-4 */ 91945cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" }, 92045cf0e91SGwan-gyeong Mun /* High Definition Colorimetry based on IEC 61966-2-4 */ 92145cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" }, 92245cf0e91SGwan-gyeong Mun /* Colorimetry based on IEC 61966-2-1/Amendment 1 */ 92345cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" }, 92445cf0e91SGwan-gyeong Mun /* Colorimetry based on IEC 61966-2-5 [33] */ 92545cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" }, 92645cf0e91SGwan-gyeong Mun /* Colorimetry based on ITU-R BT.2020 */ 92745cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" }, 92845cf0e91SGwan-gyeong Mun /* Colorimetry based on ITU-R BT.2020 */ 92945cf0e91SGwan-gyeong Mun { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" }, 93045cf0e91SGwan-gyeong Mun }; 93145cf0e91SGwan-gyeong Mun 9324ada6f22SDaniel Vetter /** 9334ada6f22SDaniel Vetter * DOC: standard connector properties 9344ada6f22SDaniel Vetter * 9354ada6f22SDaniel Vetter * DRM connectors have a few standardized properties: 9364ada6f22SDaniel Vetter * 9374ada6f22SDaniel Vetter * EDID: 9384ada6f22SDaniel Vetter * Blob property which contains the current EDID read from the sink. This 9394ada6f22SDaniel Vetter * is useful to parse sink identification information like vendor, model 9404ada6f22SDaniel Vetter * and serial. Drivers should update this property by calling 941c555f023SDaniel Vetter * drm_connector_update_edid_property(), usually after having parsed 9424ada6f22SDaniel Vetter * the EDID using drm_add_edid_modes(). Userspace cannot change this 9434ada6f22SDaniel Vetter * property. 9444ada6f22SDaniel Vetter * DPMS: 9454ada6f22SDaniel Vetter * Legacy property for setting the power state of the connector. For atomic 9464ada6f22SDaniel Vetter * drivers this is only provided for backwards compatibility with existing 9474ada6f22SDaniel Vetter * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the 9484ada6f22SDaniel Vetter * connector is linked to. Drivers should never set this property directly, 949d574528aSDaniel Vetter * it is handled by the DRM core by calling the &drm_connector_funcs.dpms 950144a7999SDaniel Vetter * callback. For atomic drivers the remapping to the "ACTIVE" property is 9511e3e4caeSSimon Ser * implemented in the DRM core. 952d0d1aee5SDaniel Vetter * 953d0d1aee5SDaniel Vetter * Note that this property cannot be set through the MODE_ATOMIC ioctl, 954d0d1aee5SDaniel Vetter * userspace must use "ACTIVE" on the CRTC instead. 955d0d1aee5SDaniel Vetter * 956d0d1aee5SDaniel Vetter * WARNING: 957d0d1aee5SDaniel Vetter * 958d0d1aee5SDaniel Vetter * For userspace also running on legacy drivers the "DPMS" semantics are a 959d0d1aee5SDaniel Vetter * lot more complicated. First, userspace cannot rely on the "DPMS" value 960d0d1aee5SDaniel Vetter * returned by the GETCONNECTOR actually reflecting reality, because many 961d0d1aee5SDaniel Vetter * drivers fail to update it. For atomic drivers this is taken care of in 962d0d1aee5SDaniel Vetter * drm_atomic_helper_update_legacy_modeset_state(). 963d0d1aee5SDaniel Vetter * 964d0d1aee5SDaniel Vetter * The second issue is that the DPMS state is only well-defined when the 965d0d1aee5SDaniel Vetter * connector is connected to a CRTC. In atomic the DRM core enforces that 966d0d1aee5SDaniel Vetter * "ACTIVE" is off in such a case, no such checks exists for "DPMS". 967d0d1aee5SDaniel Vetter * 968d0d1aee5SDaniel Vetter * Finally, when enabling an output using the legacy SETCONFIG ioctl then 969d0d1aee5SDaniel Vetter * "DPMS" is forced to ON. But see above, that might not be reflected in 970d0d1aee5SDaniel Vetter * the software value on legacy drivers. 971d0d1aee5SDaniel Vetter * 972d0d1aee5SDaniel Vetter * Summarizing: Only set "DPMS" when the connector is known to be enabled, 973d0d1aee5SDaniel Vetter * assume that a successful SETCONFIG call also sets "DPMS" to on, and 974d0d1aee5SDaniel Vetter * never read back the value of "DPMS" because it can be incorrect. 9754ada6f22SDaniel Vetter * PATH: 9764ada6f22SDaniel Vetter * Connector path property to identify how this sink is physically 9774ada6f22SDaniel Vetter * connected. Used by DP MST. This should be set by calling 97897e14fbeSDaniel Vetter * drm_connector_set_path_property(), in the case of DP MST with the 9794ada6f22SDaniel Vetter * path property the MST manager created. Userspace cannot change this 9804ada6f22SDaniel Vetter * property. 9814ada6f22SDaniel Vetter * TILE: 9824ada6f22SDaniel Vetter * Connector tile group property to indicate how a set of DRM connector 9834ada6f22SDaniel Vetter * compose together into one logical screen. This is used by both high-res 9844ada6f22SDaniel Vetter * external screens (often only using a single cable, but exposing multiple 9854ada6f22SDaniel Vetter * DP MST sinks), or high-res integrated panels (like dual-link DSI) which 9864ada6f22SDaniel Vetter * are not gen-locked. Note that for tiled panels which are genlocked, like 9874ada6f22SDaniel Vetter * dual-link LVDS or dual-link DSI, the driver should try to not expose the 988*84e543bcSAntonio Borneo * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers 98997e14fbeSDaniel Vetter * should update this value using drm_connector_set_tile_property(). 9904ada6f22SDaniel Vetter * Userspace cannot change this property. 99140ee6fbeSManasi Navare * link-status: 992716719a3SSean Paul * Connector link-status property to indicate the status of link. The 993716719a3SSean Paul * default value of link-status is "GOOD". If something fails during or 994716719a3SSean Paul * after modeset, the kernel driver may set this to "BAD" and issue a 995716719a3SSean Paul * hotplug uevent. Drivers should update this value using 99697e14fbeSDaniel Vetter * drm_connector_set_link_status_property(). 997a66da873SSimon Ser * 998a66da873SSimon Ser * When user-space receives the hotplug uevent and detects a "BAD" 999a66da873SSimon Ser * link-status, the sink doesn't receive pixels anymore (e.g. the screen 1000a66da873SSimon Ser * becomes completely black). The list of available modes may have 1001a66da873SSimon Ser * changed. User-space is expected to pick a new mode if the current one 1002a66da873SSimon Ser * has disappeared and perform a new modeset with link-status set to 1003a66da873SSimon Ser * "GOOD" to re-enable the connector. 1004a66da873SSimon Ser * 1005a66da873SSimon Ser * If multiple connectors share the same CRTC and one of them gets a "BAD" 1006a66da873SSimon Ser * link-status, the other are unaffected (ie. the sinks still continue to 1007a66da873SSimon Ser * receive pixels). 1008a66da873SSimon Ser * 1009a66da873SSimon Ser * When user-space performs an atomic commit on a connector with a "BAD" 1010a66da873SSimon Ser * link-status without resetting the property to "GOOD", the sink may 1011a66da873SSimon Ser * still not receive pixels. When user-space performs an atomic commit 1012a66da873SSimon Ser * which resets the link-status property to "GOOD" without the 1013a66da873SSimon Ser * ALLOW_MODESET flag set, it might fail because a modeset is required. 1014a66da873SSimon Ser * 1015a66da873SSimon Ser * User-space can only change link-status to "GOOD", changing it to "BAD" 1016a66da873SSimon Ser * is a no-op. 1017a66da873SSimon Ser * 1018a66da873SSimon Ser * For backwards compatibility with non-atomic userspace the kernel 1019a66da873SSimon Ser * tries to automatically set the link-status back to "GOOD" in the 1020a66da873SSimon Ser * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar 1021a66da873SSimon Ser * to how it might fail if a different screen has been connected in the 1022a66da873SSimon Ser * interim. 102366660d4cSDave Airlie * non_desktop: 102466660d4cSDave Airlie * Indicates the output should be ignored for purposes of displaying a 102566660d4cSDave Airlie * standard desktop environment or console. This is most likely because 102666660d4cSDave Airlie * the output device is not rectilinear. 102724557865SSean Paul * Content Protection: 102824557865SSean Paul * This property is used by userspace to request the kernel protect future 102924557865SSean Paul * content communicated over the link. When requested, kernel will apply 103024557865SSean Paul * the appropriate means of protection (most often HDCP), and use the 103124557865SSean Paul * property to tell userspace the protection is active. 103224557865SSean Paul * 103324557865SSean Paul * Drivers can set this up by calling 103424557865SSean Paul * drm_connector_attach_content_protection_property() on initialization. 103524557865SSean Paul * 103624557865SSean Paul * The value of this property can be one of the following: 103724557865SSean Paul * 1038bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0 103924557865SSean Paul * The link is not protected, content is transmitted in the clear. 1040bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1 104124557865SSean Paul * Userspace has requested content protection, but the link is not 104224557865SSean Paul * currently protected. When in this state, kernel should enable 104324557865SSean Paul * Content Protection as soon as possible. 1044bbeba09fSDaniel Vetter * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2 104524557865SSean Paul * Userspace has requested content protection, and the link is 104624557865SSean Paul * protected. Only the driver can set the property to this value. 104724557865SSean Paul * If userspace attempts to set to ENABLED, kernel will return 104824557865SSean Paul * -EINVAL. 104924557865SSean Paul * 105024557865SSean Paul * A few guidelines: 105124557865SSean Paul * 105224557865SSean Paul * - DESIRED state should be preserved until userspace de-asserts it by 105324557865SSean Paul * setting the property to UNDESIRED. This means ENABLED should only 105424557865SSean Paul * transition to UNDESIRED when the user explicitly requests it. 105524557865SSean Paul * - If the state is DESIRED, kernel should attempt to re-authenticate the 105624557865SSean Paul * link whenever possible. This includes across disable/enable, dpms, 105724557865SSean Paul * hotplug, downstream device changes, link status failures, etc.. 1058bb5a45d4SRamalingam C * - Kernel sends uevent with the connector id and property id through 1059bb5a45d4SRamalingam C * @drm_hdcp_update_content_protection, upon below kernel triggered 1060bb5a45d4SRamalingam C * scenarios: 106112db36bcSSean Paul * 106212db36bcSSean Paul * - DESIRED -> ENABLED (authentication success) 106312db36bcSSean Paul * - ENABLED -> DESIRED (termination of authentication) 1064bb5a45d4SRamalingam C * - Please note no uevents for userspace triggered property state changes, 1065bb5a45d4SRamalingam C * which can't fail such as 106612db36bcSSean Paul * 106712db36bcSSean Paul * - DESIRED/ENABLED -> UNDESIRED 106812db36bcSSean Paul * - UNDESIRED -> DESIRED 1069bb5a45d4SRamalingam C * - Userspace is responsible for polling the property or listen to uevents 1070bb5a45d4SRamalingam C * to determine when the value transitions from ENABLED to DESIRED. 1071bb5a45d4SRamalingam C * This signifies the link is no longer protected and userspace should 1072bb5a45d4SRamalingam C * take appropriate action (whatever that might be). 10734ada6f22SDaniel Vetter * 10747672dbbaSRamalingam C * HDCP Content Type: 10757672dbbaSRamalingam C * This Enum property is used by the userspace to declare the content type 10767672dbbaSRamalingam C * of the display stream, to kernel. Here display stream stands for any 10777672dbbaSRamalingam C * display content that userspace intended to display through HDCP 10787672dbbaSRamalingam C * encryption. 10797672dbbaSRamalingam C * 10807672dbbaSRamalingam C * Content Type of a stream is decided by the owner of the stream, as 10817672dbbaSRamalingam C * "HDCP Type0" or "HDCP Type1". 10827672dbbaSRamalingam C * 10837672dbbaSRamalingam C * The value of the property can be one of the below: 10847672dbbaSRamalingam C * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0 10857672dbbaSRamalingam C * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1 10867672dbbaSRamalingam C * 10877672dbbaSRamalingam C * When kernel starts the HDCP authentication (see "Content Protection" 10887672dbbaSRamalingam C * for details), it uses the content type in "HDCP Content Type" 10897672dbbaSRamalingam C * for performing the HDCP authentication with the display sink. 10907672dbbaSRamalingam C * 10917672dbbaSRamalingam C * Please note in HDCP spec versions, a link can be authenticated with 10927672dbbaSRamalingam C * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be 10937672dbbaSRamalingam C * authenticated with HDCP1.4 only for Content Type 0(though it is implicit 10947672dbbaSRamalingam C * in nature. As there is no reference for Content Type in HDCP1.4). 10957672dbbaSRamalingam C * 10967672dbbaSRamalingam C * HDCP2.2 authentication protocol itself takes the "Content Type" as a 10977672dbbaSRamalingam C * parameter, which is a input for the DP HDCP2.2 encryption algo. 10987672dbbaSRamalingam C * 10997672dbbaSRamalingam C * In case of Type 0 content protection request, kernel driver can choose 11007672dbbaSRamalingam C * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for 11017672dbbaSRamalingam C * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send 11027672dbbaSRamalingam C * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link). 11037672dbbaSRamalingam C * But if the content is classified as "HDCP Type 1", above mentioned 11047672dbbaSRamalingam C * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't 11057672dbbaSRamalingam C * authenticate the HDCP1.4 capable sink for "HDCP Type 1". 11067672dbbaSRamalingam C * 11077672dbbaSRamalingam C * Please note userspace can be ignorant of the HDCP versions used by the 11087672dbbaSRamalingam C * kernel driver to achieve the "HDCP Content Type". 11097672dbbaSRamalingam C * 11107672dbbaSRamalingam C * At current scenario, classifying a content as Type 1 ensures that the 11117672dbbaSRamalingam C * content will be displayed only through the HDCP2.2 encrypted link. 11127672dbbaSRamalingam C * 11137672dbbaSRamalingam C * Note that the HDCP Content Type property is introduced at HDCP 2.2, and 11147672dbbaSRamalingam C * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2 11157672dbbaSRamalingam C * (hence supporting Type 0 and Type 1). Based on how next versions of 11167672dbbaSRamalingam C * HDCP specs are defined content Type could be used for higher versions 11177672dbbaSRamalingam C * too. 11187672dbbaSRamalingam C * 11197672dbbaSRamalingam C * If content type is changed when "Content Protection" is not UNDESIRED, 11207672dbbaSRamalingam C * then kernel will disable the HDCP and re-enable with new type in the 11217672dbbaSRamalingam C * same atomic commit. And when "Content Protection" is ENABLED, it means 11227672dbbaSRamalingam C * that link is HDCP authenticated and encrypted, for the transmission of 11237672dbbaSRamalingam C * the Type of stream mentioned at "HDCP Content Type". 11247672dbbaSRamalingam C * 1125a09db883SUma Shankar * HDR_OUTPUT_METADATA: 1126a09db883SUma Shankar * Connector property to enable userspace to send HDR Metadata to 1127a09db883SUma Shankar * driver. This metadata is based on the composition and blending 1128a09db883SUma Shankar * policies decided by user, taking into account the hardware and 1129a09db883SUma Shankar * sink capabilities. The driver gets this metadata and creates a 1130a09db883SUma Shankar * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI, 1131a09db883SUma Shankar * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then 1132a09db883SUma Shankar * sent to sink. This notifies the sink of the upcoming frame's Color 1133a09db883SUma Shankar * Encoding and Luminance parameters. 1134a09db883SUma Shankar * 1135a09db883SUma Shankar * Userspace first need to detect the HDR capabilities of sink by 1136a09db883SUma Shankar * reading and parsing the EDID. Details of HDR metadata for HDMI 1137a09db883SUma Shankar * are added in CTA 861.G spec. For DP , its defined in VESA DP 1138a09db883SUma Shankar * Standard v1.4. It needs to then get the metadata information 1139a09db883SUma Shankar * of the video/game/app content which are encoded in HDR (basically 1140a09db883SUma Shankar * using HDR transfer functions). With this information it needs to 1141a09db883SUma Shankar * decide on a blending policy and compose the relevant 1142a09db883SUma Shankar * layers/overlays into a common format. Once this blending is done, 1143a09db883SUma Shankar * userspace will be aware of the metadata of the composed frame to 1144a09db883SUma Shankar * be send to sink. It then uses this property to communicate this 1145a09db883SUma Shankar * metadata to driver which then make a Infoframe packet and sends 1146a09db883SUma Shankar * to sink based on the type of encoder connected. 1147a09db883SUma Shankar * 1148a09db883SUma Shankar * Userspace will be responsible to do Tone mapping operation in case: 1149a09db883SUma Shankar * - Some layers are HDR and others are SDR 1150a09db883SUma Shankar * - HDR layers luminance is not same as sink 11519f9b2559SSean Paul * 1152a09db883SUma Shankar * It will even need to do colorspace conversion and get all layers 1153a09db883SUma Shankar * to one common colorspace for blending. It can use either GL, Media 1154*84e543bcSAntonio Borneo * or display engine to get this done based on the capabilities of the 1155a09db883SUma Shankar * associated hardware. 1156a09db883SUma Shankar * 1157a09db883SUma Shankar * Driver expects metadata to be put in &struct hdr_output_metadata 1158a09db883SUma Shankar * structure from userspace. This is received as blob and stored in 1159a09db883SUma Shankar * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the 1160a09db883SUma Shankar * sink metadata in &struct hdr_sink_metadata, as 1161a09db883SUma Shankar * &drm_connector.hdr_sink_metadata. Driver uses 1162a09db883SUma Shankar * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata, 1163a09db883SUma Shankar * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of 1164a09db883SUma Shankar * HDMI encoder. 1165a09db883SUma Shankar * 116647e22ff1SRadhakrishna Sripada * max bpc: 116747e22ff1SRadhakrishna Sripada * This range property is used by userspace to limit the bit depth. When 116847e22ff1SRadhakrishna Sripada * used the driver would limit the bpc in accordance with the valid range 116947e22ff1SRadhakrishna Sripada * supported by the hardware and sink. Drivers to use the function 117047e22ff1SRadhakrishna Sripada * drm_connector_attach_max_bpc_property() to create and attach the 117147e22ff1SRadhakrishna Sripada * property to the connector during initialization. 117247e22ff1SRadhakrishna Sripada * 11734ada6f22SDaniel Vetter * Connectors also have one standardized atomic property: 11744ada6f22SDaniel Vetter * 11754ada6f22SDaniel Vetter * CRTC_ID: 11764ada6f22SDaniel Vetter * Mode object ID of the &drm_crtc this connector should be connected to. 11778d70f395SHans de Goede * 11788d70f395SHans de Goede * Connectors for LCD panels may also have one standardized property: 11798d70f395SHans de Goede * 11808d70f395SHans de Goede * panel orientation: 11818d70f395SHans de Goede * On some devices the LCD panel is mounted in the casing in such a way 11828d70f395SHans de Goede * that the up/top side of the panel does not match with the top side of 11838d70f395SHans de Goede * the device. Userspace can use this property to check for this. 11848d70f395SHans de Goede * Note that input coordinates from touchscreens (input devices with 11858d70f395SHans de Goede * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel 11868d70f395SHans de Goede * coordinates, so if userspace rotates the picture to adjust for 11878d70f395SHans de Goede * the orientation it must also apply the same transformation to the 1188bbeba09fSDaniel Vetter * touchscreen input coordinates. This property is initialized by calling 118969654c63SDerek Basehore * drm_connector_set_panel_orientation() or 119069654c63SDerek Basehore * drm_connector_set_panel_orientation_with_quirk() 1191bbeba09fSDaniel Vetter * 1192bbeba09fSDaniel Vetter * scaling mode: 1193bbeba09fSDaniel Vetter * This property defines how a non-native mode is upscaled to the native 1194bbeba09fSDaniel Vetter * mode of an LCD panel: 1195bbeba09fSDaniel Vetter * 1196bbeba09fSDaniel Vetter * None: 1197bbeba09fSDaniel Vetter * No upscaling happens, scaling is left to the panel. Not all 1198bbeba09fSDaniel Vetter * drivers expose this mode. 1199bbeba09fSDaniel Vetter * Full: 1200bbeba09fSDaniel Vetter * The output is upscaled to the full resolution of the panel, 1201bbeba09fSDaniel Vetter * ignoring the aspect ratio. 1202bbeba09fSDaniel Vetter * Center: 1203bbeba09fSDaniel Vetter * No upscaling happens, the output is centered within the native 1204bbeba09fSDaniel Vetter * resolution the panel. 1205bbeba09fSDaniel Vetter * Full aspect: 1206bbeba09fSDaniel Vetter * The output is upscaled to maximize either the width or height 1207bbeba09fSDaniel Vetter * while retaining the aspect ratio. 1208bbeba09fSDaniel Vetter * 1209bbeba09fSDaniel Vetter * This property should be set up by calling 1210bbeba09fSDaniel Vetter * drm_connector_attach_scaling_mode_property(). Note that drivers 1211bbeba09fSDaniel Vetter * can also expose this property to external outputs, in which case they 1212bbeba09fSDaniel Vetter * must support "None", which should be the default (since external screens 1213bbeba09fSDaniel Vetter * have a built-in scaler). 12144ada6f22SDaniel Vetter */ 12154ada6f22SDaniel Vetter 121652217195SDaniel Vetter int drm_connector_create_standard_properties(struct drm_device *dev) 121752217195SDaniel Vetter { 121852217195SDaniel Vetter struct drm_property *prop; 121952217195SDaniel Vetter 122052217195SDaniel Vetter prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | 122152217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 122252217195SDaniel Vetter "EDID", 0); 122352217195SDaniel Vetter if (!prop) 122452217195SDaniel Vetter return -ENOMEM; 122552217195SDaniel Vetter dev->mode_config.edid_property = prop; 122652217195SDaniel Vetter 122752217195SDaniel Vetter prop = drm_property_create_enum(dev, 0, 122852217195SDaniel Vetter "DPMS", drm_dpms_enum_list, 122952217195SDaniel Vetter ARRAY_SIZE(drm_dpms_enum_list)); 123052217195SDaniel Vetter if (!prop) 123152217195SDaniel Vetter return -ENOMEM; 123252217195SDaniel Vetter dev->mode_config.dpms_property = prop; 123352217195SDaniel Vetter 123452217195SDaniel Vetter prop = drm_property_create(dev, 123552217195SDaniel Vetter DRM_MODE_PROP_BLOB | 123652217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 123752217195SDaniel Vetter "PATH", 0); 123852217195SDaniel Vetter if (!prop) 123952217195SDaniel Vetter return -ENOMEM; 124052217195SDaniel Vetter dev->mode_config.path_property = prop; 124152217195SDaniel Vetter 124252217195SDaniel Vetter prop = drm_property_create(dev, 124352217195SDaniel Vetter DRM_MODE_PROP_BLOB | 124452217195SDaniel Vetter DRM_MODE_PROP_IMMUTABLE, 124552217195SDaniel Vetter "TILE", 0); 124652217195SDaniel Vetter if (!prop) 124752217195SDaniel Vetter return -ENOMEM; 124852217195SDaniel Vetter dev->mode_config.tile_property = prop; 124952217195SDaniel Vetter 125040ee6fbeSManasi Navare prop = drm_property_create_enum(dev, 0, "link-status", 125140ee6fbeSManasi Navare drm_link_status_enum_list, 125240ee6fbeSManasi Navare ARRAY_SIZE(drm_link_status_enum_list)); 125340ee6fbeSManasi Navare if (!prop) 125440ee6fbeSManasi Navare return -ENOMEM; 125540ee6fbeSManasi Navare dev->mode_config.link_status_property = prop; 125640ee6fbeSManasi Navare 125766660d4cSDave Airlie prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop"); 125866660d4cSDave Airlie if (!prop) 125966660d4cSDave Airlie return -ENOMEM; 126066660d4cSDave Airlie dev->mode_config.non_desktop_property = prop; 126166660d4cSDave Airlie 1262fbb5d035SUma Shankar prop = drm_property_create(dev, DRM_MODE_PROP_BLOB, 1263fbb5d035SUma Shankar "HDR_OUTPUT_METADATA", 0); 1264fbb5d035SUma Shankar if (!prop) 1265fbb5d035SUma Shankar return -ENOMEM; 1266fbb5d035SUma Shankar dev->mode_config.hdr_output_metadata_property = prop; 1267fbb5d035SUma Shankar 126852217195SDaniel Vetter return 0; 126952217195SDaniel Vetter } 127052217195SDaniel Vetter 127152217195SDaniel Vetter /** 127252217195SDaniel Vetter * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties 127352217195SDaniel Vetter * @dev: DRM device 127452217195SDaniel Vetter * 127552217195SDaniel Vetter * Called by a driver the first time a DVI-I connector is made. 127652217195SDaniel Vetter */ 127752217195SDaniel Vetter int drm_mode_create_dvi_i_properties(struct drm_device *dev) 127852217195SDaniel Vetter { 127952217195SDaniel Vetter struct drm_property *dvi_i_selector; 128052217195SDaniel Vetter struct drm_property *dvi_i_subconnector; 128152217195SDaniel Vetter 128252217195SDaniel Vetter if (dev->mode_config.dvi_i_select_subconnector_property) 128352217195SDaniel Vetter return 0; 128452217195SDaniel Vetter 128552217195SDaniel Vetter dvi_i_selector = 128652217195SDaniel Vetter drm_property_create_enum(dev, 0, 128752217195SDaniel Vetter "select subconnector", 128852217195SDaniel Vetter drm_dvi_i_select_enum_list, 128952217195SDaniel Vetter ARRAY_SIZE(drm_dvi_i_select_enum_list)); 129052217195SDaniel Vetter dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; 129152217195SDaniel Vetter 129252217195SDaniel Vetter dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 129352217195SDaniel Vetter "subconnector", 129452217195SDaniel Vetter drm_dvi_i_subconnector_enum_list, 129552217195SDaniel Vetter ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); 129652217195SDaniel Vetter dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; 129752217195SDaniel Vetter 129852217195SDaniel Vetter return 0; 129952217195SDaniel Vetter } 130052217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); 130152217195SDaniel Vetter 130252217195SDaniel Vetter /** 130350525c33SStanislav Lisovskiy * DOC: HDMI connector properties 130450525c33SStanislav Lisovskiy * 130550525c33SStanislav Lisovskiy * content type (HDMI specific): 130650525c33SStanislav Lisovskiy * Indicates content type setting to be used in HDMI infoframes to indicate 13071e55a53aSMatt Roper * content type for the external device, so that it adjusts its display 130850525c33SStanislav Lisovskiy * settings accordingly. 130950525c33SStanislav Lisovskiy * 131050525c33SStanislav Lisovskiy * The value of this property can be one of the following: 131150525c33SStanislav Lisovskiy * 131250525c33SStanislav Lisovskiy * No Data: 131350525c33SStanislav Lisovskiy * Content type is unknown 131450525c33SStanislav Lisovskiy * Graphics: 131550525c33SStanislav Lisovskiy * Content type is graphics 131650525c33SStanislav Lisovskiy * Photo: 131750525c33SStanislav Lisovskiy * Content type is photo 131850525c33SStanislav Lisovskiy * Cinema: 131950525c33SStanislav Lisovskiy * Content type is cinema 132050525c33SStanislav Lisovskiy * Game: 132150525c33SStanislav Lisovskiy * Content type is game 132250525c33SStanislav Lisovskiy * 132350525c33SStanislav Lisovskiy * Drivers can set up this property by calling 132450525c33SStanislav Lisovskiy * drm_connector_attach_content_type_property(). Decoding to 1325ba609631SDaniel Vetter * infoframe values is done through drm_hdmi_avi_infoframe_content_type(). 132650525c33SStanislav Lisovskiy */ 132750525c33SStanislav Lisovskiy 132850525c33SStanislav Lisovskiy /** 132950525c33SStanislav Lisovskiy * drm_connector_attach_content_type_property - attach content-type property 133050525c33SStanislav Lisovskiy * @connector: connector to attach content type property on. 133150525c33SStanislav Lisovskiy * 133250525c33SStanislav Lisovskiy * Called by a driver the first time a HDMI connector is made. 133350525c33SStanislav Lisovskiy */ 133450525c33SStanislav Lisovskiy int drm_connector_attach_content_type_property(struct drm_connector *connector) 133550525c33SStanislav Lisovskiy { 133650525c33SStanislav Lisovskiy if (!drm_mode_create_content_type_property(connector->dev)) 133750525c33SStanislav Lisovskiy drm_object_attach_property(&connector->base, 133850525c33SStanislav Lisovskiy connector->dev->mode_config.content_type_property, 133950525c33SStanislav Lisovskiy DRM_MODE_CONTENT_TYPE_NO_DATA); 134050525c33SStanislav Lisovskiy return 0; 134150525c33SStanislav Lisovskiy } 134250525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_connector_attach_content_type_property); 134350525c33SStanislav Lisovskiy 134450525c33SStanislav Lisovskiy 134550525c33SStanislav Lisovskiy /** 134650525c33SStanislav Lisovskiy * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe 134750525c33SStanislav Lisovskiy * content type information, based 134850525c33SStanislav Lisovskiy * on correspondent DRM property. 134950525c33SStanislav Lisovskiy * @frame: HDMI AVI infoframe 135050525c33SStanislav Lisovskiy * @conn_state: DRM display connector state 135150525c33SStanislav Lisovskiy * 135250525c33SStanislav Lisovskiy */ 135350525c33SStanislav Lisovskiy void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame, 135450525c33SStanislav Lisovskiy const struct drm_connector_state *conn_state) 135550525c33SStanislav Lisovskiy { 135650525c33SStanislav Lisovskiy switch (conn_state->content_type) { 135750525c33SStanislav Lisovskiy case DRM_MODE_CONTENT_TYPE_GRAPHICS: 135850525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS; 135950525c33SStanislav Lisovskiy break; 136050525c33SStanislav Lisovskiy case DRM_MODE_CONTENT_TYPE_CINEMA: 136150525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_CINEMA; 136250525c33SStanislav Lisovskiy break; 136350525c33SStanislav Lisovskiy case DRM_MODE_CONTENT_TYPE_GAME: 136450525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_GAME; 136550525c33SStanislav Lisovskiy break; 136650525c33SStanislav Lisovskiy case DRM_MODE_CONTENT_TYPE_PHOTO: 136750525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_PHOTO; 136850525c33SStanislav Lisovskiy break; 136950525c33SStanislav Lisovskiy default: 137050525c33SStanislav Lisovskiy /* Graphics is the default(0) */ 137150525c33SStanislav Lisovskiy frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS; 137250525c33SStanislav Lisovskiy } 137350525c33SStanislav Lisovskiy 137450525c33SStanislav Lisovskiy frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA; 137550525c33SStanislav Lisovskiy } 137650525c33SStanislav Lisovskiy EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type); 137750525c33SStanislav Lisovskiy 137850525c33SStanislav Lisovskiy /** 13796c4f52dcSBoris Brezillon * drm_mode_attach_tv_margin_properties - attach TV connector margin properties 13806c4f52dcSBoris Brezillon * @connector: DRM connector 13816c4f52dcSBoris Brezillon * 13826c4f52dcSBoris Brezillon * Called by a driver when it needs to attach TV margin props to a connector. 13836c4f52dcSBoris Brezillon * Typically used on SDTV and HDMI connectors. 13846c4f52dcSBoris Brezillon */ 13856c4f52dcSBoris Brezillon void drm_connector_attach_tv_margin_properties(struct drm_connector *connector) 13866c4f52dcSBoris Brezillon { 13876c4f52dcSBoris Brezillon struct drm_device *dev = connector->dev; 13886c4f52dcSBoris Brezillon 13896c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 13906c4f52dcSBoris Brezillon dev->mode_config.tv_left_margin_property, 13916c4f52dcSBoris Brezillon 0); 13926c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 13936c4f52dcSBoris Brezillon dev->mode_config.tv_right_margin_property, 13946c4f52dcSBoris Brezillon 0); 13956c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 13966c4f52dcSBoris Brezillon dev->mode_config.tv_top_margin_property, 13976c4f52dcSBoris Brezillon 0); 13986c4f52dcSBoris Brezillon drm_object_attach_property(&connector->base, 13996c4f52dcSBoris Brezillon dev->mode_config.tv_bottom_margin_property, 14006c4f52dcSBoris Brezillon 0); 14016c4f52dcSBoris Brezillon } 14026c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties); 14036c4f52dcSBoris Brezillon 14046c4f52dcSBoris Brezillon /** 14056c4f52dcSBoris Brezillon * drm_mode_create_tv_margin_properties - create TV connector margin properties 14066c4f52dcSBoris Brezillon * @dev: DRM device 14076c4f52dcSBoris Brezillon * 14086c4f52dcSBoris Brezillon * Called by a driver's HDMI connector initialization routine, this function 14096c4f52dcSBoris Brezillon * creates the TV margin properties for a given device. No need to call this 14106c4f52dcSBoris Brezillon * function for an SDTV connector, it's already called from 14116c4f52dcSBoris Brezillon * drm_mode_create_tv_properties(). 14126c4f52dcSBoris Brezillon */ 14136c4f52dcSBoris Brezillon int drm_mode_create_tv_margin_properties(struct drm_device *dev) 14146c4f52dcSBoris Brezillon { 14156c4f52dcSBoris Brezillon if (dev->mode_config.tv_left_margin_property) 14166c4f52dcSBoris Brezillon return 0; 14176c4f52dcSBoris Brezillon 14186c4f52dcSBoris Brezillon dev->mode_config.tv_left_margin_property = 14196c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "left margin", 0, 100); 14206c4f52dcSBoris Brezillon if (!dev->mode_config.tv_left_margin_property) 14216c4f52dcSBoris Brezillon return -ENOMEM; 14226c4f52dcSBoris Brezillon 14236c4f52dcSBoris Brezillon dev->mode_config.tv_right_margin_property = 14246c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "right margin", 0, 100); 14256c4f52dcSBoris Brezillon if (!dev->mode_config.tv_right_margin_property) 14266c4f52dcSBoris Brezillon return -ENOMEM; 14276c4f52dcSBoris Brezillon 14286c4f52dcSBoris Brezillon dev->mode_config.tv_top_margin_property = 14296c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "top margin", 0, 100); 14306c4f52dcSBoris Brezillon if (!dev->mode_config.tv_top_margin_property) 14316c4f52dcSBoris Brezillon return -ENOMEM; 14326c4f52dcSBoris Brezillon 14336c4f52dcSBoris Brezillon dev->mode_config.tv_bottom_margin_property = 14346c4f52dcSBoris Brezillon drm_property_create_range(dev, 0, "bottom margin", 0, 100); 14356c4f52dcSBoris Brezillon if (!dev->mode_config.tv_bottom_margin_property) 14366c4f52dcSBoris Brezillon return -ENOMEM; 14376c4f52dcSBoris Brezillon 14386c4f52dcSBoris Brezillon return 0; 14396c4f52dcSBoris Brezillon } 14406c4f52dcSBoris Brezillon EXPORT_SYMBOL(drm_mode_create_tv_margin_properties); 14416c4f52dcSBoris Brezillon 14426c4f52dcSBoris Brezillon /** 1443eda6887fSBoris Brezillon * drm_mode_create_tv_properties - create TV specific connector properties 144452217195SDaniel Vetter * @dev: DRM device 144552217195SDaniel Vetter * @num_modes: number of different TV formats (modes) supported 144652217195SDaniel Vetter * @modes: array of pointers to strings containing name of each format 144752217195SDaniel Vetter * 144852217195SDaniel Vetter * Called by a driver's TV initialization routine, this function creates 144952217195SDaniel Vetter * the TV specific connector properties for a given device. Caller is 145052217195SDaniel Vetter * responsible for allocating a list of format names and passing them to 145152217195SDaniel Vetter * this routine. 145252217195SDaniel Vetter */ 145352217195SDaniel Vetter int drm_mode_create_tv_properties(struct drm_device *dev, 145452217195SDaniel Vetter unsigned int num_modes, 145552217195SDaniel Vetter const char * const modes[]) 145652217195SDaniel Vetter { 145752217195SDaniel Vetter struct drm_property *tv_selector; 145852217195SDaniel Vetter struct drm_property *tv_subconnector; 145952217195SDaniel Vetter unsigned int i; 146052217195SDaniel Vetter 146152217195SDaniel Vetter if (dev->mode_config.tv_select_subconnector_property) 146252217195SDaniel Vetter return 0; 146352217195SDaniel Vetter 146452217195SDaniel Vetter /* 146552217195SDaniel Vetter * Basic connector properties 146652217195SDaniel Vetter */ 146752217195SDaniel Vetter tv_selector = drm_property_create_enum(dev, 0, 146852217195SDaniel Vetter "select subconnector", 146952217195SDaniel Vetter drm_tv_select_enum_list, 147052217195SDaniel Vetter ARRAY_SIZE(drm_tv_select_enum_list)); 147152217195SDaniel Vetter if (!tv_selector) 147252217195SDaniel Vetter goto nomem; 147352217195SDaniel Vetter 147452217195SDaniel Vetter dev->mode_config.tv_select_subconnector_property = tv_selector; 147552217195SDaniel Vetter 147652217195SDaniel Vetter tv_subconnector = 147752217195SDaniel Vetter drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 147852217195SDaniel Vetter "subconnector", 147952217195SDaniel Vetter drm_tv_subconnector_enum_list, 148052217195SDaniel Vetter ARRAY_SIZE(drm_tv_subconnector_enum_list)); 148152217195SDaniel Vetter if (!tv_subconnector) 148252217195SDaniel Vetter goto nomem; 148352217195SDaniel Vetter dev->mode_config.tv_subconnector_property = tv_subconnector; 148452217195SDaniel Vetter 148552217195SDaniel Vetter /* 148652217195SDaniel Vetter * Other, TV specific properties: margins & TV modes. 148752217195SDaniel Vetter */ 14886c4f52dcSBoris Brezillon if (drm_mode_create_tv_margin_properties(dev)) 148952217195SDaniel Vetter goto nomem; 149052217195SDaniel Vetter 149152217195SDaniel Vetter dev->mode_config.tv_mode_property = 149252217195SDaniel Vetter drm_property_create(dev, DRM_MODE_PROP_ENUM, 149352217195SDaniel Vetter "mode", num_modes); 149452217195SDaniel Vetter if (!dev->mode_config.tv_mode_property) 149552217195SDaniel Vetter goto nomem; 149652217195SDaniel Vetter 149752217195SDaniel Vetter for (i = 0; i < num_modes; i++) 149830e9db6dSVille Syrjälä drm_property_add_enum(dev->mode_config.tv_mode_property, 149952217195SDaniel Vetter i, modes[i]); 150052217195SDaniel Vetter 150152217195SDaniel Vetter dev->mode_config.tv_brightness_property = 150252217195SDaniel Vetter drm_property_create_range(dev, 0, "brightness", 0, 100); 150352217195SDaniel Vetter if (!dev->mode_config.tv_brightness_property) 150452217195SDaniel Vetter goto nomem; 150552217195SDaniel Vetter 150652217195SDaniel Vetter dev->mode_config.tv_contrast_property = 150752217195SDaniel Vetter drm_property_create_range(dev, 0, "contrast", 0, 100); 150852217195SDaniel Vetter if (!dev->mode_config.tv_contrast_property) 150952217195SDaniel Vetter goto nomem; 151052217195SDaniel Vetter 151152217195SDaniel Vetter dev->mode_config.tv_flicker_reduction_property = 151252217195SDaniel Vetter drm_property_create_range(dev, 0, "flicker reduction", 0, 100); 151352217195SDaniel Vetter if (!dev->mode_config.tv_flicker_reduction_property) 151452217195SDaniel Vetter goto nomem; 151552217195SDaniel Vetter 151652217195SDaniel Vetter dev->mode_config.tv_overscan_property = 151752217195SDaniel Vetter drm_property_create_range(dev, 0, "overscan", 0, 100); 151852217195SDaniel Vetter if (!dev->mode_config.tv_overscan_property) 151952217195SDaniel Vetter goto nomem; 152052217195SDaniel Vetter 152152217195SDaniel Vetter dev->mode_config.tv_saturation_property = 152252217195SDaniel Vetter drm_property_create_range(dev, 0, "saturation", 0, 100); 152352217195SDaniel Vetter if (!dev->mode_config.tv_saturation_property) 152452217195SDaniel Vetter goto nomem; 152552217195SDaniel Vetter 152652217195SDaniel Vetter dev->mode_config.tv_hue_property = 152752217195SDaniel Vetter drm_property_create_range(dev, 0, "hue", 0, 100); 152852217195SDaniel Vetter if (!dev->mode_config.tv_hue_property) 152952217195SDaniel Vetter goto nomem; 153052217195SDaniel Vetter 153152217195SDaniel Vetter return 0; 153252217195SDaniel Vetter nomem: 153352217195SDaniel Vetter return -ENOMEM; 153452217195SDaniel Vetter } 153552217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tv_properties); 153652217195SDaniel Vetter 153752217195SDaniel Vetter /** 153852217195SDaniel Vetter * drm_mode_create_scaling_mode_property - create scaling mode property 153952217195SDaniel Vetter * @dev: DRM device 154052217195SDaniel Vetter * 154152217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 154252217195SDaniel Vetter * connectors. 15438f6e1e22SMaarten Lankhorst * 15448f6e1e22SMaarten Lankhorst * Atomic drivers should use drm_connector_attach_scaling_mode_property() 15458f6e1e22SMaarten Lankhorst * instead to correctly assign &drm_connector_state.picture_aspect_ratio 15468f6e1e22SMaarten Lankhorst * in the atomic state. 154752217195SDaniel Vetter */ 154852217195SDaniel Vetter int drm_mode_create_scaling_mode_property(struct drm_device *dev) 154952217195SDaniel Vetter { 155052217195SDaniel Vetter struct drm_property *scaling_mode; 155152217195SDaniel Vetter 155252217195SDaniel Vetter if (dev->mode_config.scaling_mode_property) 155352217195SDaniel Vetter return 0; 155452217195SDaniel Vetter 155552217195SDaniel Vetter scaling_mode = 155652217195SDaniel Vetter drm_property_create_enum(dev, 0, "scaling mode", 155752217195SDaniel Vetter drm_scaling_mode_enum_list, 155852217195SDaniel Vetter ARRAY_SIZE(drm_scaling_mode_enum_list)); 155952217195SDaniel Vetter 156052217195SDaniel Vetter dev->mode_config.scaling_mode_property = scaling_mode; 156152217195SDaniel Vetter 156252217195SDaniel Vetter return 0; 156352217195SDaniel Vetter } 156452217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); 156552217195SDaniel Vetter 156652217195SDaniel Vetter /** 1567ab7a664fSNicholas Kazlauskas * DOC: Variable refresh properties 1568ab7a664fSNicholas Kazlauskas * 1569ab7a664fSNicholas Kazlauskas * Variable refresh rate capable displays can dynamically adjust their 1570ab7a664fSNicholas Kazlauskas * refresh rate by extending the duration of their vertical front porch 1571ab7a664fSNicholas Kazlauskas * until page flip or timeout occurs. This can reduce or remove stuttering 1572ab7a664fSNicholas Kazlauskas * and latency in scenarios where the page flip does not align with the 1573ab7a664fSNicholas Kazlauskas * vblank interval. 1574ab7a664fSNicholas Kazlauskas * 1575ab7a664fSNicholas Kazlauskas * An example scenario would be an application flipping at a constant rate 1576ab7a664fSNicholas Kazlauskas * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank 1577ab7a664fSNicholas Kazlauskas * interval and the same contents will be displayed twice. This can be 1578ab7a664fSNicholas Kazlauskas * observed as stuttering for content with motion. 1579ab7a664fSNicholas Kazlauskas * 1580ab7a664fSNicholas Kazlauskas * If variable refresh rate was active on a display that supported a 1581ab7a664fSNicholas Kazlauskas * variable refresh range from 35Hz to 60Hz no stuttering would be observable 1582ab7a664fSNicholas Kazlauskas * for the example scenario. The minimum supported variable refresh rate of 1583ab7a664fSNicholas Kazlauskas * 35Hz is below the page flip frequency and the vertical front porch can 1584ab7a664fSNicholas Kazlauskas * be extended until the page flip occurs. The vblank interval will be 1585ab7a664fSNicholas Kazlauskas * directly aligned to the page flip rate. 1586ab7a664fSNicholas Kazlauskas * 1587ab7a664fSNicholas Kazlauskas * Not all userspace content is suitable for use with variable refresh rate. 1588ab7a664fSNicholas Kazlauskas * Large and frequent changes in vertical front porch duration may worsen 1589ab7a664fSNicholas Kazlauskas * perceived stuttering for input sensitive applications. 1590ab7a664fSNicholas Kazlauskas * 1591ab7a664fSNicholas Kazlauskas * Panel brightness will also vary with vertical front porch duration. Some 1592ab7a664fSNicholas Kazlauskas * panels may have noticeable differences in brightness between the minimum 1593ab7a664fSNicholas Kazlauskas * vertical front porch duration and the maximum vertical front porch duration. 1594ab7a664fSNicholas Kazlauskas * Large and frequent changes in vertical front porch duration may produce 1595ab7a664fSNicholas Kazlauskas * observable flickering for such panels. 1596ab7a664fSNicholas Kazlauskas * 1597ab7a664fSNicholas Kazlauskas * Userspace control for variable refresh rate is supported via properties 1598ab7a664fSNicholas Kazlauskas * on the &drm_connector and &drm_crtc objects. 1599ab7a664fSNicholas Kazlauskas * 1600ab7a664fSNicholas Kazlauskas * "vrr_capable": 1601ab7a664fSNicholas Kazlauskas * Optional &drm_connector boolean property that drivers should attach 1602ab7a664fSNicholas Kazlauskas * with drm_connector_attach_vrr_capable_property() on connectors that 1603ab7a664fSNicholas Kazlauskas * could support variable refresh rates. Drivers should update the 1604ab7a664fSNicholas Kazlauskas * property value by calling drm_connector_set_vrr_capable_property(). 1605ab7a664fSNicholas Kazlauskas * 1606ab7a664fSNicholas Kazlauskas * Absence of the property should indicate absence of support. 1607ab7a664fSNicholas Kazlauskas * 160877086014SDaniel Vetter * "VRR_ENABLED": 1609ab7a664fSNicholas Kazlauskas * Default &drm_crtc boolean property that notifies the driver that the 1610ab7a664fSNicholas Kazlauskas * content on the CRTC is suitable for variable refresh rate presentation. 1611ab7a664fSNicholas Kazlauskas * The driver will take this property as a hint to enable variable 1612ab7a664fSNicholas Kazlauskas * refresh rate support if the receiver supports it, ie. if the 1613ab7a664fSNicholas Kazlauskas * "vrr_capable" property is true on the &drm_connector object. The 1614ab7a664fSNicholas Kazlauskas * vertical front porch duration will be extended until page-flip or 1615ab7a664fSNicholas Kazlauskas * timeout when enabled. 1616ab7a664fSNicholas Kazlauskas * 1617ab7a664fSNicholas Kazlauskas * The minimum vertical front porch duration is defined as the vertical 1618ab7a664fSNicholas Kazlauskas * front porch duration for the current mode. 1619ab7a664fSNicholas Kazlauskas * 1620ab7a664fSNicholas Kazlauskas * The maximum vertical front porch duration is greater than or equal to 1621ab7a664fSNicholas Kazlauskas * the minimum vertical front porch duration. The duration is derived 1622ab7a664fSNicholas Kazlauskas * from the minimum supported variable refresh rate for the connector. 1623ab7a664fSNicholas Kazlauskas * 1624ab7a664fSNicholas Kazlauskas * The driver may place further restrictions within these minimum 1625ab7a664fSNicholas Kazlauskas * and maximum bounds. 1626ab7a664fSNicholas Kazlauskas */ 1627ab7a664fSNicholas Kazlauskas 1628ab7a664fSNicholas Kazlauskas /** 1629ba1b0f6cSNicholas Kazlauskas * drm_connector_attach_vrr_capable_property - creates the 1630ba1b0f6cSNicholas Kazlauskas * vrr_capable property 1631ba1b0f6cSNicholas Kazlauskas * @connector: connector to create the vrr_capable property on. 1632ba1b0f6cSNicholas Kazlauskas * 1633ba1b0f6cSNicholas Kazlauskas * This is used by atomic drivers to add support for querying 1634ba1b0f6cSNicholas Kazlauskas * variable refresh rate capability for a connector. 1635ba1b0f6cSNicholas Kazlauskas * 1636ba1b0f6cSNicholas Kazlauskas * Returns: 1637*84e543bcSAntonio Borneo * Zero on success, negative errno on failure. 1638ba1b0f6cSNicholas Kazlauskas */ 1639ba1b0f6cSNicholas Kazlauskas int drm_connector_attach_vrr_capable_property( 1640ba1b0f6cSNicholas Kazlauskas struct drm_connector *connector) 1641ba1b0f6cSNicholas Kazlauskas { 1642ba1b0f6cSNicholas Kazlauskas struct drm_device *dev = connector->dev; 1643ba1b0f6cSNicholas Kazlauskas struct drm_property *prop; 1644ba1b0f6cSNicholas Kazlauskas 1645ba1b0f6cSNicholas Kazlauskas if (!connector->vrr_capable_property) { 1646ba1b0f6cSNicholas Kazlauskas prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, 1647ba1b0f6cSNicholas Kazlauskas "vrr_capable"); 1648ba1b0f6cSNicholas Kazlauskas if (!prop) 1649ba1b0f6cSNicholas Kazlauskas return -ENOMEM; 1650ba1b0f6cSNicholas Kazlauskas 1651ba1b0f6cSNicholas Kazlauskas connector->vrr_capable_property = prop; 1652ba1b0f6cSNicholas Kazlauskas drm_object_attach_property(&connector->base, prop, 0); 1653ba1b0f6cSNicholas Kazlauskas } 1654ba1b0f6cSNicholas Kazlauskas 1655ba1b0f6cSNicholas Kazlauskas return 0; 1656ba1b0f6cSNicholas Kazlauskas } 1657ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property); 1658ba1b0f6cSNicholas Kazlauskas 1659ba1b0f6cSNicholas Kazlauskas /** 16608f6e1e22SMaarten Lankhorst * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property 16618f6e1e22SMaarten Lankhorst * @connector: connector to attach scaling mode property on. 16628f6e1e22SMaarten Lankhorst * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*). 16638f6e1e22SMaarten Lankhorst * 16648f6e1e22SMaarten Lankhorst * This is used to add support for scaling mode to atomic drivers. 16658f6e1e22SMaarten Lankhorst * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio 16668f6e1e22SMaarten Lankhorst * and can be used from &drm_connector_helper_funcs->atomic_check for validation. 16678f6e1e22SMaarten Lankhorst * 16688f6e1e22SMaarten Lankhorst * This is the atomic version of drm_mode_create_scaling_mode_property(). 16698f6e1e22SMaarten Lankhorst * 16708f6e1e22SMaarten Lankhorst * Returns: 16718f6e1e22SMaarten Lankhorst * Zero on success, negative errno on failure. 16728f6e1e22SMaarten Lankhorst */ 16738f6e1e22SMaarten Lankhorst int drm_connector_attach_scaling_mode_property(struct drm_connector *connector, 16748f6e1e22SMaarten Lankhorst u32 scaling_mode_mask) 16758f6e1e22SMaarten Lankhorst { 16768f6e1e22SMaarten Lankhorst struct drm_device *dev = connector->dev; 16778f6e1e22SMaarten Lankhorst struct drm_property *scaling_mode_property; 167830e9db6dSVille Syrjälä int i; 16798f6e1e22SMaarten Lankhorst const unsigned valid_scaling_mode_mask = 16808f6e1e22SMaarten Lankhorst (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1; 16818f6e1e22SMaarten Lankhorst 16828f6e1e22SMaarten Lankhorst if (WARN_ON(hweight32(scaling_mode_mask) < 2 || 16838f6e1e22SMaarten Lankhorst scaling_mode_mask & ~valid_scaling_mode_mask)) 16848f6e1e22SMaarten Lankhorst return -EINVAL; 16858f6e1e22SMaarten Lankhorst 16868f6e1e22SMaarten Lankhorst scaling_mode_property = 16878f6e1e22SMaarten Lankhorst drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode", 16888f6e1e22SMaarten Lankhorst hweight32(scaling_mode_mask)); 16898f6e1e22SMaarten Lankhorst 16908f6e1e22SMaarten Lankhorst if (!scaling_mode_property) 16918f6e1e22SMaarten Lankhorst return -ENOMEM; 16928f6e1e22SMaarten Lankhorst 16938f6e1e22SMaarten Lankhorst for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) { 16948f6e1e22SMaarten Lankhorst int ret; 16958f6e1e22SMaarten Lankhorst 16968f6e1e22SMaarten Lankhorst if (!(BIT(i) & scaling_mode_mask)) 16978f6e1e22SMaarten Lankhorst continue; 16988f6e1e22SMaarten Lankhorst 169930e9db6dSVille Syrjälä ret = drm_property_add_enum(scaling_mode_property, 17008f6e1e22SMaarten Lankhorst drm_scaling_mode_enum_list[i].type, 17018f6e1e22SMaarten Lankhorst drm_scaling_mode_enum_list[i].name); 17028f6e1e22SMaarten Lankhorst 17038f6e1e22SMaarten Lankhorst if (ret) { 17048f6e1e22SMaarten Lankhorst drm_property_destroy(dev, scaling_mode_property); 17058f6e1e22SMaarten Lankhorst 17068f6e1e22SMaarten Lankhorst return ret; 17078f6e1e22SMaarten Lankhorst } 17088f6e1e22SMaarten Lankhorst } 17098f6e1e22SMaarten Lankhorst 17108f6e1e22SMaarten Lankhorst drm_object_attach_property(&connector->base, 17118f6e1e22SMaarten Lankhorst scaling_mode_property, 0); 17128f6e1e22SMaarten Lankhorst 17138f6e1e22SMaarten Lankhorst connector->scaling_mode_property = scaling_mode_property; 17148f6e1e22SMaarten Lankhorst 17158f6e1e22SMaarten Lankhorst return 0; 17168f6e1e22SMaarten Lankhorst } 17178f6e1e22SMaarten Lankhorst EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property); 17188f6e1e22SMaarten Lankhorst 17198f6e1e22SMaarten Lankhorst /** 172052217195SDaniel Vetter * drm_mode_create_aspect_ratio_property - create aspect ratio property 172152217195SDaniel Vetter * @dev: DRM device 172252217195SDaniel Vetter * 172352217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 172452217195SDaniel Vetter * connectors. 172552217195SDaniel Vetter * 172652217195SDaniel Vetter * Returns: 172752217195SDaniel Vetter * Zero on success, negative errno on failure. 172852217195SDaniel Vetter */ 172952217195SDaniel Vetter int drm_mode_create_aspect_ratio_property(struct drm_device *dev) 173052217195SDaniel Vetter { 173152217195SDaniel Vetter if (dev->mode_config.aspect_ratio_property) 173252217195SDaniel Vetter return 0; 173352217195SDaniel Vetter 173452217195SDaniel Vetter dev->mode_config.aspect_ratio_property = 173552217195SDaniel Vetter drm_property_create_enum(dev, 0, "aspect ratio", 173652217195SDaniel Vetter drm_aspect_ratio_enum_list, 173752217195SDaniel Vetter ARRAY_SIZE(drm_aspect_ratio_enum_list)); 173852217195SDaniel Vetter 173952217195SDaniel Vetter if (dev->mode_config.aspect_ratio_property == NULL) 174052217195SDaniel Vetter return -ENOMEM; 174152217195SDaniel Vetter 174252217195SDaniel Vetter return 0; 174352217195SDaniel Vetter } 174452217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); 174552217195SDaniel Vetter 174652217195SDaniel Vetter /** 1747d2c6a405SUma Shankar * DOC: standard connector properties 1748d2c6a405SUma Shankar * 1749d2c6a405SUma Shankar * Colorspace: 1750d2c6a405SUma Shankar * This property helps select a suitable colorspace based on the sink 1751d2c6a405SUma Shankar * capability. Modern sink devices support wider gamut like BT2020. 1752d2c6a405SUma Shankar * This helps switch to BT2020 mode if the BT2020 encoded video stream 1753d2c6a405SUma Shankar * is being played by the user, same for any other colorspace. Thereby 1754d2c6a405SUma Shankar * giving a good visual experience to users. 1755d2c6a405SUma Shankar * 1756d2c6a405SUma Shankar * The expectation from userspace is that it should parse the EDID 1757d2c6a405SUma Shankar * and get supported colorspaces. Use this property and switch to the 1758d2c6a405SUma Shankar * one supported. Sink supported colorspaces should be retrieved by 1759d2c6a405SUma Shankar * userspace from EDID and driver will not explicitly expose them. 1760d2c6a405SUma Shankar * 1761d2c6a405SUma Shankar * Basically the expectation from userspace is: 1762d2c6a405SUma Shankar * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink 1763d2c6a405SUma Shankar * colorspace 1764d2c6a405SUma Shankar * - Set this new property to let the sink know what it 1765d2c6a405SUma Shankar * converted the CRTC output to. 1766d2c6a405SUma Shankar * - This property is just to inform sink what colorspace 1767d2c6a405SUma Shankar * source is trying to drive. 1768d2c6a405SUma Shankar * 17698806cd3aSGwan-gyeong Mun * Because between HDMI and DP have different colorspaces, 177045cf0e91SGwan-gyeong Mun * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and 177145cf0e91SGwan-gyeong Mun * drm_mode_create_dp_colorspace_property() is used for DP connector. 1772d2c6a405SUma Shankar */ 17738806cd3aSGwan-gyeong Mun 17748806cd3aSGwan-gyeong Mun /** 17758806cd3aSGwan-gyeong Mun * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property 17768806cd3aSGwan-gyeong Mun * @connector: connector to create the Colorspace property on. 17778806cd3aSGwan-gyeong Mun * 17788806cd3aSGwan-gyeong Mun * Called by a driver the first time it's needed, must be attached to desired 17798806cd3aSGwan-gyeong Mun * HDMI connectors. 17808806cd3aSGwan-gyeong Mun * 17818806cd3aSGwan-gyeong Mun * Returns: 1782*84e543bcSAntonio Borneo * Zero on success, negative errno on failure. 17838806cd3aSGwan-gyeong Mun */ 17848806cd3aSGwan-gyeong Mun int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector) 1785d2c6a405SUma Shankar { 1786d2c6a405SUma Shankar struct drm_device *dev = connector->dev; 1787d2c6a405SUma Shankar 17888806cd3aSGwan-gyeong Mun if (connector->colorspace_property) 17898806cd3aSGwan-gyeong Mun return 0; 17908806cd3aSGwan-gyeong Mun 17918806cd3aSGwan-gyeong Mun connector->colorspace_property = 17928806cd3aSGwan-gyeong Mun drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace", 1793d2c6a405SUma Shankar hdmi_colorspaces, 1794d2c6a405SUma Shankar ARRAY_SIZE(hdmi_colorspaces)); 17958806cd3aSGwan-gyeong Mun 17968806cd3aSGwan-gyeong Mun if (!connector->colorspace_property) 1797d2c6a405SUma Shankar return -ENOMEM; 1798d2c6a405SUma Shankar 1799d2c6a405SUma Shankar return 0; 1800d2c6a405SUma Shankar } 18018806cd3aSGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property); 1802d2c6a405SUma Shankar 1803d2c6a405SUma Shankar /** 180445cf0e91SGwan-gyeong Mun * drm_mode_create_dp_colorspace_property - create dp colorspace property 180545cf0e91SGwan-gyeong Mun * @connector: connector to create the Colorspace property on. 180645cf0e91SGwan-gyeong Mun * 180745cf0e91SGwan-gyeong Mun * Called by a driver the first time it's needed, must be attached to desired 180845cf0e91SGwan-gyeong Mun * DP connectors. 180945cf0e91SGwan-gyeong Mun * 181045cf0e91SGwan-gyeong Mun * Returns: 1811*84e543bcSAntonio Borneo * Zero on success, negative errno on failure. 181245cf0e91SGwan-gyeong Mun */ 181345cf0e91SGwan-gyeong Mun int drm_mode_create_dp_colorspace_property(struct drm_connector *connector) 181445cf0e91SGwan-gyeong Mun { 181545cf0e91SGwan-gyeong Mun struct drm_device *dev = connector->dev; 181645cf0e91SGwan-gyeong Mun 181745cf0e91SGwan-gyeong Mun if (connector->colorspace_property) 181845cf0e91SGwan-gyeong Mun return 0; 181945cf0e91SGwan-gyeong Mun 182045cf0e91SGwan-gyeong Mun connector->colorspace_property = 182145cf0e91SGwan-gyeong Mun drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace", 182245cf0e91SGwan-gyeong Mun dp_colorspaces, 182345cf0e91SGwan-gyeong Mun ARRAY_SIZE(dp_colorspaces)); 182445cf0e91SGwan-gyeong Mun 182545cf0e91SGwan-gyeong Mun if (!connector->colorspace_property) 182645cf0e91SGwan-gyeong Mun return -ENOMEM; 182745cf0e91SGwan-gyeong Mun 182845cf0e91SGwan-gyeong Mun return 0; 182945cf0e91SGwan-gyeong Mun } 183045cf0e91SGwan-gyeong Mun EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property); 183152217195SDaniel Vetter 183297e14fbeSDaniel Vetter /** 183352217195SDaniel Vetter * drm_mode_create_content_type_property - create content type property 183452217195SDaniel Vetter * @dev: DRM device 183597e14fbeSDaniel Vetter * 183652217195SDaniel Vetter * Called by a driver the first time it's needed, must be attached to desired 183752217195SDaniel Vetter * connectors. 183852217195SDaniel Vetter * 183952217195SDaniel Vetter * Returns: 184052217195SDaniel Vetter * Zero on success, negative errno on failure. 184152217195SDaniel Vetter */ 184252217195SDaniel Vetter int drm_mode_create_content_type_property(struct drm_device *dev) 184352217195SDaniel Vetter { 184452217195SDaniel Vetter if (dev->mode_config.content_type_property) 184597e14fbeSDaniel Vetter return 0; 184652217195SDaniel Vetter 184752217195SDaniel Vetter dev->mode_config.content_type_property = 184852217195SDaniel Vetter drm_property_create_enum(dev, 0, "content type", 184952217195SDaniel Vetter drm_content_type_enum_list, 185052217195SDaniel Vetter ARRAY_SIZE(drm_content_type_enum_list)); 185152217195SDaniel Vetter 185252217195SDaniel Vetter if (dev->mode_config.content_type_property == NULL) 185352217195SDaniel Vetter return -ENOMEM; 185452217195SDaniel Vetter 185552217195SDaniel Vetter return 0; 185652217195SDaniel Vetter } 185752217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_content_type_property); 185852217195SDaniel Vetter 185952217195SDaniel Vetter /** 186052217195SDaniel Vetter * drm_mode_create_suggested_offset_properties - create suggests offset properties 186152217195SDaniel Vetter * @dev: DRM device 186252217195SDaniel Vetter * 1863*84e543bcSAntonio Borneo * Create the suggested x/y offset property for connectors. 186452217195SDaniel Vetter */ 186552217195SDaniel Vetter int drm_mode_create_suggested_offset_properties(struct drm_device *dev) 186652217195SDaniel Vetter { 186752217195SDaniel Vetter if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) 186852217195SDaniel Vetter return 0; 186952217195SDaniel Vetter 187052217195SDaniel Vetter dev->mode_config.suggested_x_property = 187152217195SDaniel Vetter drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); 187252217195SDaniel Vetter 187352217195SDaniel Vetter dev->mode_config.suggested_y_property = 187452217195SDaniel Vetter drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); 187552217195SDaniel Vetter 187652217195SDaniel Vetter if (dev->mode_config.suggested_x_property == NULL || 187752217195SDaniel Vetter dev->mode_config.suggested_y_property == NULL) 187852217195SDaniel Vetter return -ENOMEM; 187952217195SDaniel Vetter return 0; 188052217195SDaniel Vetter } 188152217195SDaniel Vetter EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); 188252217195SDaniel Vetter 188352217195SDaniel Vetter /** 188452217195SDaniel Vetter * drm_connector_set_path_property - set tile property on connector 188552217195SDaniel Vetter * @connector: connector to set property on. 188652217195SDaniel Vetter * @path: path to use for property; must not be NULL. 188752217195SDaniel Vetter * 188852217195SDaniel Vetter * This creates a property to expose to userspace to specify a 188952217195SDaniel Vetter * connector path. This is mainly used for DisplayPort MST where 189052217195SDaniel Vetter * connectors have a topology and we want to allow userspace to give 189152217195SDaniel Vetter * them more meaningful names. 189252217195SDaniel Vetter * 189352217195SDaniel Vetter * Returns: 189452217195SDaniel Vetter * Zero on success, negative errno on failure. 189552217195SDaniel Vetter */ 189652217195SDaniel Vetter int drm_connector_set_path_property(struct drm_connector *connector, 189752217195SDaniel Vetter const char *path) 189852217195SDaniel Vetter { 189952217195SDaniel Vetter struct drm_device *dev = connector->dev; 190052217195SDaniel Vetter int ret; 190152217195SDaniel Vetter 190252217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 190352217195SDaniel Vetter &connector->path_blob_ptr, 190452217195SDaniel Vetter strlen(path) + 1, 190552217195SDaniel Vetter path, 190652217195SDaniel Vetter &connector->base, 190752217195SDaniel Vetter dev->mode_config.path_property); 190852217195SDaniel Vetter return ret; 190952217195SDaniel Vetter } 191052217195SDaniel Vetter EXPORT_SYMBOL(drm_connector_set_path_property); 191152217195SDaniel Vetter 191252217195SDaniel Vetter /** 191352217195SDaniel Vetter * drm_connector_set_tile_property - set tile property on connector 191452217195SDaniel Vetter * @connector: connector to set property on. 191552217195SDaniel Vetter * 191652217195SDaniel Vetter * This looks up the tile information for a connector, and creates a 191752217195SDaniel Vetter * property for userspace to parse if it exists. The property is of 191852217195SDaniel Vetter * the form of 8 integers using ':' as a separator. 19192de3a078SManasi Navare * This is used for dual port tiled displays with DisplayPort SST 19202de3a078SManasi Navare * or DisplayPort MST connectors. 192152217195SDaniel Vetter * 192252217195SDaniel Vetter * Returns: 192352217195SDaniel Vetter * Zero on success, errno on failure. 192452217195SDaniel Vetter */ 192552217195SDaniel Vetter int drm_connector_set_tile_property(struct drm_connector *connector) 192652217195SDaniel Vetter { 192752217195SDaniel Vetter struct drm_device *dev = connector->dev; 192852217195SDaniel Vetter char tile[256]; 192952217195SDaniel Vetter int ret; 193052217195SDaniel Vetter 193152217195SDaniel Vetter if (!connector->has_tile) { 193252217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 193352217195SDaniel Vetter &connector->tile_blob_ptr, 193452217195SDaniel Vetter 0, 193552217195SDaniel Vetter NULL, 193652217195SDaniel Vetter &connector->base, 193752217195SDaniel Vetter dev->mode_config.tile_property); 193852217195SDaniel Vetter return ret; 193952217195SDaniel Vetter } 194052217195SDaniel Vetter 194152217195SDaniel Vetter snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", 194252217195SDaniel Vetter connector->tile_group->id, connector->tile_is_single_monitor, 194352217195SDaniel Vetter connector->num_h_tile, connector->num_v_tile, 194452217195SDaniel Vetter connector->tile_h_loc, connector->tile_v_loc, 194552217195SDaniel Vetter connector->tile_h_size, connector->tile_v_size); 194652217195SDaniel Vetter 194752217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 194852217195SDaniel Vetter &connector->tile_blob_ptr, 194952217195SDaniel Vetter strlen(tile) + 1, 195052217195SDaniel Vetter tile, 195152217195SDaniel Vetter &connector->base, 195252217195SDaniel Vetter dev->mode_config.tile_property); 195352217195SDaniel Vetter return ret; 195452217195SDaniel Vetter } 195597e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_tile_property); 195652217195SDaniel Vetter 195752217195SDaniel Vetter /** 1958c555f023SDaniel Vetter * drm_connector_update_edid_property - update the edid property of a connector 195952217195SDaniel Vetter * @connector: drm connector 196052217195SDaniel Vetter * @edid: new value of the edid property 196152217195SDaniel Vetter * 196252217195SDaniel Vetter * This function creates a new blob modeset object and assigns its id to the 196352217195SDaniel Vetter * connector's edid property. 19642de3a078SManasi Navare * Since we also parse tile information from EDID's displayID block, we also 19652de3a078SManasi Navare * set the connector's tile property here. See drm_connector_set_tile_property() 19662de3a078SManasi Navare * for more details. 196752217195SDaniel Vetter * 196852217195SDaniel Vetter * Returns: 196952217195SDaniel Vetter * Zero on success, negative errno on failure. 197052217195SDaniel Vetter */ 1971c555f023SDaniel Vetter int drm_connector_update_edid_property(struct drm_connector *connector, 197252217195SDaniel Vetter const struct edid *edid) 197352217195SDaniel Vetter { 197452217195SDaniel Vetter struct drm_device *dev = connector->dev; 197552217195SDaniel Vetter size_t size = 0; 197652217195SDaniel Vetter int ret; 197752217195SDaniel Vetter 197852217195SDaniel Vetter /* ignore requests to set edid when overridden */ 197952217195SDaniel Vetter if (connector->override_edid) 198052217195SDaniel Vetter return 0; 198152217195SDaniel Vetter 198252217195SDaniel Vetter if (edid) 198352217195SDaniel Vetter size = EDID_LENGTH * (1 + edid->extensions); 198452217195SDaniel Vetter 1985170178feSKeith Packard /* Set the display info, using edid if available, otherwise 1986*84e543bcSAntonio Borneo * resetting the values to defaults. This duplicates the work 1987170178feSKeith Packard * done in drm_add_edid_modes, but that function is not 1988170178feSKeith Packard * consistently called before this one in all drivers and the 1989170178feSKeith Packard * computation is cheap enough that it seems better to 1990170178feSKeith Packard * duplicate it rather than attempt to ensure some arbitrary 1991170178feSKeith Packard * ordering of calls. 1992170178feSKeith Packard */ 1993170178feSKeith Packard if (edid) 1994170178feSKeith Packard drm_add_display_info(connector, edid); 1995170178feSKeith Packard else 1996170178feSKeith Packard drm_reset_display_info(connector); 1997170178feSKeith Packard 1998092c367aSVille Syrjälä drm_update_tile_info(connector, edid); 1999092c367aSVille Syrjälä 200066660d4cSDave Airlie drm_object_property_set_value(&connector->base, 200166660d4cSDave Airlie dev->mode_config.non_desktop_property, 200266660d4cSDave Airlie connector->display_info.non_desktop); 200366660d4cSDave Airlie 200452217195SDaniel Vetter ret = drm_property_replace_global_blob(dev, 200552217195SDaniel Vetter &connector->edid_blob_ptr, 200652217195SDaniel Vetter size, 200752217195SDaniel Vetter edid, 200852217195SDaniel Vetter &connector->base, 200952217195SDaniel Vetter dev->mode_config.edid_property); 20102de3a078SManasi Navare if (ret) 201152217195SDaniel Vetter return ret; 20122de3a078SManasi Navare return drm_connector_set_tile_property(connector); 201352217195SDaniel Vetter } 2014c555f023SDaniel Vetter EXPORT_SYMBOL(drm_connector_update_edid_property); 201552217195SDaniel Vetter 201640ee6fbeSManasi Navare /** 201797e14fbeSDaniel Vetter * drm_connector_set_link_status_property - Set link status property of a connector 201840ee6fbeSManasi Navare * @connector: drm connector 201940ee6fbeSManasi Navare * @link_status: new value of link status property (0: Good, 1: Bad) 202040ee6fbeSManasi Navare * 202140ee6fbeSManasi Navare * In usual working scenario, this link status property will always be set to 202240ee6fbeSManasi Navare * "GOOD". If something fails during or after a mode set, the kernel driver 202340ee6fbeSManasi Navare * may set this link status property to "BAD". The caller then needs to send a 202440ee6fbeSManasi Navare * hotplug uevent for userspace to re-check the valid modes through 202540ee6fbeSManasi Navare * GET_CONNECTOR_IOCTL and retry modeset. 202640ee6fbeSManasi Navare * 202740ee6fbeSManasi Navare * Note: Drivers cannot rely on userspace to support this property and 202840ee6fbeSManasi Navare * issue a modeset. As such, they may choose to handle issues (like 202940ee6fbeSManasi Navare * re-training a link) without userspace's intervention. 203040ee6fbeSManasi Navare * 203140ee6fbeSManasi Navare * The reason for adding this property is to handle link training failures, but 203240ee6fbeSManasi Navare * it is not limited to DP or link training. For example, if we implement 203340ee6fbeSManasi Navare * asynchronous setcrtc, this property can be used to report any failures in that. 203440ee6fbeSManasi Navare */ 203597e14fbeSDaniel Vetter void drm_connector_set_link_status_property(struct drm_connector *connector, 203640ee6fbeSManasi Navare uint64_t link_status) 203740ee6fbeSManasi Navare { 203840ee6fbeSManasi Navare struct drm_device *dev = connector->dev; 203940ee6fbeSManasi Navare 204040ee6fbeSManasi Navare drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 204140ee6fbeSManasi Navare connector->state->link_status = link_status; 204240ee6fbeSManasi Navare drm_modeset_unlock(&dev->mode_config.connection_mutex); 204340ee6fbeSManasi Navare } 204497e14fbeSDaniel Vetter EXPORT_SYMBOL(drm_connector_set_link_status_property); 204540ee6fbeSManasi Navare 20468d70f395SHans de Goede /** 204747e22ff1SRadhakrishna Sripada * drm_connector_attach_max_bpc_property - attach "max bpc" property 204847e22ff1SRadhakrishna Sripada * @connector: connector to attach max bpc property on. 204947e22ff1SRadhakrishna Sripada * @min: The minimum bit depth supported by the connector. 205047e22ff1SRadhakrishna Sripada * @max: The maximum bit depth supported by the connector. 205147e22ff1SRadhakrishna Sripada * 205247e22ff1SRadhakrishna Sripada * This is used to add support for limiting the bit depth on a connector. 205347e22ff1SRadhakrishna Sripada * 205447e22ff1SRadhakrishna Sripada * Returns: 205547e22ff1SRadhakrishna Sripada * Zero on success, negative errno on failure. 205647e22ff1SRadhakrishna Sripada */ 205747e22ff1SRadhakrishna Sripada int drm_connector_attach_max_bpc_property(struct drm_connector *connector, 205847e22ff1SRadhakrishna Sripada int min, int max) 205947e22ff1SRadhakrishna Sripada { 206047e22ff1SRadhakrishna Sripada struct drm_device *dev = connector->dev; 206147e22ff1SRadhakrishna Sripada struct drm_property *prop; 206247e22ff1SRadhakrishna Sripada 206347e22ff1SRadhakrishna Sripada prop = connector->max_bpc_property; 206447e22ff1SRadhakrishna Sripada if (!prop) { 206547e22ff1SRadhakrishna Sripada prop = drm_property_create_range(dev, 0, "max bpc", min, max); 206647e22ff1SRadhakrishna Sripada if (!prop) 206747e22ff1SRadhakrishna Sripada return -ENOMEM; 206847e22ff1SRadhakrishna Sripada 206947e22ff1SRadhakrishna Sripada connector->max_bpc_property = prop; 207047e22ff1SRadhakrishna Sripada } 207147e22ff1SRadhakrishna Sripada 207247e22ff1SRadhakrishna Sripada drm_object_attach_property(&connector->base, prop, max); 207347e22ff1SRadhakrishna Sripada connector->state->max_requested_bpc = max; 207447e22ff1SRadhakrishna Sripada connector->state->max_bpc = max; 207547e22ff1SRadhakrishna Sripada 207647e22ff1SRadhakrishna Sripada return 0; 207747e22ff1SRadhakrishna Sripada } 207847e22ff1SRadhakrishna Sripada EXPORT_SYMBOL(drm_connector_attach_max_bpc_property); 207947e22ff1SRadhakrishna Sripada 208047e22ff1SRadhakrishna Sripada /** 2081ba1b0f6cSNicholas Kazlauskas * drm_connector_set_vrr_capable_property - sets the variable refresh rate 2082ba1b0f6cSNicholas Kazlauskas * capable property for a connector 2083ba1b0f6cSNicholas Kazlauskas * @connector: drm connector 2084ba1b0f6cSNicholas Kazlauskas * @capable: True if the connector is variable refresh rate capable 2085ba1b0f6cSNicholas Kazlauskas * 2086ba1b0f6cSNicholas Kazlauskas * Should be used by atomic drivers to update the indicated support for 2087ba1b0f6cSNicholas Kazlauskas * variable refresh rate over a connector. 2088ba1b0f6cSNicholas Kazlauskas */ 2089ba1b0f6cSNicholas Kazlauskas void drm_connector_set_vrr_capable_property( 2090ba1b0f6cSNicholas Kazlauskas struct drm_connector *connector, bool capable) 2091ba1b0f6cSNicholas Kazlauskas { 2092ba1b0f6cSNicholas Kazlauskas drm_object_property_set_value(&connector->base, 2093ba1b0f6cSNicholas Kazlauskas connector->vrr_capable_property, 2094ba1b0f6cSNicholas Kazlauskas capable); 2095ba1b0f6cSNicholas Kazlauskas } 2096ba1b0f6cSNicholas Kazlauskas EXPORT_SYMBOL(drm_connector_set_vrr_capable_property); 2097ba1b0f6cSNicholas Kazlauskas 2098ba1b0f6cSNicholas Kazlauskas /** 2099*84e543bcSAntonio Borneo * drm_connector_set_panel_orientation - sets the connector's panel_orientation 210069654c63SDerek Basehore * @connector: connector for which to set the panel-orientation property. 210169654c63SDerek Basehore * @panel_orientation: drm_panel_orientation value to set 21028d70f395SHans de Goede * 210369654c63SDerek Basehore * This function sets the connector's panel_orientation and attaches 210469654c63SDerek Basehore * a "panel orientation" property to the connector. 21058d70f395SHans de Goede * 210669654c63SDerek Basehore * Calling this function on a connector where the panel_orientation has 210769654c63SDerek Basehore * already been set is a no-op (e.g. the orientation has been overridden with 210869654c63SDerek Basehore * a kernel commandline option). 210969654c63SDerek Basehore * 211069654c63SDerek Basehore * It is allowed to call this function with a panel_orientation of 211169654c63SDerek Basehore * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op. 21128d70f395SHans de Goede * 21138d70f395SHans de Goede * Returns: 21148d70f395SHans de Goede * Zero on success, negative errno on failure. 21158d70f395SHans de Goede */ 211669654c63SDerek Basehore int drm_connector_set_panel_orientation( 211769654c63SDerek Basehore struct drm_connector *connector, 211869654c63SDerek Basehore enum drm_panel_orientation panel_orientation) 21198d70f395SHans de Goede { 21208d70f395SHans de Goede struct drm_device *dev = connector->dev; 21218d70f395SHans de Goede struct drm_display_info *info = &connector->display_info; 21228d70f395SHans de Goede struct drm_property *prop; 21238d70f395SHans de Goede 212469654c63SDerek Basehore /* Already set? */ 212569654c63SDerek Basehore if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 21268d70f395SHans de Goede return 0; 21278d70f395SHans de Goede 212869654c63SDerek Basehore /* Don't attach the property if the orientation is unknown */ 212969654c63SDerek Basehore if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 213069654c63SDerek Basehore return 0; 213169654c63SDerek Basehore 213269654c63SDerek Basehore info->panel_orientation = panel_orientation; 213369654c63SDerek Basehore 21348d70f395SHans de Goede prop = dev->mode_config.panel_orientation_property; 21358d70f395SHans de Goede if (!prop) { 21368d70f395SHans de Goede prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 21378d70f395SHans de Goede "panel orientation", 21388d70f395SHans de Goede drm_panel_orientation_enum_list, 21398d70f395SHans de Goede ARRAY_SIZE(drm_panel_orientation_enum_list)); 21408d70f395SHans de Goede if (!prop) 21418d70f395SHans de Goede return -ENOMEM; 21428d70f395SHans de Goede 21438d70f395SHans de Goede dev->mode_config.panel_orientation_property = prop; 21448d70f395SHans de Goede } 21458d70f395SHans de Goede 21468d70f395SHans de Goede drm_object_attach_property(&connector->base, prop, 21478d70f395SHans de Goede info->panel_orientation); 21488d70f395SHans de Goede return 0; 21498d70f395SHans de Goede } 215069654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation); 215169654c63SDerek Basehore 215269654c63SDerek Basehore /** 215369654c63SDerek Basehore * drm_connector_set_panel_orientation_with_quirk - 2154*84e543bcSAntonio Borneo * set the connector's panel_orientation after checking for quirks 215569654c63SDerek Basehore * @connector: connector for which to init the panel-orientation property. 215669654c63SDerek Basehore * @panel_orientation: drm_panel_orientation value to set 215769654c63SDerek Basehore * @width: width in pixels of the panel, used for panel quirk detection 215869654c63SDerek Basehore * @height: height in pixels of the panel, used for panel quirk detection 215969654c63SDerek Basehore * 216069654c63SDerek Basehore * Like drm_connector_set_panel_orientation(), but with a check for platform 216169654c63SDerek Basehore * specific (e.g. DMI based) quirks overriding the passed in panel_orientation. 216269654c63SDerek Basehore * 216369654c63SDerek Basehore * Returns: 216469654c63SDerek Basehore * Zero on success, negative errno on failure. 216569654c63SDerek Basehore */ 216669654c63SDerek Basehore int drm_connector_set_panel_orientation_with_quirk( 216769654c63SDerek Basehore struct drm_connector *connector, 216869654c63SDerek Basehore enum drm_panel_orientation panel_orientation, 216969654c63SDerek Basehore int width, int height) 217069654c63SDerek Basehore { 217169654c63SDerek Basehore int orientation_quirk; 217269654c63SDerek Basehore 217369654c63SDerek Basehore orientation_quirk = drm_get_panel_orientation_quirk(width, height); 217469654c63SDerek Basehore if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 217569654c63SDerek Basehore panel_orientation = orientation_quirk; 217669654c63SDerek Basehore 217769654c63SDerek Basehore return drm_connector_set_panel_orientation(connector, 217869654c63SDerek Basehore panel_orientation); 217969654c63SDerek Basehore } 218069654c63SDerek Basehore EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk); 21818d70f395SHans de Goede 218297e14fbeSDaniel Vetter int drm_connector_set_obj_prop(struct drm_mode_object *obj, 218352217195SDaniel Vetter struct drm_property *property, 218452217195SDaniel Vetter uint64_t value) 218552217195SDaniel Vetter { 218652217195SDaniel Vetter int ret = -EINVAL; 218752217195SDaniel Vetter struct drm_connector *connector = obj_to_connector(obj); 218852217195SDaniel Vetter 218952217195SDaniel Vetter /* Do DPMS ourselves */ 219052217195SDaniel Vetter if (property == connector->dev->mode_config.dpms_property) { 219152217195SDaniel Vetter ret = (*connector->funcs->dpms)(connector, (int)value); 219252217195SDaniel Vetter } else if (connector->funcs->set_property) 219352217195SDaniel Vetter ret = connector->funcs->set_property(connector, property, value); 219452217195SDaniel Vetter 2195144a7999SDaniel Vetter if (!ret) 219652217195SDaniel Vetter drm_object_property_set_value(&connector->base, property, value); 219752217195SDaniel Vetter return ret; 219852217195SDaniel Vetter } 219952217195SDaniel Vetter 220097e14fbeSDaniel Vetter int drm_connector_property_set_ioctl(struct drm_device *dev, 220152217195SDaniel Vetter void *data, struct drm_file *file_priv) 220252217195SDaniel Vetter { 220352217195SDaniel Vetter struct drm_mode_connector_set_property *conn_set_prop = data; 220452217195SDaniel Vetter struct drm_mode_obj_set_property obj_set_prop = { 220552217195SDaniel Vetter .value = conn_set_prop->value, 220652217195SDaniel Vetter .prop_id = conn_set_prop->prop_id, 220752217195SDaniel Vetter .obj_id = conn_set_prop->connector_id, 220852217195SDaniel Vetter .obj_type = DRM_MODE_OBJECT_CONNECTOR 220952217195SDaniel Vetter }; 221052217195SDaniel Vetter 221152217195SDaniel Vetter /* It does all the locking and checking we need */ 221252217195SDaniel Vetter return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv); 221352217195SDaniel Vetter } 221452217195SDaniel Vetter 221552217195SDaniel Vetter static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) 221652217195SDaniel Vetter { 221752217195SDaniel Vetter /* For atomic drivers only state objects are synchronously updated and 221852217195SDaniel Vetter * protected by modeset locks, so check those first. */ 221952217195SDaniel Vetter if (connector->state) 222052217195SDaniel Vetter return connector->state->best_encoder; 222152217195SDaniel Vetter return connector->encoder; 222252217195SDaniel Vetter } 222352217195SDaniel Vetter 2224c3ff0cdbSAnkit Nautiyal static bool 2225c3ff0cdbSAnkit Nautiyal drm_mode_expose_to_userspace(const struct drm_display_mode *mode, 2226c3ff0cdbSAnkit Nautiyal const struct list_head *export_list, 222752217195SDaniel Vetter const struct drm_file *file_priv) 222852217195SDaniel Vetter { 222952217195SDaniel Vetter /* 223052217195SDaniel Vetter * If user-space hasn't configured the driver to expose the stereo 3D 223152217195SDaniel Vetter * modes, don't expose them. 223252217195SDaniel Vetter */ 223352217195SDaniel Vetter if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) 223452217195SDaniel Vetter return false; 2235c3ff0cdbSAnkit Nautiyal /* 2236c3ff0cdbSAnkit Nautiyal * If user-space hasn't configured the driver to expose the modes 2237c3ff0cdbSAnkit Nautiyal * with aspect-ratio, don't expose them. However if such a mode 2238c3ff0cdbSAnkit Nautiyal * is unique, let it be exposed, but reset the aspect-ratio flags 2239c3ff0cdbSAnkit Nautiyal * while preparing the list of user-modes. 2240c3ff0cdbSAnkit Nautiyal */ 2241c3ff0cdbSAnkit Nautiyal if (!file_priv->aspect_ratio_allowed) { 2242c3ff0cdbSAnkit Nautiyal struct drm_display_mode *mode_itr; 2243c3ff0cdbSAnkit Nautiyal 2244c3ff0cdbSAnkit Nautiyal list_for_each_entry(mode_itr, export_list, export_head) 2245c3ff0cdbSAnkit Nautiyal if (drm_mode_match(mode_itr, mode, 2246c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_TIMINGS | 2247c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_CLOCK | 2248c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_FLAGS | 2249c3ff0cdbSAnkit Nautiyal DRM_MODE_MATCH_3D_FLAGS)) 2250c3ff0cdbSAnkit Nautiyal return false; 2251c3ff0cdbSAnkit Nautiyal } 225252217195SDaniel Vetter 225352217195SDaniel Vetter return true; 225452217195SDaniel Vetter } 225552217195SDaniel Vetter 225652217195SDaniel Vetter int drm_mode_getconnector(struct drm_device *dev, void *data, 225752217195SDaniel Vetter struct drm_file *file_priv) 225852217195SDaniel Vetter { 225952217195SDaniel Vetter struct drm_mode_get_connector *out_resp = data; 226052217195SDaniel Vetter struct drm_connector *connector; 226152217195SDaniel Vetter struct drm_encoder *encoder; 226252217195SDaniel Vetter struct drm_display_mode *mode; 226352217195SDaniel Vetter int mode_count = 0; 226452217195SDaniel Vetter int encoders_count = 0; 226552217195SDaniel Vetter int ret = 0; 226652217195SDaniel Vetter int copied = 0; 226752217195SDaniel Vetter struct drm_mode_modeinfo u_mode; 226852217195SDaniel Vetter struct drm_mode_modeinfo __user *mode_ptr; 226952217195SDaniel Vetter uint32_t __user *encoder_ptr; 2270c3ff0cdbSAnkit Nautiyal LIST_HEAD(export_list); 227152217195SDaniel Vetter 227252217195SDaniel Vetter if (!drm_core_check_feature(dev, DRIVER_MODESET)) 227369fdf420SChris Wilson return -EOPNOTSUPP; 227452217195SDaniel Vetter 227552217195SDaniel Vetter memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); 227652217195SDaniel Vetter 2277418da172SKeith Packard connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id); 227891eefc05SDaniel Vetter if (!connector) 227991eefc05SDaniel Vetter return -ENOENT; 228052217195SDaniel Vetter 228162afb4adSJosé Roberto de Souza encoders_count = hweight32(connector->possible_encoders); 228291eefc05SDaniel Vetter 228391eefc05SDaniel Vetter if ((out_resp->count_encoders >= encoders_count) && encoders_count) { 228491eefc05SDaniel Vetter copied = 0; 228591eefc05SDaniel Vetter encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); 228683aefbb8SVille Syrjälä 228762afb4adSJosé Roberto de Souza drm_connector_for_each_possible_encoder(connector, encoder) { 228883aefbb8SVille Syrjälä if (put_user(encoder->base.id, encoder_ptr + copied)) { 228991eefc05SDaniel Vetter ret = -EFAULT; 2290e94ac351SDaniel Vetter goto out; 229191eefc05SDaniel Vetter } 229291eefc05SDaniel Vetter copied++; 229391eefc05SDaniel Vetter } 229491eefc05SDaniel Vetter } 229591eefc05SDaniel Vetter out_resp->count_encoders = encoders_count; 229691eefc05SDaniel Vetter 229791eefc05SDaniel Vetter out_resp->connector_id = connector->base.id; 229891eefc05SDaniel Vetter out_resp->connector_type = connector->connector_type; 229991eefc05SDaniel Vetter out_resp->connector_type_id = connector->connector_type_id; 230091eefc05SDaniel Vetter 230191eefc05SDaniel Vetter mutex_lock(&dev->mode_config.mutex); 230291eefc05SDaniel Vetter if (out_resp->count_modes == 0) { 230391eefc05SDaniel Vetter connector->funcs->fill_modes(connector, 230491eefc05SDaniel Vetter dev->mode_config.max_width, 230591eefc05SDaniel Vetter dev->mode_config.max_height); 230691eefc05SDaniel Vetter } 230791eefc05SDaniel Vetter 230891eefc05SDaniel Vetter out_resp->mm_width = connector->display_info.width_mm; 230991eefc05SDaniel Vetter out_resp->mm_height = connector->display_info.height_mm; 231091eefc05SDaniel Vetter out_resp->subpixel = connector->display_info.subpixel_order; 231191eefc05SDaniel Vetter out_resp->connection = connector->status; 231291eefc05SDaniel Vetter 231391eefc05SDaniel Vetter /* delayed so we get modes regardless of pre-fill_modes state */ 231491eefc05SDaniel Vetter list_for_each_entry(mode, &connector->modes, head) 2315c3ff0cdbSAnkit Nautiyal if (drm_mode_expose_to_userspace(mode, &export_list, 2316c3ff0cdbSAnkit Nautiyal file_priv)) { 2317c3ff0cdbSAnkit Nautiyal list_add_tail(&mode->export_head, &export_list); 231891eefc05SDaniel Vetter mode_count++; 2319c3ff0cdbSAnkit Nautiyal } 232091eefc05SDaniel Vetter 232152217195SDaniel Vetter /* 232252217195SDaniel Vetter * This ioctl is called twice, once to determine how much space is 232352217195SDaniel Vetter * needed, and the 2nd time to fill it. 2324c3ff0cdbSAnkit Nautiyal * The modes that need to be exposed to the user are maintained in the 2325c3ff0cdbSAnkit Nautiyal * 'export_list'. When the ioctl is called first time to determine the, 2326c3ff0cdbSAnkit Nautiyal * space, the export_list gets filled, to find the no.of modes. In the 2327c3ff0cdbSAnkit Nautiyal * 2nd time, the user modes are filled, one by one from the export_list. 232852217195SDaniel Vetter */ 232952217195SDaniel Vetter if ((out_resp->count_modes >= mode_count) && mode_count) { 233052217195SDaniel Vetter copied = 0; 233152217195SDaniel Vetter mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; 2332c3ff0cdbSAnkit Nautiyal list_for_each_entry(mode, &export_list, export_head) { 233352217195SDaniel Vetter drm_mode_convert_to_umode(&u_mode, mode); 2334c3ff0cdbSAnkit Nautiyal /* 2335c3ff0cdbSAnkit Nautiyal * Reset aspect ratio flags of user-mode, if modes with 2336c3ff0cdbSAnkit Nautiyal * aspect-ratio are not supported. 2337c3ff0cdbSAnkit Nautiyal */ 2338c3ff0cdbSAnkit Nautiyal if (!file_priv->aspect_ratio_allowed) 2339c3ff0cdbSAnkit Nautiyal u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK; 234052217195SDaniel Vetter if (copy_to_user(mode_ptr + copied, 234152217195SDaniel Vetter &u_mode, sizeof(u_mode))) { 234252217195SDaniel Vetter ret = -EFAULT; 2343e94ac351SDaniel Vetter mutex_unlock(&dev->mode_config.mutex); 2344e94ac351SDaniel Vetter 234552217195SDaniel Vetter goto out; 234652217195SDaniel Vetter } 234752217195SDaniel Vetter copied++; 234852217195SDaniel Vetter } 234952217195SDaniel Vetter } 235052217195SDaniel Vetter out_resp->count_modes = mode_count; 235152217195SDaniel Vetter mutex_unlock(&dev->mode_config.mutex); 2352e94ac351SDaniel Vetter 2353e94ac351SDaniel Vetter drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 2354e94ac351SDaniel Vetter encoder = drm_connector_get_encoder(connector); 2355e94ac351SDaniel Vetter if (encoder) 2356e94ac351SDaniel Vetter out_resp->encoder_id = encoder->base.id; 2357e94ac351SDaniel Vetter else 2358e94ac351SDaniel Vetter out_resp->encoder_id = 0; 2359e94ac351SDaniel Vetter 2360e94ac351SDaniel Vetter /* Only grab properties after probing, to make sure EDID and other 2361e94ac351SDaniel Vetter * properties reflect the latest status. */ 2362e94ac351SDaniel Vetter ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic, 2363e94ac351SDaniel Vetter (uint32_t __user *)(unsigned long)(out_resp->props_ptr), 2364e94ac351SDaniel Vetter (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), 2365e94ac351SDaniel Vetter &out_resp->count_props); 2366e94ac351SDaniel Vetter drm_modeset_unlock(&dev->mode_config.connection_mutex); 2367e94ac351SDaniel Vetter 2368e94ac351SDaniel Vetter out: 2369ad093607SThierry Reding drm_connector_put(connector); 237052217195SDaniel Vetter 237152217195SDaniel Vetter return ret; 237252217195SDaniel Vetter } 237352217195SDaniel Vetter 23749498c19bSDaniel Vetter 23759498c19bSDaniel Vetter /** 23769498c19bSDaniel Vetter * DOC: Tile group 23779498c19bSDaniel Vetter * 23789498c19bSDaniel Vetter * Tile groups are used to represent tiled monitors with a unique integer 23799498c19bSDaniel Vetter * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle, 23809498c19bSDaniel Vetter * we store this in a tile group, so we have a common identifier for all tiles 23819498c19bSDaniel Vetter * in a monitor group. The property is called "TILE". Drivers can manage tile 23829498c19bSDaniel Vetter * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and 23839498c19bSDaniel Vetter * drm_mode_get_tile_group(). But this is only needed for internal panels where 23849498c19bSDaniel Vetter * the tile group information is exposed through a non-standard way. 23859498c19bSDaniel Vetter */ 23869498c19bSDaniel Vetter 23879498c19bSDaniel Vetter static void drm_tile_group_free(struct kref *kref) 23889498c19bSDaniel Vetter { 23899498c19bSDaniel Vetter struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); 23909498c19bSDaniel Vetter struct drm_device *dev = tg->dev; 23919498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 23929498c19bSDaniel Vetter idr_remove(&dev->mode_config.tile_idr, tg->id); 23939498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 23949498c19bSDaniel Vetter kfree(tg); 23959498c19bSDaniel Vetter } 23969498c19bSDaniel Vetter 23979498c19bSDaniel Vetter /** 23989498c19bSDaniel Vetter * drm_mode_put_tile_group - drop a reference to a tile group. 23999498c19bSDaniel Vetter * @dev: DRM device 24009498c19bSDaniel Vetter * @tg: tile group to drop reference to. 24019498c19bSDaniel Vetter * 24029498c19bSDaniel Vetter * drop reference to tile group and free if 0. 24039498c19bSDaniel Vetter */ 24049498c19bSDaniel Vetter void drm_mode_put_tile_group(struct drm_device *dev, 24059498c19bSDaniel Vetter struct drm_tile_group *tg) 24069498c19bSDaniel Vetter { 24079498c19bSDaniel Vetter kref_put(&tg->refcount, drm_tile_group_free); 24089498c19bSDaniel Vetter } 24099498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_put_tile_group); 24109498c19bSDaniel Vetter 24119498c19bSDaniel Vetter /** 24129498c19bSDaniel Vetter * drm_mode_get_tile_group - get a reference to an existing tile group 24139498c19bSDaniel Vetter * @dev: DRM device 24149498c19bSDaniel Vetter * @topology: 8-bytes unique per monitor. 24159498c19bSDaniel Vetter * 24169498c19bSDaniel Vetter * Use the unique bytes to get a reference to an existing tile group. 24179498c19bSDaniel Vetter * 24189498c19bSDaniel Vetter * RETURNS: 24199498c19bSDaniel Vetter * tile group or NULL if not found. 24209498c19bSDaniel Vetter */ 24219498c19bSDaniel Vetter struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 2422267ea759SVille Syrjälä const char topology[8]) 24239498c19bSDaniel Vetter { 24249498c19bSDaniel Vetter struct drm_tile_group *tg; 24259498c19bSDaniel Vetter int id; 24269498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 24279498c19bSDaniel Vetter idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { 24289498c19bSDaniel Vetter if (!memcmp(tg->group_data, topology, 8)) { 24299498c19bSDaniel Vetter if (!kref_get_unless_zero(&tg->refcount)) 24309498c19bSDaniel Vetter tg = NULL; 24319498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 24329498c19bSDaniel Vetter return tg; 24339498c19bSDaniel Vetter } 24349498c19bSDaniel Vetter } 24359498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 24369498c19bSDaniel Vetter return NULL; 24379498c19bSDaniel Vetter } 24389498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_get_tile_group); 24399498c19bSDaniel Vetter 24409498c19bSDaniel Vetter /** 24419498c19bSDaniel Vetter * drm_mode_create_tile_group - create a tile group from a displayid description 24429498c19bSDaniel Vetter * @dev: DRM device 24439498c19bSDaniel Vetter * @topology: 8-bytes unique per monitor. 24449498c19bSDaniel Vetter * 24459498c19bSDaniel Vetter * Create a tile group for the unique monitor, and get a unique 24469498c19bSDaniel Vetter * identifier for the tile group. 24479498c19bSDaniel Vetter * 24489498c19bSDaniel Vetter * RETURNS: 2449705c8160SDan Carpenter * new tile group or NULL. 24509498c19bSDaniel Vetter */ 24519498c19bSDaniel Vetter struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 2452267ea759SVille Syrjälä const char topology[8]) 24539498c19bSDaniel Vetter { 24549498c19bSDaniel Vetter struct drm_tile_group *tg; 24559498c19bSDaniel Vetter int ret; 24569498c19bSDaniel Vetter 24579498c19bSDaniel Vetter tg = kzalloc(sizeof(*tg), GFP_KERNEL); 24589498c19bSDaniel Vetter if (!tg) 2459705c8160SDan Carpenter return NULL; 24609498c19bSDaniel Vetter 24619498c19bSDaniel Vetter kref_init(&tg->refcount); 24629498c19bSDaniel Vetter memcpy(tg->group_data, topology, 8); 24639498c19bSDaniel Vetter tg->dev = dev; 24649498c19bSDaniel Vetter 24659498c19bSDaniel Vetter mutex_lock(&dev->mode_config.idr_mutex); 24669498c19bSDaniel Vetter ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); 24679498c19bSDaniel Vetter if (ret >= 0) { 24689498c19bSDaniel Vetter tg->id = ret; 24699498c19bSDaniel Vetter } else { 24709498c19bSDaniel Vetter kfree(tg); 2471705c8160SDan Carpenter tg = NULL; 24729498c19bSDaniel Vetter } 24739498c19bSDaniel Vetter 24749498c19bSDaniel Vetter mutex_unlock(&dev->mode_config.idr_mutex); 24759498c19bSDaniel Vetter return tg; 24769498c19bSDaniel Vetter } 24779498c19bSDaniel Vetter EXPORT_SYMBOL(drm_mode_create_tile_group); 2478