1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * Permission to use, copy, modify, distribute, and sell this software and its 5 * documentation for any purpose is hereby granted without fee, provided that 6 * the above copyright notice appear in all copies and that both that copyright 7 * notice and this permission notice appear in supporting documentation, and 8 * that the name of the copyright holders not be used in advertising or 9 * publicity pertaining to distribution of the software without specific, 10 * written prior permission. The copyright holders make no representations 11 * about the suitability of this software for any purpose. It is provided "as 12 * is" without express or implied warranty. 13 * 14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 20 * OF THIS SOFTWARE. 21 */ 22 23 #include <drm/drm_auth.h> 24 #include <drm/drm_connector.h> 25 #include <drm/drm_drv.h> 26 #include <drm/drm_edid.h> 27 #include <drm/drm_encoder.h> 28 #include <drm/drm_file.h> 29 #include <drm/drm_managed.h> 30 #include <drm/drm_panel.h> 31 #include <drm/drm_panel_quirks.h> 32 #include <drm/drm_print.h> 33 #include <drm/drm_privacy_screen_consumer.h> 34 #include <drm/drm_sysfs.h> 35 36 #include <linux/export.h> 37 #include <linux/platform_device.h> 38 #include <linux/property.h> 39 #include <linux/uaccess.h> 40 41 #include <video/cmdline.h> 42 43 #include "drm_crtc_internal.h" 44 #include "drm_internal.h" 45 46 /** 47 * DOC: overview 48 * 49 * In DRM connectors are the general abstraction for display sinks, and include 50 * also fixed panels or anything else that can display pixels in some form. As 51 * opposed to all other KMS objects representing hardware (like CRTC, encoder or 52 * plane abstractions) connectors can be hotplugged and unplugged at runtime. 53 * Hence they are reference-counted using drm_connector_get() and 54 * drm_connector_put(). 55 * 56 * KMS driver must create, initialize, register and attach at a &struct 57 * drm_connector for each such sink. The instance is created as other KMS 58 * objects and initialized by setting the following fields. The connector is 59 * initialized with a call to drm_connector_init() with a pointer to the 60 * &struct drm_connector_funcs and a connector type, and then exposed to 61 * userspace with a call to drm_connector_register(). 62 * 63 * Connectors must be attached to an encoder to be used. For devices that map 64 * connectors to encoders 1:1, the connector should be attached at 65 * initialization time with a call to drm_connector_attach_encoder(). The 66 * driver must also set the &drm_connector.encoder field to point to the 67 * attached encoder. 68 * 69 * For connectors which are not fixed (like built-in panels) the driver needs to 70 * support hotplug notifications. The simplest way to do that is by using the 71 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have 72 * hardware support for hotplug interrupts. Connectors with hardware hotplug 73 * support can instead use e.g. drm_helper_hpd_irq_event(). 74 */ 75 76 /* 77 * Global connector list for drm_connector_find_by_fwnode(). 78 * Note drm_connector_[un]register() first take connector->lock and then 79 * take the connector_list_lock. 80 */ 81 static DEFINE_MUTEX(connector_list_lock); 82 static LIST_HEAD(connector_list); 83 84 struct drm_conn_prop_enum_list { 85 int type; 86 const char *name; 87 struct ida ida; 88 }; 89 90 /* 91 * Connector and encoder types. 92 */ 93 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { 94 { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, 95 { DRM_MODE_CONNECTOR_VGA, "VGA" }, 96 { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, 97 { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, 98 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, 99 { DRM_MODE_CONNECTOR_Composite, "Composite" }, 100 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, 101 { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, 102 { DRM_MODE_CONNECTOR_Component, "Component" }, 103 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, 104 { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, 105 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, 106 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, 107 { DRM_MODE_CONNECTOR_TV, "TV" }, 108 { DRM_MODE_CONNECTOR_eDP, "eDP" }, 109 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, 110 { DRM_MODE_CONNECTOR_DSI, "DSI" }, 111 { DRM_MODE_CONNECTOR_DPI, "DPI" }, 112 { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, 113 { DRM_MODE_CONNECTOR_SPI, "SPI" }, 114 { DRM_MODE_CONNECTOR_USB, "USB" }, 115 }; 116 117 void drm_connector_ida_init(void) 118 { 119 int i; 120 121 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 122 ida_init(&drm_connector_enum_list[i].ida); 123 } 124 125 void drm_connector_ida_destroy(void) 126 { 127 int i; 128 129 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 130 ida_destroy(&drm_connector_enum_list[i].ida); 131 } 132 133 /** 134 * drm_get_connector_type_name - return a string for connector type 135 * @type: The connector type (DRM_MODE_CONNECTOR_*) 136 * 137 * Returns: the name of the connector type, or NULL if the type is not valid. 138 */ 139 const char *drm_get_connector_type_name(unsigned int type) 140 { 141 if (type < ARRAY_SIZE(drm_connector_enum_list)) 142 return drm_connector_enum_list[type].name; 143 144 return NULL; 145 } 146 EXPORT_SYMBOL(drm_get_connector_type_name); 147 148 /** 149 * drm_connector_get_cmdline_mode - reads the user's cmdline mode 150 * @connector: connector to query 151 * 152 * The kernel supports per-connector configuration of its consoles through 153 * use of the video= parameter. This function parses that option and 154 * extracts the user's specified mode (or enable/disable status) for a 155 * particular connector. This is typically only used during the early fbdev 156 * setup. 157 */ 158 static void drm_connector_get_cmdline_mode(struct drm_connector *connector) 159 { 160 struct drm_cmdline_mode *mode = &connector->cmdline_mode; 161 const char *option; 162 163 option = video_get_options(connector->name); 164 if (!option) 165 return; 166 167 if (!drm_mode_parse_command_line_for_connector(option, 168 connector, 169 mode)) 170 return; 171 172 if (mode->force) { 173 DRM_INFO("forcing %s connector %s\n", connector->name, 174 drm_get_connector_force_name(mode->force)); 175 connector->force = mode->force; 176 } 177 178 if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) { 179 DRM_INFO("cmdline forces connector %s panel_orientation to %d\n", 180 connector->name, mode->panel_orientation); 181 drm_connector_set_panel_orientation(connector, 182 mode->panel_orientation); 183 } 184 185 DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n", 186 connector->name, mode->name, 187 mode->xres, mode->yres, 188 mode->refresh_specified ? mode->refresh : 60, 189 mode->rb ? " reduced blanking" : "", 190 mode->margins ? " with margins" : "", 191 mode->interlace ? " interlaced" : ""); 192 } 193 194 static void drm_connector_free(struct kref *kref) 195 { 196 struct drm_connector *connector = 197 container_of(kref, struct drm_connector, base.refcount); 198 struct drm_device *dev = connector->dev; 199 200 drm_mode_object_unregister(dev, &connector->base); 201 connector->funcs->destroy(connector); 202 } 203 204 void drm_connector_free_work_fn(struct work_struct *work) 205 { 206 struct drm_connector *connector, *n; 207 struct drm_device *dev = 208 container_of(work, struct drm_device, mode_config.connector_free_work); 209 struct drm_mode_config *config = &dev->mode_config; 210 unsigned long flags; 211 struct llist_node *freed; 212 213 spin_lock_irqsave(&config->connector_list_lock, flags); 214 freed = llist_del_all(&config->connector_free_list); 215 spin_unlock_irqrestore(&config->connector_list_lock, flags); 216 217 llist_for_each_entry_safe(connector, n, freed, free_node) { 218 drm_mode_object_unregister(dev, &connector->base); 219 connector->funcs->destroy(connector); 220 } 221 } 222 223 static int drm_connector_init_only(struct drm_device *dev, 224 struct drm_connector *connector, 225 const struct drm_connector_funcs *funcs, 226 int connector_type, 227 struct i2c_adapter *ddc) 228 { 229 struct drm_mode_config *config = &dev->mode_config; 230 int ret; 231 struct ida *connector_ida = 232 &drm_connector_enum_list[connector_type].ida; 233 234 WARN_ON(drm_drv_uses_atomic_modeset(dev) && 235 (!funcs->atomic_destroy_state || 236 !funcs->atomic_duplicate_state)); 237 238 ret = __drm_mode_object_add(dev, &connector->base, 239 DRM_MODE_OBJECT_CONNECTOR, 240 false, drm_connector_free); 241 if (ret) 242 return ret; 243 244 connector->base.properties = &connector->properties; 245 connector->dev = dev; 246 connector->funcs = funcs; 247 248 /* connector index is used with 32bit bitmasks */ 249 ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL); 250 if (ret < 0) { 251 DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n", 252 drm_connector_enum_list[connector_type].name, 253 ret); 254 goto out_put; 255 } 256 connector->index = ret; 257 ret = 0; 258 259 connector->connector_type = connector_type; 260 connector->connector_type_id = 261 ida_alloc_min(connector_ida, 1, GFP_KERNEL); 262 if (connector->connector_type_id < 0) { 263 ret = connector->connector_type_id; 264 goto out_put_id; 265 } 266 connector->name = 267 kasprintf(GFP_KERNEL, "%s-%d", 268 drm_connector_enum_list[connector_type].name, 269 connector->connector_type_id); 270 if (!connector->name) { 271 ret = -ENOMEM; 272 goto out_put_type_id; 273 } 274 275 /* provide ddc symlink in sysfs */ 276 connector->ddc = ddc; 277 278 INIT_LIST_HEAD(&connector->head); 279 INIT_LIST_HEAD(&connector->global_connector_list_entry); 280 INIT_LIST_HEAD(&connector->probed_modes); 281 INIT_LIST_HEAD(&connector->modes); 282 mutex_init(&connector->mutex); 283 mutex_init(&connector->cec.mutex); 284 mutex_init(&connector->eld_mutex); 285 mutex_init(&connector->edid_override_mutex); 286 mutex_init(&connector->hdmi.infoframes.lock); 287 mutex_init(&connector->hdmi_audio.lock); 288 connector->edid_blob_ptr = NULL; 289 connector->epoch_counter = 0; 290 connector->tile_blob_ptr = NULL; 291 connector->status = connector_status_unknown; 292 connector->display_info.panel_orientation = 293 DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 294 295 drm_connector_get_cmdline_mode(connector); 296 297 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL && 298 connector_type != DRM_MODE_CONNECTOR_WRITEBACK) 299 drm_connector_attach_edid_property(connector); 300 301 drm_object_attach_property(&connector->base, 302 config->dpms_property, 0); 303 304 drm_object_attach_property(&connector->base, 305 config->link_status_property, 306 0); 307 308 drm_object_attach_property(&connector->base, 309 config->non_desktop_property, 310 0); 311 drm_object_attach_property(&connector->base, 312 config->tile_property, 313 0); 314 315 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 316 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); 317 } 318 319 connector->debugfs_entry = NULL; 320 out_put_type_id: 321 if (ret) 322 ida_free(connector_ida, connector->connector_type_id); 323 out_put_id: 324 if (ret) 325 ida_free(&config->connector_ida, connector->index); 326 out_put: 327 if (ret) 328 drm_mode_object_unregister(dev, &connector->base); 329 330 return ret; 331 } 332 333 static void drm_connector_add(struct drm_connector *connector) 334 { 335 struct drm_device *dev = connector->dev; 336 struct drm_mode_config *config = &dev->mode_config; 337 338 if (drm_WARN_ON(dev, !list_empty(&connector->head))) 339 return; 340 341 spin_lock_irq(&config->connector_list_lock); 342 list_add_tail(&connector->head, &config->connector_list); 343 config->num_connector++; 344 spin_unlock_irq(&config->connector_list_lock); 345 } 346 347 static void drm_connector_remove(struct drm_connector *connector) 348 { 349 struct drm_device *dev = connector->dev; 350 351 /* 352 * For dynamic connectors drm_connector_cleanup() can call this function 353 * before the connector is registered and added to the list. 354 */ 355 if (list_empty(&connector->head)) 356 return; 357 358 spin_lock_irq(&dev->mode_config.connector_list_lock); 359 list_del_init(&connector->head); 360 dev->mode_config.num_connector--; 361 spin_unlock_irq(&dev->mode_config.connector_list_lock); 362 } 363 364 static int drm_connector_init_and_add(struct drm_device *dev, 365 struct drm_connector *connector, 366 const struct drm_connector_funcs *funcs, 367 int connector_type, 368 struct i2c_adapter *ddc) 369 { 370 int ret; 371 372 ret = drm_connector_init_only(dev, connector, funcs, connector_type, ddc); 373 if (ret) 374 return ret; 375 376 drm_connector_add(connector); 377 378 return 0; 379 } 380 381 /** 382 * drm_connector_init - Init a preallocated connector 383 * @dev: DRM device 384 * @connector: the connector to init 385 * @funcs: callbacks for this connector 386 * @connector_type: user visible type of the connector 387 * 388 * Initialises a preallocated connector. Connectors should be 389 * subclassed as part of driver connector objects. 390 * 391 * At driver unload time the driver's &drm_connector_funcs.destroy hook 392 * should call drm_connector_cleanup() and free the connector structure. 393 * The connector structure should not be allocated with devm_kzalloc(). 394 * 395 * Note: consider using drmm_connector_init() instead of 396 * drm_connector_init() to let the DRM managed resource infrastructure 397 * take care of cleanup and deallocation. 398 * 399 * Returns: 400 * Zero on success, error code on failure. 401 */ 402 int drm_connector_init(struct drm_device *dev, 403 struct drm_connector *connector, 404 const struct drm_connector_funcs *funcs, 405 int connector_type) 406 { 407 if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) 408 return -EINVAL; 409 410 return drm_connector_init_and_add(dev, connector, funcs, connector_type, NULL); 411 } 412 EXPORT_SYMBOL(drm_connector_init); 413 414 /** 415 * drm_connector_dynamic_init - Init a preallocated dynamic connector 416 * @dev: DRM device 417 * @connector: the connector to init 418 * @funcs: callbacks for this connector 419 * @connector_type: user visible type of the connector 420 * @ddc: pointer to the associated ddc adapter 421 * 422 * Initialises a preallocated dynamic connector. Connectors should be 423 * subclassed as part of driver connector objects. The connector 424 * structure should not be allocated with devm_kzalloc(). 425 * 426 * Drivers should call this for dynamic connectors which can be hotplugged 427 * after drm_dev_register() has been called already, e.g. DP MST connectors. 428 * For all other - static - connectors, drivers should call one of the 429 * drm_connector_init*()/drmm_connector_init*() functions. 430 * 431 * After calling this function the drivers must call 432 * drm_connector_dynamic_register(). 433 * 434 * To remove the connector the driver must call drm_connector_unregister() 435 * followed by drm_connector_put(). Putting the last reference will call the 436 * driver's &drm_connector_funcs.destroy hook, which in turn must call 437 * drm_connector_cleanup() and free the connector structure. 438 * 439 * Returns: 440 * Zero on success, error code on failure. 441 */ 442 int drm_connector_dynamic_init(struct drm_device *dev, 443 struct drm_connector *connector, 444 const struct drm_connector_funcs *funcs, 445 int connector_type, 446 struct i2c_adapter *ddc) 447 { 448 if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) 449 return -EINVAL; 450 451 return drm_connector_init_only(dev, connector, funcs, connector_type, ddc); 452 } 453 EXPORT_SYMBOL(drm_connector_dynamic_init); 454 455 /** 456 * drm_connector_init_with_ddc - Init a preallocated connector 457 * @dev: DRM device 458 * @connector: the connector to init 459 * @funcs: callbacks for this connector 460 * @connector_type: user visible type of the connector 461 * @ddc: pointer to the associated ddc adapter 462 * 463 * Initialises a preallocated connector. Connectors should be 464 * subclassed as part of driver connector objects. 465 * 466 * At driver unload time the driver's &drm_connector_funcs.destroy hook 467 * should call drm_connector_cleanup() and free the connector structure. 468 * The connector structure should not be allocated with devm_kzalloc(). 469 * 470 * Ensures that the ddc field of the connector is correctly set. 471 * 472 * Note: consider using drmm_connector_init() instead of 473 * drm_connector_init_with_ddc() to let the DRM managed resource 474 * infrastructure take care of cleanup and deallocation. 475 * 476 * Returns: 477 * Zero on success, error code on failure. 478 */ 479 int drm_connector_init_with_ddc(struct drm_device *dev, 480 struct drm_connector *connector, 481 const struct drm_connector_funcs *funcs, 482 int connector_type, 483 struct i2c_adapter *ddc) 484 { 485 if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) 486 return -EINVAL; 487 488 return drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc); 489 } 490 EXPORT_SYMBOL(drm_connector_init_with_ddc); 491 492 static void drm_connector_cleanup_action(struct drm_device *dev, 493 void *ptr) 494 { 495 struct drm_connector *connector = ptr; 496 497 drm_connector_cleanup(connector); 498 } 499 500 /** 501 * drmm_connector_init - Init a preallocated connector 502 * @dev: DRM device 503 * @connector: the connector to init 504 * @funcs: callbacks for this connector 505 * @connector_type: user visible type of the connector 506 * @ddc: optional pointer to the associated ddc adapter 507 * 508 * Initialises a preallocated connector. Connectors should be 509 * subclassed as part of driver connector objects. 510 * 511 * Cleanup is automatically handled with a call to 512 * drm_connector_cleanup() in a DRM-managed action. 513 * 514 * The connector structure should be allocated with drmm_kzalloc(). 515 * 516 * The @drm_connector_funcs.destroy hook must be NULL. 517 * 518 * Returns: 519 * Zero on success, error code on failure. 520 */ 521 int drmm_connector_init(struct drm_device *dev, 522 struct drm_connector *connector, 523 const struct drm_connector_funcs *funcs, 524 int connector_type, 525 struct i2c_adapter *ddc) 526 { 527 int ret; 528 529 if (drm_WARN_ON(dev, funcs && funcs->destroy)) 530 return -EINVAL; 531 532 ret = drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc); 533 if (ret) 534 return ret; 535 536 ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action, 537 connector); 538 if (ret) 539 return ret; 540 541 return 0; 542 } 543 EXPORT_SYMBOL(drmm_connector_init); 544 545 /** 546 * drmm_connector_hdmi_init - Init a preallocated HDMI connector 547 * @dev: DRM device 548 * @connector: A pointer to the HDMI connector to init 549 * @funcs: callbacks for this connector 550 * @hdmi_funcs: HDMI-related callbacks and capabilities for this connector 551 * @connector_type: user visible type of the connector 552 * @ddc: optional pointer to the associated ddc adapter 553 * 554 * Initialises a preallocated HDMI connector. Connectors can be 555 * subclassed as part of driver connector objects. 556 * 557 * Cleanup is automatically handled with a call to 558 * drm_connector_cleanup() in a DRM-managed action. 559 * 560 * The connector structure should be allocated with drmm_kzalloc(). 561 * 562 * The @drm_connector_funcs.destroy hook must be NULL. 563 * 564 * Returns: 565 * Zero on success, error code on failure. 566 */ 567 int drmm_connector_hdmi_init(struct drm_device *dev, 568 struct drm_connector *connector, 569 const struct drm_connector_funcs *funcs, 570 const struct drm_connector_hdmi_funcs *hdmi_funcs, 571 int connector_type, 572 struct i2c_adapter *ddc) 573 { 574 int ret; 575 576 if (!hdmi_funcs) 577 return -EINVAL; 578 579 if (!hdmi_funcs->vendor || !hdmi_funcs->product) 580 return -EINVAL; 581 582 if ((strlen(hdmi_funcs->vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) || 583 (strlen(hdmi_funcs->product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN)) 584 return -EINVAL; 585 586 if (!hdmi_funcs->supported_formats || 587 !(hdmi_funcs->supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444))) 588 return -EINVAL; 589 590 if (connector->ycbcr_420_allowed != 591 !!(hdmi_funcs->supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420))) 592 return -EINVAL; 593 594 if (!(hdmi_funcs->max_bpc == 8 || 595 hdmi_funcs->max_bpc == 10 || 596 hdmi_funcs->max_bpc == 12)) 597 return -EINVAL; 598 599 if (!hdmi_funcs->avi.clear_infoframe || 600 !hdmi_funcs->avi.write_infoframe || 601 !hdmi_funcs->hdmi.clear_infoframe || 602 !hdmi_funcs->hdmi.write_infoframe) 603 return -EINVAL; 604 605 if (hdmi_funcs->supported_hdmi_ver >= HDMI_VERSION_2_0 && 606 (!hdmi_funcs->scrambler_enable || 607 !hdmi_funcs->scrambler_disable)) { 608 drm_err(dev, "Scrambler callbacks missing for HDMI 2.x\n"); 609 return -EINVAL; 610 } 611 612 if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA || 613 connector_type == DRM_MODE_CONNECTOR_HDMIB)) 614 return -EINVAL; 615 616 ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc); 617 if (ret) 618 return ret; 619 620 /* TODO: remove after conversion to new drmm_connector_hdmi_init() */ 621 connector->hdmi.supported_formats = hdmi_funcs->supported_formats; 622 623 /* 624 * The supported HDMI version can be used to determinate the maximum 625 * TMDS character rate allowed by the specification. Some controllers, 626 * however, may support a lower rate than that version would imply. 627 * 628 * A non-zero caps->max_tmds_char_rate lets drivers override this 629 * default with the actual controller capability. A value of zero keeps 630 * the limit inferred from supported_hdmi_ver. 631 */ 632 if (hdmi_funcs->supported_hdmi_ver >= HDMI_VERSION_2_0) 633 connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ; 634 else if (hdmi_funcs->supported_hdmi_ver >= HDMI_VERSION_1_3) 635 connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ; 636 else if (hdmi_funcs->supported_hdmi_ver >= HDMI_VERSION_1_0) 637 connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ; 638 639 if (hdmi_funcs->supported_tmds_char_rate) { 640 if (hdmi_funcs->supported_tmds_char_rate > connector->hdmi.max_tmds_char_rate) { 641 drm_err(dev, "Enforced max_tmds_char_rate exceeds %llu spec limit\n", 642 connector->hdmi.max_tmds_char_rate); 643 return -EINVAL; 644 } 645 646 connector->hdmi.max_tmds_char_rate = hdmi_funcs->supported_tmds_char_rate; 647 } 648 649 /* TODO: remove after conversion to new drmm_connector_hdmi_init() */ 650 strtomem_pad(connector->hdmi.vendor, hdmi_funcs->vendor, 0); 651 strtomem_pad(connector->hdmi.product, hdmi_funcs->product, 0); 652 653 /* 654 * drm_connector_attach_max_bpc_property() requires the 655 * connector to have a state. 656 */ 657 if (connector->funcs->atomic_create_state) { 658 struct drm_connector_state *state; 659 660 state = connector->funcs->atomic_create_state(connector); 661 if (IS_ERR(state)) 662 return PTR_ERR(state); 663 664 connector->state = state; 665 } else if (connector->funcs->reset) { 666 connector->funcs->reset(connector); 667 if (!connector->state) 668 return -ENOMEM; 669 } 670 671 drm_connector_attach_max_bpc_property(connector, 8, hdmi_funcs->max_bpc); 672 /* TODO: remove after conversion to new drmm_connector_hdmi_init() */ 673 connector->max_bpc = hdmi_funcs->max_bpc; 674 675 if (hdmi_funcs->max_bpc > 8) 676 drm_connector_attach_hdr_output_metadata_property(connector); 677 678 ret = drm_connector_attach_color_format_property(connector, 679 hdmi_funcs->supported_formats); 680 if (ret) 681 return ret; 682 683 connector->hdmi.funcs = hdmi_funcs; 684 685 return 0; 686 } 687 EXPORT_SYMBOL(drmm_connector_hdmi_init); 688 689 /** 690 * drmm_connector_hdmi_ini2 - Init a preallocated HDMI connector 691 * @dev: DRM device 692 * @connector: A pointer to the HDMI connector to init 693 * @vendor: HDMI Controller Vendor name 694 * @product: HDMI Controller Product name 695 * @funcs: callbacks for this connector 696 * @hdmi_funcs: HDMI-related callbacks for this connector 697 * @connector_type: user visible type of the connector 698 * @ddc: optional pointer to the associated ddc adapter 699 * @supported_formats: Bitmask of @drm_output_color_format listing supported output formats 700 * @max_bpc: Maximum bits per char the HDMI connector supports 701 * 702 * Initialises a preallocated HDMI connector. Connectors can be 703 * subclassed as part of driver connector objects. 704 * 705 * Cleanup is automatically handled with a call to 706 * drm_connector_cleanup() in a DRM-managed action. 707 * 708 * The connector structure should be allocated with drmm_kzalloc(). 709 * 710 * The @drm_connector_funcs.destroy hook must be NULL. 711 * 712 * Returns: 713 * Zero on success, error code on failure. 714 */ 715 int drmm_connector_hdmi_ini2(struct drm_device *dev, 716 struct drm_connector *connector, 717 const char *vendor, const char *product, 718 const struct drm_connector_funcs *funcs, 719 const struct drm_connector_hdmi_funcs *hdmi_funcs, 720 int connector_type, 721 struct i2c_adapter *ddc, 722 unsigned long supported_formats, 723 unsigned int max_bpc) 724 { 725 int ret; 726 727 if (!vendor || !product) 728 return -EINVAL; 729 730 if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) || 731 (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN)) 732 return -EINVAL; 733 734 if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA || 735 connector_type == DRM_MODE_CONNECTOR_HDMIB)) 736 return -EINVAL; 737 738 if (!supported_formats || !(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444))) 739 return -EINVAL; 740 741 if (connector->ycbcr_420_allowed != !!(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420))) 742 return -EINVAL; 743 744 if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12)) 745 return -EINVAL; 746 747 if (!hdmi_funcs->avi.clear_infoframe || 748 !hdmi_funcs->avi.write_infoframe || 749 !hdmi_funcs->hdmi.clear_infoframe || 750 !hdmi_funcs->hdmi.write_infoframe) 751 return -EINVAL; 752 753 ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc); 754 if (ret) 755 return ret; 756 757 connector->hdmi.supported_formats = supported_formats; 758 strtomem_pad(connector->hdmi.vendor, vendor, 0); 759 strtomem_pad(connector->hdmi.product, product, 0); 760 761 /* 762 * drm_connector_attach_max_bpc_property() requires the 763 * connector to have a state. 764 */ 765 if (connector->funcs->atomic_create_state) { 766 struct drm_connector_state *state; 767 768 state = connector->funcs->atomic_create_state(connector); 769 if (IS_ERR(state)) 770 return PTR_ERR(state); 771 772 connector->state = state; 773 } else if (connector->funcs->reset) { 774 connector->funcs->reset(connector); 775 if (!connector->state) 776 return -ENOMEM; 777 } 778 779 drm_connector_attach_max_bpc_property(connector, 8, max_bpc); 780 connector->max_bpc = max_bpc; 781 782 if (max_bpc > 8) 783 drm_connector_attach_hdr_output_metadata_property(connector); 784 785 ret = drm_connector_attach_color_format_property(connector, supported_formats); 786 if (ret) 787 return ret; 788 789 connector->hdmi.funcs = hdmi_funcs; 790 791 return 0; 792 } 793 EXPORT_SYMBOL(drmm_connector_hdmi_ini2); 794 795 /** 796 * drm_connector_attach_edid_property - attach edid property. 797 * @connector: the connector 798 * 799 * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a 800 * edid property attached by default. This function can be used to 801 * explicitly enable the edid property in these cases. 802 */ 803 void drm_connector_attach_edid_property(struct drm_connector *connector) 804 { 805 struct drm_mode_config *config = &connector->dev->mode_config; 806 807 drm_object_attach_property(&connector->base, 808 config->edid_property, 809 0); 810 } 811 EXPORT_SYMBOL(drm_connector_attach_edid_property); 812 813 /** 814 * drm_connector_attach_encoder - attach a connector to an encoder 815 * @connector: connector to attach 816 * @encoder: encoder to attach @connector to 817 * 818 * This function links up a connector to an encoder. Note that the routing 819 * restrictions between encoders and crtcs are exposed to userspace through the 820 * possible_clones and possible_crtcs bitmasks. 821 * 822 * Returns: 823 * Zero on success, negative errno on failure. 824 */ 825 int drm_connector_attach_encoder(struct drm_connector *connector, 826 struct drm_encoder *encoder) 827 { 828 /* 829 * In the past, drivers have attempted to model the static association 830 * of connector to encoder in simple connector/encoder devices using a 831 * direct assignment of connector->encoder = encoder. This connection 832 * is a logical one and the responsibility of the core, so drivers are 833 * expected not to mess with this. 834 * 835 * Note that the error return should've been enough here, but a large 836 * majority of drivers ignores the return value, so add in a big WARN 837 * to get people's attention. 838 */ 839 if (WARN_ON(connector->encoder)) 840 return -EINVAL; 841 842 connector->possible_encoders |= drm_encoder_mask(encoder); 843 844 return 0; 845 } 846 EXPORT_SYMBOL(drm_connector_attach_encoder); 847 848 /** 849 * drm_connector_has_possible_encoder - check if the connector and encoder are 850 * associated with each other 851 * @connector: the connector 852 * @encoder: the encoder 853 * 854 * Returns: 855 * True if @encoder is one of the possible encoders for @connector. 856 */ 857 bool drm_connector_has_possible_encoder(struct drm_connector *connector, 858 struct drm_encoder *encoder) 859 { 860 return connector->possible_encoders & drm_encoder_mask(encoder); 861 } 862 EXPORT_SYMBOL(drm_connector_has_possible_encoder); 863 864 static void drm_mode_remove(struct drm_connector *connector, 865 struct drm_display_mode *mode) 866 { 867 list_del(&mode->head); 868 drm_mode_destroy(connector->dev, mode); 869 } 870 871 /** 872 * drm_connector_cec_phys_addr_invalidate - invalidate CEC physical address 873 * @connector: connector undergoing CEC operation 874 * 875 * Invalidated CEC physical address set for this DRM connector. 876 */ 877 void drm_connector_cec_phys_addr_invalidate(struct drm_connector *connector) 878 { 879 mutex_lock(&connector->cec.mutex); 880 881 if (connector->cec.funcs && 882 connector->cec.funcs->phys_addr_invalidate) 883 connector->cec.funcs->phys_addr_invalidate(connector); 884 885 mutex_unlock(&connector->cec.mutex); 886 } 887 EXPORT_SYMBOL(drm_connector_cec_phys_addr_invalidate); 888 889 /** 890 * drm_connector_cec_phys_addr_set - propagate CEC physical address 891 * @connector: connector undergoing CEC operation 892 * 893 * Propagate CEC physical address from the display_info to this DRM connector. 894 */ 895 void drm_connector_cec_phys_addr_set(struct drm_connector *connector) 896 { 897 u16 addr; 898 899 mutex_lock(&connector->cec.mutex); 900 901 addr = connector->display_info.source_physical_address; 902 903 if (connector->cec.funcs && 904 connector->cec.funcs->phys_addr_set) 905 connector->cec.funcs->phys_addr_set(connector, addr); 906 907 mutex_unlock(&connector->cec.mutex); 908 } 909 EXPORT_SYMBOL(drm_connector_cec_phys_addr_set); 910 911 /** 912 * drm_connector_cleanup - cleans up an initialised connector 913 * @connector: connector to cleanup 914 * 915 * Cleans up the connector but doesn't free the object. 916 */ 917 void drm_connector_cleanup(struct drm_connector *connector) 918 { 919 struct drm_device *dev = connector->dev; 920 struct drm_display_mode *mode, *t; 921 922 /* The connector should have been removed from userspace long before 923 * it is finally destroyed. 924 */ 925 if (WARN_ON(connector->registration_state == 926 DRM_CONNECTOR_REGISTERED)) 927 drm_connector_unregister(connector); 928 929 if (connector->hdmi.scdc_work_initialized) 930 cancel_delayed_work_sync(&connector->hdmi.scdc_work); 931 932 platform_device_unregister(connector->hdmi_audio.codec_pdev); 933 934 if (connector->privacy_screen) { 935 drm_privacy_screen_put(connector->privacy_screen); 936 connector->privacy_screen = NULL; 937 } 938 939 if (connector->tile_group) { 940 drm_mode_put_tile_group(dev, connector->tile_group); 941 connector->tile_group = NULL; 942 } 943 944 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) 945 drm_mode_remove(connector, mode); 946 947 list_for_each_entry_safe(mode, t, &connector->modes, head) 948 drm_mode_remove(connector, mode); 949 950 ida_free(&drm_connector_enum_list[connector->connector_type].ida, 951 connector->connector_type_id); 952 953 ida_free(&dev->mode_config.connector_ida, connector->index); 954 955 kfree(connector->display_info.bus_formats); 956 kfree(connector->display_info.vics); 957 drm_mode_object_unregister(dev, &connector->base); 958 kfree(connector->name); 959 connector->name = NULL; 960 fwnode_handle_put(connector->fwnode); 961 connector->fwnode = NULL; 962 963 drm_connector_remove(connector); 964 965 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); 966 if (connector->state && connector->funcs->atomic_destroy_state) 967 connector->funcs->atomic_destroy_state(connector, 968 connector->state); 969 970 mutex_destroy(&connector->hdmi_audio.lock); 971 mutex_destroy(&connector->hdmi.infoframes.lock); 972 mutex_destroy(&connector->mutex); 973 974 memset(connector, 0, sizeof(*connector)); 975 976 if (dev->registered) 977 drm_sysfs_hotplug_event(dev); 978 } 979 EXPORT_SYMBOL(drm_connector_cleanup); 980 981 /** 982 * drm_connector_register - register a connector 983 * @connector: the connector to register 984 * 985 * Register userspace interfaces for a connector. Drivers shouldn't call this 986 * function. Static connectors will be registered automatically by DRM core 987 * from drm_dev_register(), dynamic connectors (MST) should be registered by 988 * drivers calling drm_connector_dynamic_register(). 989 * 990 * When the connector is no longer available, callers must call 991 * drm_connector_unregister(). 992 * 993 * Note: Existing uses of this function in drivers should be a nop already and 994 * are scheduled to be removed. 995 * 996 * Returns: 997 * Zero on success, error code on failure. 998 */ 999 int drm_connector_register(struct drm_connector *connector) 1000 { 1001 int ret = 0; 1002 1003 if (!connector->dev->registered) 1004 return 0; 1005 1006 mutex_lock(&connector->mutex); 1007 if (connector->registration_state != DRM_CONNECTOR_INITIALIZING) 1008 goto unlock; 1009 1010 ret = drm_sysfs_connector_add(connector); 1011 if (ret) 1012 goto unlock; 1013 1014 drm_debugfs_connector_add(connector); 1015 1016 if (connector->funcs->late_register) { 1017 ret = connector->funcs->late_register(connector); 1018 if (ret) 1019 goto err_debugfs; 1020 } 1021 1022 ret = drm_sysfs_connector_add_late(connector); 1023 if (ret) 1024 goto err_late_register; 1025 1026 drm_mode_object_register(connector->dev, &connector->base); 1027 1028 connector->registration_state = DRM_CONNECTOR_REGISTERED; 1029 1030 /* Let userspace know we have a new connector */ 1031 drm_sysfs_connector_hotplug_event(connector); 1032 1033 if (connector->privacy_screen) 1034 drm_privacy_screen_register_notifier(connector->privacy_screen, 1035 &connector->privacy_screen_notifier); 1036 1037 mutex_lock(&connector_list_lock); 1038 list_add_tail(&connector->global_connector_list_entry, &connector_list); 1039 mutex_unlock(&connector_list_lock); 1040 goto unlock; 1041 1042 err_late_register: 1043 if (connector->funcs->early_unregister) 1044 connector->funcs->early_unregister(connector); 1045 err_debugfs: 1046 drm_debugfs_connector_remove(connector); 1047 drm_sysfs_connector_remove(connector); 1048 unlock: 1049 mutex_unlock(&connector->mutex); 1050 return ret; 1051 } 1052 EXPORT_SYMBOL(drm_connector_register); 1053 1054 /** 1055 * drm_connector_dynamic_register - register a dynamic connector 1056 * @connector: the connector to register 1057 * 1058 * Register userspace interfaces for a connector. Only call this for connectors 1059 * initialized by calling drm_connector_dynamic_init(). All other connectors 1060 * will be registered automatically when calling drm_dev_register(). 1061 * 1062 * When the connector is no longer available the driver must call 1063 * drm_connector_unregister(). 1064 * 1065 * Returns: 1066 * Zero on success, error code on failure. 1067 */ 1068 int drm_connector_dynamic_register(struct drm_connector *connector) 1069 { 1070 /* Was the connector inited already? */ 1071 if (WARN_ON(!(connector->funcs && connector->funcs->destroy))) 1072 return -EINVAL; 1073 1074 drm_connector_add(connector); 1075 1076 return drm_connector_register(connector); 1077 } 1078 EXPORT_SYMBOL(drm_connector_dynamic_register); 1079 1080 /** 1081 * drm_connector_unregister - unregister a connector 1082 * @connector: the connector to unregister 1083 * 1084 * Unregister userspace interfaces for a connector. Drivers should call this 1085 * for dynamic connectors (MST) only, which were registered explicitly by 1086 * calling drm_connector_dynamic_register(). All other - static - connectors 1087 * will be unregistered automatically by DRM core and drivers shouldn't call 1088 * this function for those. 1089 * 1090 * Note: Existing uses of this function in drivers for static connectors 1091 * should be a nop already and are scheduled to be removed. 1092 */ 1093 void drm_connector_unregister(struct drm_connector *connector) 1094 { 1095 mutex_lock(&connector->mutex); 1096 if (connector->registration_state != DRM_CONNECTOR_REGISTERED) { 1097 mutex_unlock(&connector->mutex); 1098 return; 1099 } 1100 1101 mutex_lock(&connector_list_lock); 1102 list_del_init(&connector->global_connector_list_entry); 1103 mutex_unlock(&connector_list_lock); 1104 1105 if (connector->privacy_screen) 1106 drm_privacy_screen_unregister_notifier( 1107 connector->privacy_screen, 1108 &connector->privacy_screen_notifier); 1109 1110 drm_sysfs_connector_remove_early(connector); 1111 1112 if (connector->funcs->early_unregister) 1113 connector->funcs->early_unregister(connector); 1114 1115 drm_debugfs_connector_remove(connector); 1116 drm_sysfs_connector_remove(connector); 1117 1118 connector->registration_state = DRM_CONNECTOR_UNREGISTERED; 1119 mutex_unlock(&connector->mutex); 1120 } 1121 EXPORT_SYMBOL(drm_connector_unregister); 1122 1123 void drm_connector_unregister_all(struct drm_device *dev) 1124 { 1125 struct drm_connector *connector; 1126 struct drm_connector_list_iter conn_iter; 1127 1128 drm_connector_list_iter_begin(dev, &conn_iter); 1129 drm_for_each_connector_iter(connector, &conn_iter) 1130 drm_connector_unregister(connector); 1131 drm_connector_list_iter_end(&conn_iter); 1132 } 1133 1134 int drm_connector_register_all(struct drm_device *dev) 1135 { 1136 struct drm_connector *connector; 1137 struct drm_connector_list_iter conn_iter; 1138 int ret = 0; 1139 1140 drm_connector_list_iter_begin(dev, &conn_iter); 1141 drm_for_each_connector_iter(connector, &conn_iter) { 1142 ret = drm_connector_register(connector); 1143 if (ret) 1144 break; 1145 } 1146 drm_connector_list_iter_end(&conn_iter); 1147 1148 if (ret) 1149 drm_connector_unregister_all(dev); 1150 return ret; 1151 } 1152 1153 /** 1154 * drm_get_connector_status_name - return a string for connector status 1155 * @status: connector status to compute name of 1156 * 1157 * In contrast to the other drm_get_*_name functions this one here returns a 1158 * const pointer and hence is threadsafe. 1159 * 1160 * Returns: connector status string 1161 */ 1162 const char *drm_get_connector_status_name(enum drm_connector_status status) 1163 { 1164 if (status == connector_status_connected) 1165 return "connected"; 1166 else if (status == connector_status_disconnected) 1167 return "disconnected"; 1168 else 1169 return "unknown"; 1170 } 1171 EXPORT_SYMBOL(drm_get_connector_status_name); 1172 1173 /** 1174 * drm_get_connector_force_name - return a string for connector force 1175 * @force: connector force to get name of 1176 * 1177 * Returns: const pointer to name. 1178 */ 1179 const char *drm_get_connector_force_name(enum drm_connector_force force) 1180 { 1181 switch (force) { 1182 case DRM_FORCE_UNSPECIFIED: 1183 return "unspecified"; 1184 case DRM_FORCE_OFF: 1185 return "off"; 1186 case DRM_FORCE_ON: 1187 return "on"; 1188 case DRM_FORCE_ON_DIGITAL: 1189 return "digital"; 1190 default: 1191 return "unknown"; 1192 } 1193 } 1194 1195 #ifdef CONFIG_LOCKDEP 1196 static struct lockdep_map connector_list_iter_dep_map = { 1197 .name = "drm_connector_list_iter" 1198 }; 1199 #endif 1200 1201 /** 1202 * drm_connector_list_iter_begin - initialize a connector_list iterator 1203 * @dev: DRM device 1204 * @iter: connector_list iterator 1205 * 1206 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter 1207 * must always be cleaned up again by calling drm_connector_list_iter_end(). 1208 * Iteration itself happens using drm_connector_list_iter_next() or 1209 * drm_for_each_connector_iter(). 1210 */ 1211 void drm_connector_list_iter_begin(struct drm_device *dev, 1212 struct drm_connector_list_iter *iter) 1213 { 1214 iter->dev = dev; 1215 iter->conn = NULL; 1216 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_); 1217 } 1218 EXPORT_SYMBOL(drm_connector_list_iter_begin); 1219 1220 /* 1221 * Extra-safe connector put function that works in any context. Should only be 1222 * used from the connector_iter functions, where we never really expect to 1223 * actually release the connector when dropping our final reference. 1224 */ 1225 static void 1226 __drm_connector_put_safe(struct drm_connector *conn) 1227 { 1228 struct drm_mode_config *config = &conn->dev->mode_config; 1229 1230 lockdep_assert_held(&config->connector_list_lock); 1231 1232 if (!refcount_dec_and_test(&conn->base.refcount.refcount)) 1233 return; 1234 1235 llist_add(&conn->free_node, &config->connector_free_list); 1236 schedule_work(&config->connector_free_work); 1237 } 1238 1239 /** 1240 * drm_connector_list_iter_next - return next connector 1241 * @iter: connector_list iterator 1242 * 1243 * Returns: the next connector for @iter, or NULL when the list walk has 1244 * completed. 1245 */ 1246 struct drm_connector * 1247 drm_connector_list_iter_next(struct drm_connector_list_iter *iter) 1248 { 1249 struct drm_connector *old_conn = iter->conn; 1250 struct drm_mode_config *config = &iter->dev->mode_config; 1251 struct list_head *lhead; 1252 unsigned long flags; 1253 1254 spin_lock_irqsave(&config->connector_list_lock, flags); 1255 lhead = old_conn ? &old_conn->head : &config->connector_list; 1256 1257 do { 1258 if (lhead->next == &config->connector_list) { 1259 iter->conn = NULL; 1260 break; 1261 } 1262 1263 lhead = lhead->next; 1264 iter->conn = list_entry(lhead, struct drm_connector, head); 1265 1266 /* loop until it's not a zombie connector */ 1267 } while (!kref_get_unless_zero(&iter->conn->base.refcount)); 1268 1269 if (old_conn) 1270 __drm_connector_put_safe(old_conn); 1271 spin_unlock_irqrestore(&config->connector_list_lock, flags); 1272 1273 return iter->conn; 1274 } 1275 EXPORT_SYMBOL(drm_connector_list_iter_next); 1276 1277 /** 1278 * drm_connector_list_iter_end - tear down a connector_list iterator 1279 * @iter: connector_list iterator 1280 * 1281 * Tears down @iter and releases any resources (like &drm_connector references) 1282 * acquired while walking the list. This must always be called, both when the 1283 * iteration completes fully or when it was aborted without walking the entire 1284 * list. 1285 */ 1286 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter) 1287 { 1288 struct drm_mode_config *config = &iter->dev->mode_config; 1289 unsigned long flags; 1290 1291 iter->dev = NULL; 1292 if (iter->conn) { 1293 spin_lock_irqsave(&config->connector_list_lock, flags); 1294 __drm_connector_put_safe(iter->conn); 1295 spin_unlock_irqrestore(&config->connector_list_lock, flags); 1296 } 1297 lock_release(&connector_list_iter_dep_map, _RET_IP_); 1298 } 1299 EXPORT_SYMBOL(drm_connector_list_iter_end); 1300 1301 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { 1302 { SubPixelUnknown, "Unknown" }, 1303 { SubPixelHorizontalRGB, "Horizontal RGB" }, 1304 { SubPixelHorizontalBGR, "Horizontal BGR" }, 1305 { SubPixelVerticalRGB, "Vertical RGB" }, 1306 { SubPixelVerticalBGR, "Vertical BGR" }, 1307 { SubPixelNone, "None" }, 1308 }; 1309 1310 /** 1311 * drm_get_subpixel_order_name - return a string for a given subpixel enum 1312 * @order: enum of subpixel_order 1313 * 1314 * Note you could abuse this and return something out of bounds, but that 1315 * would be a caller error. No unscrubbed user data should make it here. 1316 * 1317 * Returns: string describing an enumerated subpixel property 1318 */ 1319 const char *drm_get_subpixel_order_name(enum subpixel_order order) 1320 { 1321 return drm_subpixel_enum_list[order].name; 1322 } 1323 EXPORT_SYMBOL(drm_get_subpixel_order_name); 1324 1325 static const struct drm_prop_enum_list drm_dpms_enum_list[] = { 1326 { DRM_MODE_DPMS_ON, "On" }, 1327 { DRM_MODE_DPMS_STANDBY, "Standby" }, 1328 { DRM_MODE_DPMS_SUSPEND, "Suspend" }, 1329 { DRM_MODE_DPMS_OFF, "Off" } 1330 }; 1331 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) 1332 1333 static const struct drm_prop_enum_list drm_link_status_enum_list[] = { 1334 { DRM_MODE_LINK_STATUS_GOOD, "Good" }, 1335 { DRM_MODE_LINK_STATUS_BAD, "Bad" }, 1336 }; 1337 1338 static const struct drm_prop_enum_list drm_panel_type_enum_list[] = { 1339 { DRM_MODE_PANEL_TYPE_UNKNOWN, "unknown" }, 1340 { DRM_MODE_PANEL_TYPE_OLED, "OLED" }, 1341 { DRM_MODE_PANEL_TYPE_LCD, "LCD" }, 1342 }; 1343 1344 /** 1345 * drm_display_info_set_bus_formats - set the supported bus formats 1346 * @info: display info to store bus formats in 1347 * @formats: array containing the supported bus formats 1348 * @num_formats: the number of entries in the fmts array 1349 * 1350 * Store the supported bus formats in display info structure. 1351 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for 1352 * a full list of available formats. 1353 * 1354 * Returns: 1355 * 0 on success or a negative error code on failure. 1356 */ 1357 int drm_display_info_set_bus_formats(struct drm_display_info *info, 1358 const u32 *formats, 1359 unsigned int num_formats) 1360 { 1361 u32 *fmts = NULL; 1362 1363 if (!formats && num_formats) 1364 return -EINVAL; 1365 1366 if (formats && num_formats) { 1367 fmts = kmemdup(formats, sizeof(*formats) * num_formats, 1368 GFP_KERNEL); 1369 if (!fmts) 1370 return -ENOMEM; 1371 } 1372 1373 kfree(info->bus_formats); 1374 info->bus_formats = fmts; 1375 info->num_bus_formats = num_formats; 1376 1377 return 0; 1378 } 1379 EXPORT_SYMBOL(drm_display_info_set_bus_formats); 1380 1381 /* Optional connector properties. */ 1382 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { 1383 { DRM_MODE_SCALE_NONE, "None" }, 1384 { DRM_MODE_SCALE_FULLSCREEN, "Full" }, 1385 { DRM_MODE_SCALE_CENTER, "Center" }, 1386 { DRM_MODE_SCALE_ASPECT, "Full aspect" }, 1387 }; 1388 1389 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { 1390 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, 1391 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, 1392 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, 1393 }; 1394 1395 static const struct drm_prop_enum_list drm_content_type_enum_list[] = { 1396 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" }, 1397 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" }, 1398 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" }, 1399 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" }, 1400 { DRM_MODE_CONTENT_TYPE_GAME, "Game" }, 1401 }; 1402 1403 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = { 1404 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" }, 1405 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" }, 1406 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" }, 1407 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" }, 1408 }; 1409 1410 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { 1411 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 1412 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 1413 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 1414 }; 1415 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) 1416 1417 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { 1418 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 1419 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 1420 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 1421 }; 1422 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, 1423 drm_dvi_i_subconnector_enum_list) 1424 1425 static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = { 1426 { DRM_MODE_TV_MODE_NTSC, "NTSC" }, 1427 { DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" }, 1428 { DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" }, 1429 { DRM_MODE_TV_MODE_PAL, "PAL" }, 1430 { DRM_MODE_TV_MODE_PAL_M, "PAL-M" }, 1431 { DRM_MODE_TV_MODE_PAL_N, "PAL-N" }, 1432 { DRM_MODE_TV_MODE_SECAM, "SECAM" }, 1433 { DRM_MODE_TV_MODE_MONOCHROME, "Mono" }, 1434 }; 1435 DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list) 1436 1437 /** 1438 * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value 1439 * @name: TV Mode name we want to convert 1440 * @len: Length of @name 1441 * 1442 * Translates @name into an enum drm_connector_tv_mode. 1443 * 1444 * Returns: the enum value on success, a negative errno otherwise. 1445 */ 1446 int drm_get_tv_mode_from_name(const char *name, size_t len) 1447 { 1448 unsigned int i; 1449 1450 for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) { 1451 const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i]; 1452 1453 if (strlen(item->name) == len && !strncmp(item->name, name, len)) 1454 return item->type; 1455 } 1456 1457 return -EINVAL; 1458 } 1459 EXPORT_SYMBOL(drm_get_tv_mode_from_name); 1460 1461 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { 1462 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 1463 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 1464 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 1465 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 1466 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 1467 }; 1468 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) 1469 1470 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { 1471 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 1472 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 1473 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 1474 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 1475 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 1476 }; 1477 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, 1478 drm_tv_subconnector_enum_list) 1479 1480 static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = { 1481 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ 1482 { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */ 1483 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */ 1484 { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */ 1485 { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */ 1486 { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */ 1487 { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */ 1488 }; 1489 1490 DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name, 1491 drm_dp_subconnector_enum_list) 1492 1493 1494 static const char * const colorspace_names[] = { 1495 /* For Default case, driver will set the colorspace */ 1496 [DRM_MODE_COLORIMETRY_DEFAULT] = "Default", 1497 /* Standard Definition Colorimetry based on CEA 861 */ 1498 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC", 1499 [DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC", 1500 /* Standard Definition Colorimetry based on IEC 61966-2-4 */ 1501 [DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601", 1502 /* High Definition Colorimetry based on IEC 61966-2-4 */ 1503 [DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709", 1504 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */ 1505 [DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601", 1506 /* Colorimetry based on IEC 61966-2-5 [33] */ 1507 [DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601", 1508 /* Colorimetry based on IEC 61966-2-5 */ 1509 [DRM_MODE_COLORIMETRY_OPRGB] = "opRGB", 1510 /* Colorimetry based on ITU-R BT.2020 */ 1511 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC", 1512 /* Colorimetry based on ITU-R BT.2020 */ 1513 [DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB", 1514 /* Colorimetry based on ITU-R BT.2020 */ 1515 [DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC", 1516 /* Added as part of Additional Colorimetry Extension in 861.G */ 1517 [DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65", 1518 [DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater", 1519 [DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED", 1520 /* Colorimetry based on scRGB (IEC 61966-2-2) */ 1521 [DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT", 1522 [DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC", 1523 }; 1524 1525 /** 1526 * drm_get_colorspace_name - return a string for color encoding 1527 * @colorspace: color space to compute name of 1528 * 1529 * In contrast to the other drm_get_*_name functions this one here returns a 1530 * const pointer and hence is threadsafe. 1531 */ 1532 const char *drm_get_colorspace_name(enum drm_colorspace colorspace) 1533 { 1534 if (colorspace < ARRAY_SIZE(colorspace_names) && colorspace_names[colorspace]) 1535 return colorspace_names[colorspace]; 1536 else 1537 return "(null)"; 1538 } 1539 1540 static const u32 hdmi_colorspaces = 1541 BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) | 1542 BIT(DRM_MODE_COLORIMETRY_BT709_YCC) | 1543 BIT(DRM_MODE_COLORIMETRY_XVYCC_601) | 1544 BIT(DRM_MODE_COLORIMETRY_XVYCC_709) | 1545 BIT(DRM_MODE_COLORIMETRY_SYCC_601) | 1546 BIT(DRM_MODE_COLORIMETRY_OPYCC_601) | 1547 BIT(DRM_MODE_COLORIMETRY_OPRGB) | 1548 BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) | 1549 BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | 1550 BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) | 1551 BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) | 1552 BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER); 1553 1554 static const u32 hdmi_colorformats = 1555 BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444) | 1556 BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR444) | 1557 BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422) | 1558 BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420); 1559 1560 static const u32 dp_colorformats = 1561 BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444) | 1562 BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR444) | 1563 BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422) | 1564 BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420); 1565 1566 /* 1567 * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry 1568 * Format Table 2-120 1569 */ 1570 static const u32 dp_colorspaces = 1571 BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) | 1572 BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) | 1573 BIT(DRM_MODE_COLORIMETRY_OPRGB) | 1574 BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) | 1575 BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | 1576 BIT(DRM_MODE_COLORIMETRY_BT601_YCC) | 1577 BIT(DRM_MODE_COLORIMETRY_BT709_YCC) | 1578 BIT(DRM_MODE_COLORIMETRY_XVYCC_601) | 1579 BIT(DRM_MODE_COLORIMETRY_XVYCC_709) | 1580 BIT(DRM_MODE_COLORIMETRY_SYCC_601) | 1581 BIT(DRM_MODE_COLORIMETRY_OPYCC_601) | 1582 BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) | 1583 BIT(DRM_MODE_COLORIMETRY_BT2020_YCC); 1584 1585 static const struct drm_prop_enum_list broadcast_rgb_names[] = { 1586 { DRM_HDMI_BROADCAST_RGB_AUTO, "Automatic" }, 1587 { DRM_HDMI_BROADCAST_RGB_FULL, "Full" }, 1588 { DRM_HDMI_BROADCAST_RGB_LIMITED, "Limited 16:235" }, 1589 }; 1590 1591 /* 1592 * drm_hdmi_connector_get_broadcast_rgb_name - Return a string for HDMI connector RGB broadcast selection 1593 * @broadcast_rgb: Broadcast RGB selection to compute name of 1594 * 1595 * Returns: the name of the Broadcast RGB selection, or NULL if the type 1596 * is not valid. 1597 */ 1598 const char * 1599 drm_hdmi_connector_get_broadcast_rgb_name(enum drm_hdmi_broadcast_rgb broadcast_rgb) 1600 { 1601 if (broadcast_rgb >= ARRAY_SIZE(broadcast_rgb_names)) 1602 return NULL; 1603 1604 return broadcast_rgb_names[broadcast_rgb].name; 1605 } 1606 EXPORT_SYMBOL(drm_hdmi_connector_get_broadcast_rgb_name); 1607 1608 static const char * const output_format_str[] = { 1609 [DRM_OUTPUT_COLOR_FORMAT_RGB444] = "RGB", 1610 [DRM_OUTPUT_COLOR_FORMAT_YCBCR420] = "YUV 4:2:0", 1611 [DRM_OUTPUT_COLOR_FORMAT_YCBCR422] = "YUV 4:2:2", 1612 [DRM_OUTPUT_COLOR_FORMAT_YCBCR444] = "YUV 4:4:4", 1613 }; 1614 1615 /* 1616 * drm_hdmi_connector_get_output_format_name() - Return a string for HDMI connector output format 1617 * @fmt: Output format to compute name of 1618 * 1619 * Returns: the name of the output format, or NULL if the type is not 1620 * valid. 1621 */ 1622 const char * 1623 drm_hdmi_connector_get_output_format_name(enum drm_output_color_format fmt) 1624 { 1625 if (fmt >= ARRAY_SIZE(output_format_str)) 1626 return NULL; 1627 1628 return output_format_str[fmt]; 1629 } 1630 EXPORT_SYMBOL(drm_hdmi_connector_get_output_format_name); 1631 1632 /** 1633 * DOC: standard connector properties 1634 * 1635 * DRM connectors have a few standardized properties: 1636 * 1637 * EDID: 1638 * Blob property which contains the current EDID read from the sink. This 1639 * is useful to parse sink identification information like vendor, model 1640 * and serial. Drivers should update this property by calling 1641 * drm_connector_update_edid_property(), usually after having parsed 1642 * the EDID using drm_add_edid_modes(). Userspace cannot change this 1643 * property. 1644 * 1645 * User-space should not parse the EDID to obtain information exposed via 1646 * other KMS properties (because the kernel might apply limits, quirks or 1647 * fixups to the EDID). For instance, user-space should not try to parse 1648 * mode lists from the EDID. 1649 * DPMS: 1650 * Legacy property for setting the power state of the connector. For atomic 1651 * drivers this is only provided for backwards compatibility with existing 1652 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the 1653 * connector is linked to. Drivers should never set this property directly, 1654 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms 1655 * callback. For atomic drivers the remapping to the "ACTIVE" property is 1656 * implemented in the DRM core. 1657 * 1658 * On atomic drivers any DPMS setproperty ioctl where the value does not 1659 * change is completely skipped, otherwise a full atomic commit will occur. 1660 * On legacy drivers the exact behavior is driver specific. 1661 * 1662 * Note that this property cannot be set through the MODE_ATOMIC ioctl, 1663 * userspace must use "ACTIVE" on the CRTC instead. 1664 * 1665 * WARNING: 1666 * 1667 * For userspace also running on legacy drivers the "DPMS" semantics are a 1668 * lot more complicated. First, userspace cannot rely on the "DPMS" value 1669 * returned by the GETCONNECTOR actually reflecting reality, because many 1670 * drivers fail to update it. For atomic drivers this is taken care of in 1671 * drm_atomic_helper_update_legacy_modeset_state(). 1672 * 1673 * The second issue is that the DPMS state is only well-defined when the 1674 * connector is connected to a CRTC. In atomic the DRM core enforces that 1675 * "ACTIVE" is off in such a case, no such checks exists for "DPMS". 1676 * 1677 * Finally, when enabling an output using the legacy SETCONFIG ioctl then 1678 * "DPMS" is forced to ON. But see above, that might not be reflected in 1679 * the software value on legacy drivers. 1680 * 1681 * Summarizing: Only set "DPMS" when the connector is known to be enabled, 1682 * assume that a successful SETCONFIG call also sets "DPMS" to on, and 1683 * never read back the value of "DPMS" because it can be incorrect. 1684 * panel_type: 1685 * Immutable enum property to indicate the type of connected panel. 1686 * Possible values are "unknown" (default), "OLED", and "LCD". 1687 * PATH: 1688 * Connector path property to identify how this sink is physically 1689 * connected. Used by DP MST. This should be set by calling 1690 * drm_connector_set_path_property(), in the case of DP MST with the 1691 * path property the MST manager created. Userspace cannot change this 1692 * property. 1693 * 1694 * In the case of DP MST, the property has the format 1695 * ``mst:<parent>-<ports>`` where ``<parent>`` is the KMS object ID of the 1696 * parent connector and ``<ports>`` is a hyphen-separated list of DP MST 1697 * port numbers. Note, KMS object IDs are not guaranteed to be stable 1698 * across reboots. 1699 * TILE: 1700 * Connector tile group property to indicate how a set of DRM connector 1701 * compose together into one logical screen. This is used by both high-res 1702 * external screens (often only using a single cable, but exposing multiple 1703 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which 1704 * are not gen-locked. Note that for tiled panels which are genlocked, like 1705 * dual-link LVDS or dual-link DSI, the driver should try to not expose the 1706 * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers 1707 * should update this value using drm_connector_set_tile_property(). 1708 * Userspace cannot change this property. 1709 * link-status: 1710 * Connector link-status property to indicate the status of link. The 1711 * default value of link-status is "GOOD". If something fails during or 1712 * after modeset, the kernel driver may set this to "BAD" and issue a 1713 * hotplug uevent. Drivers should update this value using 1714 * drm_connector_set_link_status_property(). 1715 * 1716 * When user-space receives the hotplug uevent and detects a "BAD" 1717 * link-status, the sink doesn't receive pixels anymore (e.g. the screen 1718 * becomes completely black). The list of available modes may have 1719 * changed. User-space is expected to pick a new mode if the current one 1720 * has disappeared and perform a new modeset with link-status set to 1721 * "GOOD" to re-enable the connector. 1722 * 1723 * If multiple connectors share the same CRTC and one of them gets a "BAD" 1724 * link-status, the other are unaffected (ie. the sinks still continue to 1725 * receive pixels). 1726 * 1727 * When user-space performs an atomic commit on a connector with a "BAD" 1728 * link-status without resetting the property to "GOOD", the sink may 1729 * still not receive pixels. When user-space performs an atomic commit 1730 * which resets the link-status property to "GOOD" without the 1731 * ALLOW_MODESET flag set, it might fail because a modeset is required. 1732 * 1733 * User-space can only change link-status to "GOOD", changing it to "BAD" 1734 * is a no-op. 1735 * 1736 * For backwards compatibility with non-atomic userspace the kernel 1737 * tries to automatically set the link-status back to "GOOD" in the 1738 * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar 1739 * to how it might fail if a different screen has been connected in the 1740 * interim. 1741 * non_desktop: 1742 * Indicates the output should be ignored for purposes of displaying a 1743 * standard desktop environment or console. This is most likely because 1744 * the output device is not rectilinear. 1745 * Content Protection: 1746 * This property is used by userspace to request the kernel protect future 1747 * content communicated over the link. When requested, kernel will apply 1748 * the appropriate means of protection (most often HDCP), and use the 1749 * property to tell userspace the protection is active. 1750 * 1751 * Drivers can set this up by calling 1752 * drm_connector_attach_content_protection_property() on initialization. 1753 * 1754 * The value of this property can be one of the following: 1755 * 1756 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0 1757 * The link is not protected, content is transmitted in the clear. 1758 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1 1759 * Userspace has requested content protection, but the link is not 1760 * currently protected. When in this state, kernel should enable 1761 * Content Protection as soon as possible. 1762 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2 1763 * Userspace has requested content protection, and the link is 1764 * protected. Only the driver can set the property to this value. 1765 * If userspace attempts to set to ENABLED, kernel will return 1766 * -EINVAL. 1767 * 1768 * A few guidelines: 1769 * 1770 * - DESIRED state should be preserved until userspace de-asserts it by 1771 * setting the property to UNDESIRED. This means ENABLED should only 1772 * transition to UNDESIRED when the user explicitly requests it. 1773 * - If the state is DESIRED, kernel should attempt to re-authenticate the 1774 * link whenever possible. This includes across disable/enable, dpms, 1775 * hotplug, downstream device changes, link status failures, etc.. 1776 * - Kernel sends uevent with the connector id and property id through 1777 * @drm_hdcp_update_content_protection, upon below kernel triggered 1778 * scenarios: 1779 * 1780 * - DESIRED -> ENABLED (authentication success) 1781 * - ENABLED -> DESIRED (termination of authentication) 1782 * - Please note no uevents for userspace triggered property state changes, 1783 * which can't fail such as 1784 * 1785 * - DESIRED/ENABLED -> UNDESIRED 1786 * - UNDESIRED -> DESIRED 1787 * - Userspace is responsible for polling the property or listen to uevents 1788 * to determine when the value transitions from ENABLED to DESIRED. 1789 * This signifies the link is no longer protected and userspace should 1790 * take appropriate action (whatever that might be). 1791 * 1792 * HDCP Content Type: 1793 * This Enum property is used by the userspace to declare the content type 1794 * of the display stream, to kernel. Here display stream stands for any 1795 * display content that userspace intended to display through HDCP 1796 * encryption. 1797 * 1798 * Content Type of a stream is decided by the owner of the stream, as 1799 * "HDCP Type0" or "HDCP Type1". 1800 * 1801 * The value of the property can be one of the below: 1802 * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0 1803 * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1 1804 * 1805 * When kernel starts the HDCP authentication (see "Content Protection" 1806 * for details), it uses the content type in "HDCP Content Type" 1807 * for performing the HDCP authentication with the display sink. 1808 * 1809 * Please note in HDCP spec versions, a link can be authenticated with 1810 * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be 1811 * authenticated with HDCP1.4 only for Content Type 0(though it is implicit 1812 * in nature. As there is no reference for Content Type in HDCP1.4). 1813 * 1814 * HDCP2.2 authentication protocol itself takes the "Content Type" as a 1815 * parameter, which is a input for the DP HDCP2.2 encryption algo. 1816 * 1817 * In case of Type 0 content protection request, kernel driver can choose 1818 * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for 1819 * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send 1820 * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link). 1821 * But if the content is classified as "HDCP Type 1", above mentioned 1822 * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't 1823 * authenticate the HDCP1.4 capable sink for "HDCP Type 1". 1824 * 1825 * Please note userspace can be ignorant of the HDCP versions used by the 1826 * kernel driver to achieve the "HDCP Content Type". 1827 * 1828 * At current scenario, classifying a content as Type 1 ensures that the 1829 * content will be displayed only through the HDCP2.2 encrypted link. 1830 * 1831 * Note that the HDCP Content Type property is introduced at HDCP 2.2, and 1832 * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2 1833 * (hence supporting Type 0 and Type 1). Based on how next versions of 1834 * HDCP specs are defined content Type could be used for higher versions 1835 * too. 1836 * 1837 * If content type is changed when "Content Protection" is not UNDESIRED, 1838 * then kernel will disable the HDCP and re-enable with new type in the 1839 * same atomic commit. And when "Content Protection" is ENABLED, it means 1840 * that link is HDCP authenticated and encrypted, for the transmission of 1841 * the Type of stream mentioned at "HDCP Content Type". 1842 * 1843 * HDR_OUTPUT_METADATA: 1844 * Connector property to enable userspace to send HDR Metadata to 1845 * driver. This metadata is based on the composition and blending 1846 * policies decided by user, taking into account the hardware and 1847 * sink capabilities. The driver gets this metadata and creates a 1848 * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI, 1849 * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then 1850 * sent to sink. This notifies the sink of the upcoming frame's Color 1851 * Encoding and Luminance parameters. 1852 * 1853 * Userspace first need to detect the HDR capabilities of sink by 1854 * reading and parsing the EDID. Details of HDR metadata for HDMI 1855 * are added in CTA 861.G spec. For DP , its defined in VESA DP 1856 * Standard v1.4. It needs to then get the metadata information 1857 * of the video/game/app content which are encoded in HDR (basically 1858 * using HDR transfer functions). With this information it needs to 1859 * decide on a blending policy and compose the relevant 1860 * layers/overlays into a common format. Once this blending is done, 1861 * userspace will be aware of the metadata of the composed frame to 1862 * be send to sink. It then uses this property to communicate this 1863 * metadata to driver which then make a Infoframe packet and sends 1864 * to sink based on the type of encoder connected. 1865 * 1866 * Userspace will be responsible to do Tone mapping operation in case: 1867 * - Some layers are HDR and others are SDR 1868 * - HDR layers luminance is not same as sink 1869 * 1870 * It will even need to do colorspace conversion and get all layers 1871 * to one common colorspace for blending. It can use either GL, Media 1872 * or display engine to get this done based on the capabilities of the 1873 * associated hardware. 1874 * 1875 * Driver expects metadata to be put in &struct hdr_output_metadata 1876 * structure from userspace. This is received as blob and stored in 1877 * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the 1878 * sink metadata in &struct hdr_sink_metadata, as 1879 * &drm_connector.display_info.hdr_sink_metadata. Driver uses 1880 * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata, 1881 * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of 1882 * HDMI encoder. 1883 * 1884 * max bpc: 1885 * This range property is used by userspace to limit the bit depth. When 1886 * used the driver would limit the bpc in accordance with the valid range 1887 * supported by the hardware and sink. Drivers to use the function 1888 * drm_connector_attach_max_bpc_property() to create and attach the 1889 * property to the connector during initialization. 1890 * 1891 * Connectors also have one standardized atomic property: 1892 * 1893 * CRTC_ID: 1894 * Mode object ID of the &drm_crtc this connector should be connected to. 1895 * 1896 * Connectors for LCD panels may also have one standardized property: 1897 * 1898 * panel orientation: 1899 * On some devices the LCD panel is mounted in the casing in such a way 1900 * that the up/top side of the panel does not match with the top side of 1901 * the device. Userspace can use this property to check for this. 1902 * Note that input coordinates from touchscreens (input devices with 1903 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel 1904 * coordinates, so if userspace rotates the picture to adjust for 1905 * the orientation it must also apply the same transformation to the 1906 * touchscreen input coordinates. This property is initialized by calling 1907 * drm_connector_set_panel_orientation() or 1908 * drm_connector_set_panel_orientation_with_quirk() 1909 * 1910 * scaling mode: 1911 * This property defines how a non-native mode is upscaled to the native 1912 * mode of an LCD panel: 1913 * 1914 * None: 1915 * No upscaling happens, scaling is left to the panel. Not all 1916 * drivers expose this mode. 1917 * Full: 1918 * The output is upscaled to the full resolution of the panel, 1919 * ignoring the aspect ratio. 1920 * Center: 1921 * No upscaling happens, the output is centered within the native 1922 * resolution the panel. 1923 * Full aspect: 1924 * The output is upscaled to maximize either the width or height 1925 * while retaining the aspect ratio. 1926 * 1927 * This property should be set up by calling 1928 * drm_connector_attach_scaling_mode_property(). Note that drivers 1929 * can also expose this property to external outputs, in which case they 1930 * must support "None", which should be the default (since external screens 1931 * have a built-in scaler). 1932 * 1933 * subconnector: 1934 * This property is used by DVI-I, TVout and DisplayPort to indicate different 1935 * connector subtypes. Enum values more or less match with those from main 1936 * connector types. 1937 * For DVI-I and TVout there is also a matching property "select subconnector" 1938 * allowing to switch between signal types. 1939 * DP subconnector corresponds to a downstream port. 1940 * 1941 * privacy-screen sw-state, privacy-screen hw-state: 1942 * These 2 optional properties can be used to query the state of the 1943 * electronic privacy screen that is available on some displays; and in 1944 * some cases also control the state. If a driver implements these 1945 * properties then both properties must be present. 1946 * 1947 * "privacy-screen hw-state" is read-only and reflects the actual state 1948 * of the privacy-screen, possible values: "Enabled", "Disabled, 1949 * "Enabled-locked", "Disabled-locked". The locked states indicate 1950 * that the state cannot be changed through the DRM API. E.g. there 1951 * might be devices where the firmware-setup options, or a hardware 1952 * slider-switch, offer always on / off modes. 1953 * 1954 * "privacy-screen sw-state" can be set to change the privacy-screen state 1955 * when not locked. In this case the driver must update the hw-state 1956 * property to reflect the new state on completion of the commit of the 1957 * sw-state property. Setting the sw-state property when the hw-state is 1958 * locked must be interpreted by the driver as a request to change the 1959 * state to the set state when the hw-state becomes unlocked. E.g. if 1960 * "privacy-screen hw-state" is "Enabled-locked" and the sw-state 1961 * gets set to "Disabled" followed by the user unlocking the state by 1962 * changing the slider-switch position, then the driver must set the 1963 * state to "Disabled" upon receiving the unlock event. 1964 * 1965 * In some cases the privacy-screen's actual state might change outside of 1966 * control of the DRM code. E.g. there might be a firmware handled hotkey 1967 * which toggles the actual state, or the actual state might be changed 1968 * through another userspace API such as writing /proc/acpi/ibm/lcdshadow. 1969 * In this case the driver must update both the hw-state and the sw-state 1970 * to reflect the new value, overwriting any pending state requests in the 1971 * sw-state. Any pending sw-state requests are thus discarded. 1972 * 1973 * Note that the ability for the state to change outside of control of 1974 * the DRM master process means that userspace must not cache the value 1975 * of the sw-state. Caching the sw-state value and including it in later 1976 * atomic commits may lead to overriding a state change done through e.g. 1977 * a firmware handled hotkey. Therefor userspace must not include the 1978 * privacy-screen sw-state in an atomic commit unless it wants to change 1979 * its value. 1980 * 1981 * left margin, right margin, top margin, bottom margin: 1982 * Add margins to the connector's viewport. This is typically used to 1983 * mitigate overscan on TVs. 1984 * 1985 * The value is the size in pixels of the black border which will be 1986 * added. The attached CRTC's content will be scaled to fill the whole 1987 * area inside the margin. 1988 * 1989 * The margins configuration might be sent to the sink, e.g. via HDMI AVI 1990 * InfoFrames. 1991 * 1992 * Drivers can set up these properties by calling 1993 * drm_mode_create_tv_margin_properties(). 1994 */ 1995 1996 int drm_connector_create_standard_properties(struct drm_device *dev) 1997 { 1998 struct drm_property *prop; 1999 2000 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | 2001 DRM_MODE_PROP_IMMUTABLE, 2002 "EDID", 0); 2003 if (!prop) 2004 return -ENOMEM; 2005 dev->mode_config.edid_property = prop; 2006 2007 prop = drm_property_create_enum(dev, 0, 2008 "DPMS", drm_dpms_enum_list, 2009 ARRAY_SIZE(drm_dpms_enum_list)); 2010 if (!prop) 2011 return -ENOMEM; 2012 dev->mode_config.dpms_property = prop; 2013 2014 prop = drm_property_create(dev, 2015 DRM_MODE_PROP_BLOB | 2016 DRM_MODE_PROP_IMMUTABLE, 2017 "PATH", 0); 2018 if (!prop) 2019 return -ENOMEM; 2020 dev->mode_config.path_property = prop; 2021 2022 prop = drm_property_create(dev, 2023 DRM_MODE_PROP_BLOB | 2024 DRM_MODE_PROP_IMMUTABLE, 2025 "TILE", 0); 2026 if (!prop) 2027 return -ENOMEM; 2028 dev->mode_config.tile_property = prop; 2029 2030 prop = drm_property_create_enum(dev, 0, "link-status", 2031 drm_link_status_enum_list, 2032 ARRAY_SIZE(drm_link_status_enum_list)); 2033 if (!prop) 2034 return -ENOMEM; 2035 dev->mode_config.link_status_property = prop; 2036 2037 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, "panel_type", 2038 drm_panel_type_enum_list, 2039 ARRAY_SIZE(drm_panel_type_enum_list)); 2040 if (!prop) 2041 return -ENOMEM; 2042 dev->mode_config.panel_type_property = prop; 2043 2044 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop"); 2045 if (!prop) 2046 return -ENOMEM; 2047 dev->mode_config.non_desktop_property = prop; 2048 2049 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB, 2050 "HDR_OUTPUT_METADATA", 0); 2051 if (!prop) 2052 return -ENOMEM; 2053 dev->mode_config.hdr_output_metadata_property = prop; 2054 2055 return 0; 2056 } 2057 2058 /** 2059 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties 2060 * @dev: DRM device 2061 * 2062 * Called by a driver the first time a DVI-I connector is made. 2063 * 2064 * Returns: %0 2065 */ 2066 int drm_mode_create_dvi_i_properties(struct drm_device *dev) 2067 { 2068 struct drm_property *dvi_i_selector; 2069 struct drm_property *dvi_i_subconnector; 2070 2071 if (dev->mode_config.dvi_i_select_subconnector_property) 2072 return 0; 2073 2074 dvi_i_selector = 2075 drm_property_create_enum(dev, 0, 2076 "select subconnector", 2077 drm_dvi_i_select_enum_list, 2078 ARRAY_SIZE(drm_dvi_i_select_enum_list)); 2079 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; 2080 2081 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 2082 "subconnector", 2083 drm_dvi_i_subconnector_enum_list, 2084 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); 2085 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; 2086 2087 return 0; 2088 } 2089 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); 2090 2091 /** 2092 * drm_connector_attach_dp_subconnector_property - create subconnector property for DP 2093 * @connector: drm_connector to attach property 2094 * 2095 * Called by a driver when DP connector is created. 2096 */ 2097 void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector) 2098 { 2099 struct drm_mode_config *mode_config = &connector->dev->mode_config; 2100 2101 if (!mode_config->dp_subconnector_property) 2102 mode_config->dp_subconnector_property = 2103 drm_property_create_enum(connector->dev, 2104 DRM_MODE_PROP_IMMUTABLE, 2105 "subconnector", 2106 drm_dp_subconnector_enum_list, 2107 ARRAY_SIZE(drm_dp_subconnector_enum_list)); 2108 2109 drm_object_attach_property(&connector->base, 2110 mode_config->dp_subconnector_property, 2111 DRM_MODE_SUBCONNECTOR_Unknown); 2112 } 2113 EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property); 2114 2115 /** 2116 * DOC: HDMI connector properties 2117 * 2118 * Broadcast RGB (HDMI specific) 2119 * Indicates the Quantization Range (Full vs Limited) used. The color 2120 * processing pipeline will be adjusted to match the value of the 2121 * property, and the Infoframes will be generated and sent accordingly. 2122 * 2123 * This property is only relevant if the HDMI output format is RGB. If 2124 * it's one of the YCbCr variant, it will be ignored. 2125 * 2126 * The CRTC attached to the connector must be configured by user-space to 2127 * always produce full-range pixels. 2128 * 2129 * The value of this property can be one of the following: 2130 * 2131 * Automatic: 2132 * The quantization range is selected automatically based on the 2133 * mode according to the HDMI specifications (HDMI 1.4b - Section 2134 * 6.6 - Video Quantization Ranges). 2135 * 2136 * Full: 2137 * Full quantization range is forced. 2138 * 2139 * Limited 16:235: 2140 * Limited quantization range is forced. Unlike the name suggests, 2141 * this works for any number of bits-per-component. 2142 * 2143 * Property values other than Automatic can result in colors being off (if 2144 * limited is selected but the display expects full), or a black screen 2145 * (if full is selected but the display expects limited). 2146 * 2147 * Drivers can set up this property by calling 2148 * drm_connector_attach_broadcast_rgb_property(). 2149 * 2150 * content type (HDMI specific): 2151 * Indicates content type setting to be used in HDMI infoframes to indicate 2152 * content type for the external device, so that it adjusts its display 2153 * settings accordingly. 2154 * 2155 * The value of this property can be one of the following: 2156 * 2157 * No Data: 2158 * Content type is unknown 2159 * Graphics: 2160 * Content type is graphics 2161 * Photo: 2162 * Content type is photo 2163 * Cinema: 2164 * Content type is cinema 2165 * Game: 2166 * Content type is game 2167 * 2168 * The meaning of each content type is defined in CTA-861-G table 15. 2169 * 2170 * Drivers can set up this property by calling 2171 * drm_connector_attach_content_type_property(). Decoding to 2172 * infoframe values is done through drm_hdmi_avi_infoframe_content_type(). 2173 */ 2174 2175 /* 2176 * TODO: Document the properties: 2177 * - brightness 2178 * - contrast 2179 * - flicker reduction 2180 * - hue 2181 * - mode 2182 * - overscan 2183 * - saturation 2184 * - select subconnector 2185 */ 2186 /** 2187 * DOC: Analog TV Connector Properties 2188 * 2189 * TV Mode: 2190 * Indicates the TV Mode used on an analog TV connector. The value 2191 * of this property can be one of the following: 2192 * 2193 * NTSC: 2194 * TV Mode is CCIR System M (aka 525-lines) together with 2195 * the NTSC Color Encoding. 2196 * 2197 * NTSC-443: 2198 * 2199 * TV Mode is CCIR System M (aka 525-lines) together with 2200 * the NTSC Color Encoding, but with a color subcarrier 2201 * frequency of 4.43MHz 2202 * 2203 * NTSC-J: 2204 * 2205 * TV Mode is CCIR System M (aka 525-lines) together with 2206 * the NTSC Color Encoding, but with a black level equal to 2207 * the blanking level. 2208 * 2209 * PAL: 2210 * 2211 * TV Mode is CCIR System B (aka 625-lines) together with 2212 * the PAL Color Encoding. 2213 * 2214 * PAL-M: 2215 * 2216 * TV Mode is CCIR System M (aka 525-lines) together with 2217 * the PAL Color Encoding. 2218 * 2219 * PAL-N: 2220 * 2221 * TV Mode is CCIR System N together with the PAL Color 2222 * Encoding, a color subcarrier frequency of 3.58MHz, the 2223 * SECAM color space, and narrower channels than other PAL 2224 * variants. 2225 * 2226 * SECAM: 2227 * 2228 * TV Mode is CCIR System B (aka 625-lines) together with 2229 * the SECAM Color Encoding. 2230 * 2231 * Mono: 2232 * 2233 * Use timings appropriate to the DRM mode, including 2234 * equalizing pulses for a 525-line or 625-line mode, 2235 * with no pedestal or color encoding. 2236 * 2237 * Drivers can set up this property by calling 2238 * drm_mode_create_tv_properties(). 2239 */ 2240 2241 /** 2242 * drm_connector_attach_content_type_property - attach content-type property 2243 * @connector: connector to attach content type property on. 2244 * 2245 * Called by a driver the first time a HDMI connector is made. 2246 * 2247 * Returns: %0 2248 */ 2249 int drm_connector_attach_content_type_property(struct drm_connector *connector) 2250 { 2251 if (!drm_mode_create_content_type_property(connector->dev)) 2252 drm_object_attach_property(&connector->base, 2253 connector->dev->mode_config.content_type_property, 2254 DRM_MODE_CONTENT_TYPE_NO_DATA); 2255 return 0; 2256 } 2257 EXPORT_SYMBOL(drm_connector_attach_content_type_property); 2258 2259 /** 2260 * drm_connector_attach_tv_margin_properties - attach TV connector margin 2261 * properties 2262 * @connector: DRM connector 2263 * 2264 * Called by a driver when it needs to attach TV margin props to a connector. 2265 * Typically used on SDTV and HDMI connectors. 2266 */ 2267 void drm_connector_attach_tv_margin_properties(struct drm_connector *connector) 2268 { 2269 struct drm_device *dev = connector->dev; 2270 2271 drm_object_attach_property(&connector->base, 2272 dev->mode_config.tv_left_margin_property, 2273 0); 2274 drm_object_attach_property(&connector->base, 2275 dev->mode_config.tv_right_margin_property, 2276 0); 2277 drm_object_attach_property(&connector->base, 2278 dev->mode_config.tv_top_margin_property, 2279 0); 2280 drm_object_attach_property(&connector->base, 2281 dev->mode_config.tv_bottom_margin_property, 2282 0); 2283 } 2284 EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties); 2285 2286 /** 2287 * drm_mode_create_tv_margin_properties - create TV connector margin properties 2288 * @dev: DRM device 2289 * 2290 * Called by a driver's HDMI connector initialization routine, this function 2291 * creates the TV margin properties for a given device. No need to call this 2292 * function for an SDTV connector, it's already called from 2293 * drm_mode_create_tv_properties_legacy(). 2294 * 2295 * Returns: 2296 * 0 on success or a negative error code on failure. 2297 */ 2298 int drm_mode_create_tv_margin_properties(struct drm_device *dev) 2299 { 2300 if (dev->mode_config.tv_left_margin_property) 2301 return 0; 2302 2303 dev->mode_config.tv_left_margin_property = 2304 drm_property_create_range(dev, 0, "left margin", 0, 100); 2305 if (!dev->mode_config.tv_left_margin_property) 2306 return -ENOMEM; 2307 2308 dev->mode_config.tv_right_margin_property = 2309 drm_property_create_range(dev, 0, "right margin", 0, 100); 2310 if (!dev->mode_config.tv_right_margin_property) 2311 return -ENOMEM; 2312 2313 dev->mode_config.tv_top_margin_property = 2314 drm_property_create_range(dev, 0, "top margin", 0, 100); 2315 if (!dev->mode_config.tv_top_margin_property) 2316 return -ENOMEM; 2317 2318 dev->mode_config.tv_bottom_margin_property = 2319 drm_property_create_range(dev, 0, "bottom margin", 0, 100); 2320 if (!dev->mode_config.tv_bottom_margin_property) 2321 return -ENOMEM; 2322 2323 return 0; 2324 } 2325 EXPORT_SYMBOL(drm_mode_create_tv_margin_properties); 2326 2327 /** 2328 * drm_mode_create_tv_properties_legacy - create TV specific connector properties 2329 * @dev: DRM device 2330 * @num_modes: number of different TV formats (modes) supported 2331 * @modes: array of pointers to strings containing name of each format 2332 * 2333 * Called by a driver's TV initialization routine, this function creates 2334 * the TV specific connector properties for a given device. Caller is 2335 * responsible for allocating a list of format names and passing them to 2336 * this routine. 2337 * 2338 * NOTE: This functions registers the deprecated "mode" connector 2339 * property to select the analog TV mode (ie, NTSC, PAL, etc.). New 2340 * drivers must use drm_mode_create_tv_properties() instead. 2341 * 2342 * Returns: 2343 * 0 on success or a negative error code on failure. 2344 */ 2345 int drm_mode_create_tv_properties_legacy(struct drm_device *dev, 2346 unsigned int num_modes, 2347 const char * const modes[]) 2348 { 2349 struct drm_property *tv_selector; 2350 struct drm_property *tv_subconnector; 2351 unsigned int i; 2352 2353 if (dev->mode_config.tv_select_subconnector_property) 2354 return 0; 2355 2356 /* 2357 * Basic connector properties 2358 */ 2359 tv_selector = drm_property_create_enum(dev, 0, 2360 "select subconnector", 2361 drm_tv_select_enum_list, 2362 ARRAY_SIZE(drm_tv_select_enum_list)); 2363 if (!tv_selector) 2364 goto nomem; 2365 2366 dev->mode_config.tv_select_subconnector_property = tv_selector; 2367 2368 tv_subconnector = 2369 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 2370 "subconnector", 2371 drm_tv_subconnector_enum_list, 2372 ARRAY_SIZE(drm_tv_subconnector_enum_list)); 2373 if (!tv_subconnector) 2374 goto nomem; 2375 dev->mode_config.tv_subconnector_property = tv_subconnector; 2376 2377 /* 2378 * Other, TV specific properties: margins & TV modes. 2379 */ 2380 if (drm_mode_create_tv_margin_properties(dev)) 2381 goto nomem; 2382 2383 if (num_modes) { 2384 dev->mode_config.legacy_tv_mode_property = 2385 drm_property_create(dev, DRM_MODE_PROP_ENUM, 2386 "mode", num_modes); 2387 if (!dev->mode_config.legacy_tv_mode_property) 2388 goto nomem; 2389 2390 for (i = 0; i < num_modes; i++) 2391 drm_property_add_enum(dev->mode_config.legacy_tv_mode_property, 2392 i, modes[i]); 2393 } 2394 2395 dev->mode_config.tv_brightness_property = 2396 drm_property_create_range(dev, 0, "brightness", 0, 100); 2397 if (!dev->mode_config.tv_brightness_property) 2398 goto nomem; 2399 2400 dev->mode_config.tv_contrast_property = 2401 drm_property_create_range(dev, 0, "contrast", 0, 100); 2402 if (!dev->mode_config.tv_contrast_property) 2403 goto nomem; 2404 2405 dev->mode_config.tv_flicker_reduction_property = 2406 drm_property_create_range(dev, 0, "flicker reduction", 0, 100); 2407 if (!dev->mode_config.tv_flicker_reduction_property) 2408 goto nomem; 2409 2410 dev->mode_config.tv_overscan_property = 2411 drm_property_create_range(dev, 0, "overscan", 0, 100); 2412 if (!dev->mode_config.tv_overscan_property) 2413 goto nomem; 2414 2415 dev->mode_config.tv_saturation_property = 2416 drm_property_create_range(dev, 0, "saturation", 0, 100); 2417 if (!dev->mode_config.tv_saturation_property) 2418 goto nomem; 2419 2420 dev->mode_config.tv_hue_property = 2421 drm_property_create_range(dev, 0, "hue", 0, 100); 2422 if (!dev->mode_config.tv_hue_property) 2423 goto nomem; 2424 2425 return 0; 2426 nomem: 2427 return -ENOMEM; 2428 } 2429 EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy); 2430 2431 /** 2432 * drm_mode_create_tv_properties - create TV specific connector properties 2433 * @dev: DRM device 2434 * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*) 2435 * 2436 * Called by a driver's TV initialization routine, this function creates 2437 * the TV specific connector properties for a given device. 2438 * 2439 * Returns: 2440 * 0 on success or a negative error code on failure. 2441 */ 2442 int drm_mode_create_tv_properties(struct drm_device *dev, 2443 unsigned int supported_tv_modes) 2444 { 2445 struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX]; 2446 struct drm_property *tv_mode; 2447 unsigned int i, len = 0; 2448 2449 if (dev->mode_config.tv_mode_property) 2450 return 0; 2451 2452 for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) { 2453 if (!(supported_tv_modes & BIT(i))) 2454 continue; 2455 2456 tv_mode_list[len].type = i; 2457 tv_mode_list[len].name = drm_get_tv_mode_name(i); 2458 len++; 2459 } 2460 2461 tv_mode = drm_property_create_enum(dev, 0, "TV mode", 2462 tv_mode_list, len); 2463 if (!tv_mode) 2464 return -ENOMEM; 2465 2466 dev->mode_config.tv_mode_property = tv_mode; 2467 2468 return drm_mode_create_tv_properties_legacy(dev, 0, NULL); 2469 } 2470 EXPORT_SYMBOL(drm_mode_create_tv_properties); 2471 2472 /** 2473 * drm_mode_create_scaling_mode_property - create scaling mode property 2474 * @dev: DRM device 2475 * 2476 * Called by a driver the first time it's needed, must be attached to desired 2477 * connectors. 2478 * 2479 * Atomic drivers should use drm_connector_attach_scaling_mode_property() 2480 * instead to correctly assign &drm_connector_state.scaling_mode 2481 * in the atomic state. 2482 * 2483 * Returns: %0 2484 */ 2485 int drm_mode_create_scaling_mode_property(struct drm_device *dev) 2486 { 2487 struct drm_property *scaling_mode; 2488 2489 if (dev->mode_config.scaling_mode_property) 2490 return 0; 2491 2492 scaling_mode = 2493 drm_property_create_enum(dev, 0, "scaling mode", 2494 drm_scaling_mode_enum_list, 2495 ARRAY_SIZE(drm_scaling_mode_enum_list)); 2496 2497 dev->mode_config.scaling_mode_property = scaling_mode; 2498 2499 return 0; 2500 } 2501 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); 2502 2503 /** 2504 * DOC: Variable refresh properties 2505 * 2506 * Variable refresh rate capable displays can dynamically adjust their 2507 * refresh rate by extending the duration of their vertical front porch 2508 * until page flip or timeout occurs. This can reduce or remove stuttering 2509 * and latency in scenarios where the page flip does not align with the 2510 * vblank interval. 2511 * 2512 * An example scenario would be an application flipping at a constant rate 2513 * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank 2514 * interval and the same contents will be displayed twice. This can be 2515 * observed as stuttering for content with motion. 2516 * 2517 * If variable refresh rate was active on a display that supported a 2518 * variable refresh range from 35Hz to 60Hz no stuttering would be observable 2519 * for the example scenario. The minimum supported variable refresh rate of 2520 * 35Hz is below the page flip frequency and the vertical front porch can 2521 * be extended until the page flip occurs. The vblank interval will be 2522 * directly aligned to the page flip rate. 2523 * 2524 * Not all userspace content is suitable for use with variable refresh rate. 2525 * Large and frequent changes in vertical front porch duration may worsen 2526 * perceived stuttering for input sensitive applications. 2527 * 2528 * Panel brightness will also vary with vertical front porch duration. Some 2529 * panels may have noticeable differences in brightness between the minimum 2530 * vertical front porch duration and the maximum vertical front porch duration. 2531 * Large and frequent changes in vertical front porch duration may produce 2532 * observable flickering for such panels. 2533 * 2534 * Userspace control for variable refresh rate is supported via properties 2535 * on the &drm_connector and &drm_crtc objects. 2536 * 2537 * "vrr_capable": 2538 * Optional &drm_connector boolean property that drivers should attach 2539 * with drm_connector_attach_vrr_capable_property() on connectors that 2540 * could support variable refresh rates. Drivers should update the 2541 * property value by calling drm_connector_set_vrr_capable_property(). 2542 * 2543 * Absence of the property should indicate absence of support. 2544 * 2545 * "VRR_ENABLED": 2546 * Default &drm_crtc boolean property that notifies the driver that the 2547 * content on the CRTC is suitable for variable refresh rate presentation. 2548 * The driver will take this property as a hint to enable variable 2549 * refresh rate support if the receiver supports it, ie. if the 2550 * "vrr_capable" property is true on the &drm_connector object. The 2551 * vertical front porch duration will be extended until page-flip or 2552 * timeout when enabled. 2553 * 2554 * The minimum vertical front porch duration is defined as the vertical 2555 * front porch duration for the current mode. 2556 * 2557 * The maximum vertical front porch duration is greater than or equal to 2558 * the minimum vertical front porch duration. The duration is derived 2559 * from the minimum supported variable refresh rate for the connector. 2560 * 2561 * The driver may place further restrictions within these minimum 2562 * and maximum bounds. 2563 */ 2564 2565 /** 2566 * drm_connector_attach_vrr_capable_property - creates the 2567 * vrr_capable property 2568 * @connector: connector to create the vrr_capable property on. 2569 * 2570 * This is used by atomic drivers to add support for querying 2571 * variable refresh rate capability for a connector. 2572 * 2573 * Returns: 2574 * Zero on success, negative errno on failure. 2575 */ 2576 int drm_connector_attach_vrr_capable_property( 2577 struct drm_connector *connector) 2578 { 2579 struct drm_device *dev = connector->dev; 2580 struct drm_property *prop; 2581 2582 if (!connector->vrr_capable_property) { 2583 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, 2584 "vrr_capable"); 2585 if (!prop) 2586 return -ENOMEM; 2587 2588 connector->vrr_capable_property = prop; 2589 drm_object_attach_property(&connector->base, prop, 0); 2590 } 2591 2592 return 0; 2593 } 2594 EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property); 2595 2596 /** 2597 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property 2598 * @connector: connector to attach scaling mode property on. 2599 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*). 2600 * 2601 * This is used to add support for scaling mode to atomic drivers. 2602 * The scaling mode will be set to &drm_connector_state.scaling_mode 2603 * and can be used from &drm_connector_helper_funcs->atomic_check for validation. 2604 * 2605 * This is the atomic version of drm_mode_create_scaling_mode_property(). 2606 * 2607 * Returns: 2608 * Zero on success, negative errno on failure. 2609 */ 2610 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector, 2611 u32 scaling_mode_mask) 2612 { 2613 struct drm_device *dev = connector->dev; 2614 struct drm_property *scaling_mode_property; 2615 int i; 2616 const unsigned valid_scaling_mode_mask = 2617 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1; 2618 2619 if (WARN_ON(hweight32(scaling_mode_mask) < 2 || 2620 scaling_mode_mask & ~valid_scaling_mode_mask)) 2621 return -EINVAL; 2622 2623 scaling_mode_property = 2624 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode", 2625 hweight32(scaling_mode_mask)); 2626 2627 if (!scaling_mode_property) 2628 return -ENOMEM; 2629 2630 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) { 2631 int ret; 2632 2633 if (!(BIT(i) & scaling_mode_mask)) 2634 continue; 2635 2636 ret = drm_property_add_enum(scaling_mode_property, 2637 drm_scaling_mode_enum_list[i].type, 2638 drm_scaling_mode_enum_list[i].name); 2639 2640 if (ret) { 2641 drm_property_destroy(dev, scaling_mode_property); 2642 2643 return ret; 2644 } 2645 } 2646 2647 drm_object_attach_property(&connector->base, 2648 scaling_mode_property, 0); 2649 2650 connector->scaling_mode_property = scaling_mode_property; 2651 2652 return 0; 2653 } 2654 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property); 2655 2656 /** 2657 * drm_mode_create_aspect_ratio_property - create aspect ratio property 2658 * @dev: DRM device 2659 * 2660 * Called by a driver the first time it's needed, must be attached to desired 2661 * connectors. 2662 * 2663 * Returns: 2664 * Zero on success, negative errno on failure. 2665 */ 2666 int drm_mode_create_aspect_ratio_property(struct drm_device *dev) 2667 { 2668 if (dev->mode_config.aspect_ratio_property) 2669 return 0; 2670 2671 dev->mode_config.aspect_ratio_property = 2672 drm_property_create_enum(dev, 0, "aspect ratio", 2673 drm_aspect_ratio_enum_list, 2674 ARRAY_SIZE(drm_aspect_ratio_enum_list)); 2675 2676 if (dev->mode_config.aspect_ratio_property == NULL) 2677 return -ENOMEM; 2678 2679 return 0; 2680 } 2681 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); 2682 2683 /** 2684 * DOC: standard connector properties 2685 * 2686 * Colorspace: 2687 * This property is used to inform the driver about the color encoding 2688 * user space configured the pixel operation properties to produce. 2689 * The variants set the colorimetry, transfer characteristics, and which 2690 * YCbCr conversion should be used when necessary. 2691 * The transfer characteristics from HDR_OUTPUT_METADATA takes precedence 2692 * over this property. 2693 * User space always configures the pixel operation properties to produce 2694 * full quantization range data (see the Broadcast RGB property). 2695 * 2696 * Drivers inform the sink about what colorimetry, transfer 2697 * characteristics, YCbCr conversion, and quantization range to expect 2698 * (this can depend on the output mode, output format and other 2699 * properties). Drivers also convert the user space provided data to what 2700 * the sink expects. 2701 * 2702 * User space has to check if the sink supports all of the possible 2703 * colorimetries that the driver is allowed to pick by parsing the EDID. 2704 * 2705 * For historical reasons this property exposes a number of variants which 2706 * result in undefined behavior. 2707 * 2708 * Default: 2709 * The behavior is driver-specific. 2710 * 2711 * BT2020_RGB: 2712 * 2713 * BT2020_YCC: 2714 * User space configures the pixel operation properties to produce 2715 * RGB content with Rec. ITU-R BT.2020 colorimetry, Rec. 2716 * ITU-R BT.2020 (Table 4, RGB) transfer characteristics and full 2717 * quantization range. 2718 * User space can use the HDR_OUTPUT_METADATA property to set the 2719 * transfer characteristics to PQ (Rec. ITU-R BT.2100 Table 4) or 2720 * HLG (Rec. ITU-R BT.2100 Table 5) in which case, user space 2721 * configures pixel operation properties to produce content with 2722 * the respective transfer characteristics. 2723 * User space has to make sure the sink supports Rec. 2724 * ITU-R BT.2020 R'G'B' and Rec. ITU-R BT.2020 Y'C'BC'R 2725 * colorimetry. 2726 * Drivers can configure the sink to use an RGB format, tell the 2727 * sink to expect Rec. ITU-R BT.2020 R'G'B' colorimetry and convert 2728 * to the appropriate quantization range. 2729 * Drivers can configure the sink to use a YCbCr format, tell the 2730 * sink to expect Rec. ITU-R BT.2020 Y'C'BC'R colorimetry, convert 2731 * to YCbCr using the Rec. ITU-R BT.2020 non-constant luminance 2732 * conversion matrix and convert to the appropriate quantization 2733 * range. 2734 * The variants BT2020_RGB and BT2020_YCC are equivalent and the 2735 * driver chooses between RGB and YCbCr based on the color format 2736 * property. 2737 * 2738 * SMPTE_170M_YCC: 2739 * BT709_YCC: 2740 * XVYCC_601: 2741 * XVYCC_709: 2742 * SYCC_601: 2743 * opYCC_601: 2744 * opRGB: 2745 * BT2020_CYCC: 2746 * DCI-P3_RGB_D65: 2747 * DCI-P3_RGB_Theater: 2748 * RGB_WIDE_FIXED: 2749 * RGB_WIDE_FLOAT: 2750 * 2751 * BT601_YCC: 2752 * The behavior is undefined. 2753 * 2754 * Because between HDMI and DP have different colorspaces, 2755 * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and 2756 * drm_mode_create_dp_colorspace_property() is used for DP connector. 2757 */ 2758 2759 static int drm_mode_create_colorspace_property(struct drm_connector *connector, 2760 u32 supported_colorspaces) 2761 { 2762 struct drm_device *dev = connector->dev; 2763 u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT); 2764 struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT]; 2765 int i, len; 2766 2767 if (connector->colorspace_property) 2768 return 0; 2769 2770 if (!supported_colorspaces) { 2771 drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n", 2772 connector->base.id, connector->name); 2773 return -EINVAL; 2774 } 2775 2776 if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) { 2777 drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n", 2778 connector->base.id, connector->name); 2779 return -EINVAL; 2780 } 2781 2782 len = 0; 2783 for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) { 2784 if ((colorspaces & BIT(i)) == 0) 2785 continue; 2786 2787 enum_list[len].type = i; 2788 enum_list[len].name = colorspace_names[i]; 2789 len++; 2790 } 2791 2792 connector->colorspace_property = 2793 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace", 2794 enum_list, 2795 len); 2796 2797 if (!connector->colorspace_property) 2798 return -ENOMEM; 2799 2800 return 0; 2801 } 2802 2803 /** 2804 * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property 2805 * @connector: connector to create the Colorspace property on. 2806 * @supported_colorspaces: bitmap of supported color spaces 2807 * 2808 * Called by a driver the first time it's needed, must be attached to desired 2809 * HDMI connectors. 2810 * 2811 * Returns: 2812 * Zero on success, negative errno on failure. 2813 */ 2814 int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector, 2815 u32 supported_colorspaces) 2816 { 2817 u32 colorspaces; 2818 2819 if (supported_colorspaces) 2820 colorspaces = supported_colorspaces & hdmi_colorspaces; 2821 else 2822 colorspaces = hdmi_colorspaces; 2823 2824 return drm_mode_create_colorspace_property(connector, colorspaces); 2825 } 2826 EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property); 2827 2828 /** 2829 * drm_mode_create_dp_colorspace_property - create dp colorspace property 2830 * @connector: connector to create the Colorspace property on. 2831 * @supported_colorspaces: bitmap of supported color spaces 2832 * 2833 * Called by a driver the first time it's needed, must be attached to desired 2834 * DP connectors. 2835 * 2836 * Returns: 2837 * Zero on success, negative errno on failure. 2838 */ 2839 int drm_mode_create_dp_colorspace_property(struct drm_connector *connector, 2840 u32 supported_colorspaces) 2841 { 2842 u32 colorspaces; 2843 2844 if (supported_colorspaces) 2845 colorspaces = supported_colorspaces & dp_colorspaces; 2846 else 2847 colorspaces = dp_colorspaces; 2848 2849 return drm_mode_create_colorspace_property(connector, colorspaces); 2850 } 2851 EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property); 2852 2853 /** 2854 * drm_mode_create_content_type_property - create content type property 2855 * @dev: DRM device 2856 * 2857 * Called by a driver the first time it's needed, must be attached to desired 2858 * connectors. 2859 * 2860 * Returns: 2861 * Zero on success, negative errno on failure. 2862 */ 2863 int drm_mode_create_content_type_property(struct drm_device *dev) 2864 { 2865 if (dev->mode_config.content_type_property) 2866 return 0; 2867 2868 dev->mode_config.content_type_property = 2869 drm_property_create_enum(dev, 0, "content type", 2870 drm_content_type_enum_list, 2871 ARRAY_SIZE(drm_content_type_enum_list)); 2872 2873 if (dev->mode_config.content_type_property == NULL) 2874 return -ENOMEM; 2875 2876 return 0; 2877 } 2878 EXPORT_SYMBOL(drm_mode_create_content_type_property); 2879 2880 /** 2881 * drm_mode_create_suggested_offset_properties - create suggests offset properties 2882 * @dev: DRM device 2883 * 2884 * Create the suggested x/y offset property for connectors. 2885 * 2886 * Returns: 2887 * 0 on success or a negative error code on failure. 2888 */ 2889 int drm_mode_create_suggested_offset_properties(struct drm_device *dev) 2890 { 2891 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) 2892 return 0; 2893 2894 dev->mode_config.suggested_x_property = 2895 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); 2896 2897 dev->mode_config.suggested_y_property = 2898 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); 2899 2900 if (dev->mode_config.suggested_x_property == NULL || 2901 dev->mode_config.suggested_y_property == NULL) 2902 return -ENOMEM; 2903 return 0; 2904 } 2905 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); 2906 2907 /** 2908 * drm_connector_set_path_property - set tile property on connector 2909 * @connector: connector to set property on. 2910 * @path: path to use for property; must not be NULL. 2911 * 2912 * This creates a property to expose to userspace to specify a 2913 * connector path. This is mainly used for DisplayPort MST where 2914 * connectors have a topology and we want to allow userspace to give 2915 * them more meaningful names. 2916 * 2917 * Returns: 2918 * Zero on success, negative errno on failure. 2919 */ 2920 int drm_connector_set_path_property(struct drm_connector *connector, 2921 const char *path) 2922 { 2923 struct drm_device *dev = connector->dev; 2924 int ret; 2925 2926 ret = drm_property_replace_global_blob(dev, 2927 &connector->path_blob_ptr, 2928 strlen(path) + 1, 2929 path, 2930 &connector->base, 2931 dev->mode_config.path_property); 2932 return ret; 2933 } 2934 EXPORT_SYMBOL(drm_connector_set_path_property); 2935 2936 /** 2937 * drm_connector_set_tile_property - set tile property on connector 2938 * @connector: connector to set property on. 2939 * 2940 * This looks up the tile information for a connector, and creates a 2941 * property for userspace to parse if it exists. The property is of 2942 * the form of 8 integers using ':' as a separator. 2943 * This is used for dual port tiled displays with DisplayPort SST 2944 * or DisplayPort MST connectors. 2945 * 2946 * Returns: 2947 * Zero on success, errno on failure. 2948 */ 2949 int drm_connector_set_tile_property(struct drm_connector *connector) 2950 { 2951 struct drm_device *dev = connector->dev; 2952 char tile[256]; 2953 int ret; 2954 2955 if (!connector->has_tile) { 2956 ret = drm_property_replace_global_blob(dev, 2957 &connector->tile_blob_ptr, 2958 0, 2959 NULL, 2960 &connector->base, 2961 dev->mode_config.tile_property); 2962 return ret; 2963 } 2964 2965 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", 2966 connector->tile_group->id, connector->tile_is_single_monitor, 2967 connector->num_h_tile, connector->num_v_tile, 2968 connector->tile_h_loc, connector->tile_v_loc, 2969 connector->tile_h_size, connector->tile_v_size); 2970 2971 ret = drm_property_replace_global_blob(dev, 2972 &connector->tile_blob_ptr, 2973 strlen(tile) + 1, 2974 tile, 2975 &connector->base, 2976 dev->mode_config.tile_property); 2977 return ret; 2978 } 2979 EXPORT_SYMBOL(drm_connector_set_tile_property); 2980 2981 /** 2982 * drm_connector_set_link_status_property - Set link status property of a connector 2983 * @connector: drm connector 2984 * @link_status: new value of link status property (0: Good, 1: Bad) 2985 * 2986 * In usual working scenario, this link status property will always be set to 2987 * "GOOD". If something fails during or after a mode set, the kernel driver 2988 * may set this link status property to "BAD". The caller then needs to send a 2989 * hotplug uevent for userspace to re-check the valid modes through 2990 * GET_CONNECTOR_IOCTL and retry modeset. 2991 * 2992 * Note: Drivers cannot rely on userspace to support this property and 2993 * issue a modeset. As such, they may choose to handle issues (like 2994 * re-training a link) without userspace's intervention. 2995 * 2996 * The reason for adding this property is to handle link training failures, but 2997 * it is not limited to DP or link training. For example, if we implement 2998 * asynchronous setcrtc, this property can be used to report any failures in that. 2999 */ 3000 void drm_connector_set_link_status_property(struct drm_connector *connector, 3001 uint64_t link_status) 3002 { 3003 struct drm_device *dev = connector->dev; 3004 3005 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 3006 connector->state->link_status = link_status; 3007 drm_modeset_unlock(&dev->mode_config.connection_mutex); 3008 } 3009 EXPORT_SYMBOL(drm_connector_set_link_status_property); 3010 3011 /** 3012 * drm_connector_attach_max_bpc_property - attach "max bpc" property 3013 * @connector: connector to attach max bpc property on. 3014 * @min: The minimum bit depth supported by the connector. 3015 * @max: The maximum bit depth supported by the connector. 3016 * 3017 * This is used to add support for limiting the bit depth on a connector. 3018 * 3019 * Returns: 3020 * Zero on success, negative errno on failure. 3021 */ 3022 int drm_connector_attach_max_bpc_property(struct drm_connector *connector, 3023 int min, int max) 3024 { 3025 struct drm_device *dev = connector->dev; 3026 struct drm_property *prop; 3027 3028 prop = connector->max_bpc_property; 3029 if (!prop) { 3030 prop = drm_property_create_range(dev, 0, "max bpc", min, max); 3031 if (!prop) 3032 return -ENOMEM; 3033 3034 connector->max_bpc_property = prop; 3035 } 3036 3037 drm_object_attach_property(&connector->base, prop, max); 3038 connector->state->max_requested_bpc = max; 3039 connector->state->max_bpc = max; 3040 3041 return 0; 3042 } 3043 EXPORT_SYMBOL(drm_connector_attach_max_bpc_property); 3044 3045 /** 3046 * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADATA" property 3047 * @connector: connector to attach the property on. 3048 * 3049 * This is used to allow the userspace to send HDR Metadata to the 3050 * driver. 3051 */ 3052 void drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector) 3053 { 3054 struct drm_device *dev = connector->dev; 3055 struct drm_property *prop = dev->mode_config.hdr_output_metadata_property; 3056 3057 drm_object_attach_property(&connector->base, prop, 0); 3058 } 3059 EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property); 3060 3061 /** 3062 * drm_connector_attach_broadcast_rgb_property - attach "Broadcast RGB" property 3063 * @connector: connector to attach the property on. 3064 * 3065 * This is used to add support for forcing the RGB range on a connector 3066 * 3067 * Returns: 3068 * Zero on success, negative errno on failure. 3069 */ 3070 int drm_connector_attach_broadcast_rgb_property(struct drm_connector *connector) 3071 { 3072 struct drm_device *dev = connector->dev; 3073 struct drm_property *prop; 3074 3075 prop = connector->broadcast_rgb_property; 3076 if (!prop) { 3077 prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, 3078 "Broadcast RGB", 3079 broadcast_rgb_names, 3080 ARRAY_SIZE(broadcast_rgb_names)); 3081 if (!prop) 3082 return -EINVAL; 3083 3084 connector->broadcast_rgb_property = prop; 3085 } 3086 3087 drm_object_attach_property(&connector->base, prop, 3088 DRM_HDMI_BROADCAST_RGB_AUTO); 3089 3090 return 0; 3091 } 3092 EXPORT_SYMBOL(drm_connector_attach_broadcast_rgb_property); 3093 3094 /** 3095 * drm_connector_attach_colorspace_property - attach "Colorspace" property 3096 * @connector: connector to attach the property on. 3097 * 3098 * This is used to allow the userspace to signal the output colorspace 3099 * to the driver. 3100 * 3101 * Returns: 3102 * Zero on success, negative errno on failure. 3103 */ 3104 int drm_connector_attach_colorspace_property(struct drm_connector *connector) 3105 { 3106 struct drm_property *prop = connector->colorspace_property; 3107 3108 drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT); 3109 3110 return 0; 3111 } 3112 EXPORT_SYMBOL(drm_connector_attach_colorspace_property); 3113 3114 /** 3115 * DOC: Color format 3116 * 3117 * The connector "color format" property allows userspace to request a specific 3118 * color model on the output of the connector. Not all values listed by the 3119 * property are guaranteed to work for every sink; rather, it is an optimistic 3120 * listing of color formats that the source could output depending on 3121 * circumstances. 3122 * 3123 * Whether it actually can output a certain color format is determined during 3124 * the atomic check phase. Consequently, a userspace application that sets the 3125 * color format to a value other than "AUTO" should check whether its atomic 3126 * commit succeeded. 3127 * 3128 * Possible values for "color format": 3129 * 3130 * "AUTO": 3131 * The driver or display protocol helpers should pick a suitable color 3132 * format. All implementations of a specific display protocol will behave 3133 * the same way with "AUTO", but different display protocols do not 3134 * necessarily have the same "AUTO" semantics. 3135 * 3136 * For HDMI connectors, "AUTO" picks RGB, but falls back to YUV 4:2:0 if 3137 * the bandwidth required for full-scale RGB is not available, or the mode 3138 * is YUV 4:2:0-only, as long as the mode, source, and sink all support 3139 * YUV 4:2:0. 3140 * "RGB": 3141 * RGB output format. The quantization range (limited/full) depends on the 3142 * value of the "Broadcast RGB" property if it is present on the connector. 3143 * "YUV 4:4:4": 3144 * YUV 4:4:4 (a.k.a. YCbCr 4:4:4) output format. Chroma is not subsampled. 3145 * The quantization range defaults to limited. 3146 * "YUV 4:2:2": 3147 * YUV 4:2:2 (a.k.a. YCbCr 4:2:2) output format. Chroma has half the 3148 * horizontal resolution of Luma. The quantization range defaults to 3149 * limited. 3150 * "YUV 4:2:0": 3151 * YUV 4:2:0 (a.k.a. YCbCr 4:2:0) output format. Chroma has half the 3152 * horizontal and vertical resolution of Luma. The quantization range 3153 * defaults to limited. 3154 * 3155 * A sink may only support some color formats in specific modes and at specific 3156 * bit depths. The atomic modesetting API should be used to set a working 3157 * configuration in one go, as an unsupported combination of parameters is 3158 * rejected. 3159 */ 3160 3161 /** 3162 * drm_connector_attach_color_format_property - create and attach color format property 3163 * @connector: connector to create the color format property on 3164 * @supported_color_formats: bitmask of bit-shifted &enum drm_output_color_format 3165 * values the connector supports 3166 * 3167 * Called by a driver to create a color format property. The property is 3168 * attached to the connector automatically on success. 3169 * 3170 * @supported_color_formats should only include color formats the connector 3171 * type can actually support. 3172 * 3173 * Returns: 3174 * 0 on success, negative errno on error 3175 */ 3176 int drm_connector_attach_color_format_property(struct drm_connector *connector, 3177 unsigned long supported_color_formats) 3178 { 3179 struct drm_device *dev = connector->dev; 3180 struct drm_prop_enum_list enum_list[DRM_CONNECTOR_COLOR_FORMAT_COUNT]; 3181 unsigned int i = 0; 3182 unsigned long fmt; 3183 3184 if (connector->color_format_property) 3185 return 0; 3186 3187 if (!supported_color_formats) { 3188 drm_err(dev, "No supported color formats provided on [CONNECTOR:%d:%s]\n", 3189 connector->base.id, connector->name); 3190 return -EINVAL; 3191 } 3192 3193 if (supported_color_formats & ~GENMASK(DRM_OUTPUT_COLOR_FORMAT_COUNT - 1, 0)) { 3194 drm_err(dev, "Unknown color formats provided on [CONNECTOR:%d:%s]\n", 3195 connector->base.id, connector->name); 3196 return -EINVAL; 3197 } 3198 3199 switch (connector->connector_type) { 3200 case DRM_MODE_CONNECTOR_HDMIA: 3201 case DRM_MODE_CONNECTOR_HDMIB: 3202 if (supported_color_formats & ~hdmi_colorformats) { 3203 drm_err(dev, "Color formats not allowed for HDMI on [CONNECTOR:%d:%s]\n", 3204 connector->base.id, connector->name); 3205 return -EINVAL; 3206 } 3207 break; 3208 case DRM_MODE_CONNECTOR_DisplayPort: 3209 case DRM_MODE_CONNECTOR_eDP: 3210 if (supported_color_formats & ~dp_colorformats) { 3211 drm_err(dev, "Color formats not allowed for DP on [CONNECTOR:%d:%s]\n", 3212 connector->base.id, connector->name); 3213 return -EINVAL; 3214 } 3215 break; 3216 } 3217 3218 enum_list[0].name = "AUTO"; 3219 enum_list[0].type = DRM_CONNECTOR_COLOR_FORMAT_AUTO; 3220 3221 for_each_set_bit(fmt, &supported_color_formats, DRM_OUTPUT_COLOR_FORMAT_COUNT) { 3222 switch (fmt) { 3223 case DRM_OUTPUT_COLOR_FORMAT_RGB444: 3224 enum_list[++i].type = DRM_CONNECTOR_COLOR_FORMAT_RGB444; 3225 break; 3226 case DRM_OUTPUT_COLOR_FORMAT_YCBCR444: 3227 enum_list[++i].type = DRM_CONNECTOR_COLOR_FORMAT_YCBCR444; 3228 break; 3229 case DRM_OUTPUT_COLOR_FORMAT_YCBCR422: 3230 enum_list[++i].type = DRM_CONNECTOR_COLOR_FORMAT_YCBCR422; 3231 break; 3232 case DRM_OUTPUT_COLOR_FORMAT_YCBCR420: 3233 enum_list[++i].type = DRM_CONNECTOR_COLOR_FORMAT_YCBCR420; 3234 break; 3235 default: 3236 drm_warn(dev, "Unknown supported format %ld on [CONNECTOR:%d:%s]\n", 3237 fmt, connector->base.id, connector->name); 3238 continue; 3239 } 3240 enum_list[i].name = drm_hdmi_connector_get_output_format_name(fmt); 3241 } 3242 3243 connector->color_format_property = 3244 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "color format", 3245 enum_list, i + 1); 3246 3247 if (!connector->color_format_property) 3248 return -ENOMEM; 3249 3250 drm_object_attach_property(&connector->base, connector->color_format_property, 3251 DRM_CONNECTOR_COLOR_FORMAT_AUTO); 3252 3253 return 0; 3254 } 3255 EXPORT_SYMBOL(drm_connector_attach_color_format_property); 3256 3257 /** 3258 * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed 3259 * @old_state: old connector state to compare 3260 * @new_state: new connector state to compare 3261 * 3262 * This is used by HDR-enabled drivers to test whether the HDR metadata 3263 * have changed between two different connector state (and thus probably 3264 * requires a full blown mode change). 3265 * 3266 * Returns: 3267 * True if the metadata are equal, False otherwise 3268 */ 3269 bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state, 3270 struct drm_connector_state *new_state) 3271 { 3272 struct drm_property_blob *old_blob = old_state->hdr_output_metadata; 3273 struct drm_property_blob *new_blob = new_state->hdr_output_metadata; 3274 3275 if (!old_blob || !new_blob) 3276 return old_blob == new_blob; 3277 3278 if (old_blob->length != new_blob->length) 3279 return false; 3280 3281 return !memcmp(old_blob->data, new_blob->data, old_blob->length); 3282 } 3283 EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal); 3284 3285 /** 3286 * drm_connector_set_vrr_capable_property - sets the variable refresh rate 3287 * capable property for a connector 3288 * @connector: drm connector 3289 * @capable: True if the connector is variable refresh rate capable 3290 * 3291 * Should be used by atomic drivers to update the indicated support for 3292 * variable refresh rate over a connector. 3293 */ 3294 void drm_connector_set_vrr_capable_property( 3295 struct drm_connector *connector, bool capable) 3296 { 3297 if (!connector->vrr_capable_property) 3298 return; 3299 3300 drm_object_property_set_value(&connector->base, 3301 connector->vrr_capable_property, 3302 capable); 3303 } 3304 EXPORT_SYMBOL(drm_connector_set_vrr_capable_property); 3305 3306 /** 3307 * drm_connector_set_panel_orientation - sets the connector's panel_orientation 3308 * @connector: connector for which to set the panel-orientation property. 3309 * @panel_orientation: drm_panel_orientation value to set 3310 * 3311 * This function sets the connector's panel_orientation and attaches 3312 * a "panel orientation" property to the connector. 3313 * 3314 * Calling this function on a connector where the panel_orientation has 3315 * already been set is a no-op (e.g. the orientation has been overridden with 3316 * a kernel commandline option). 3317 * 3318 * It is allowed to call this function with a panel_orientation of 3319 * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op. 3320 * 3321 * The function shouldn't be called in panel after drm is registered (i.e. 3322 * drm_dev_register() is called in drm). 3323 * 3324 * Returns: 3325 * Zero on success, negative errno on failure. 3326 */ 3327 int drm_connector_set_panel_orientation( 3328 struct drm_connector *connector, 3329 enum drm_panel_orientation panel_orientation) 3330 { 3331 struct drm_device *dev = connector->dev; 3332 struct drm_display_info *info = &connector->display_info; 3333 struct drm_property *prop; 3334 3335 /* Already set? */ 3336 if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 3337 return 0; 3338 3339 /* Don't attach the property if the orientation is unknown */ 3340 if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 3341 return 0; 3342 3343 info->panel_orientation = panel_orientation; 3344 3345 prop = dev->mode_config.panel_orientation_property; 3346 if (!prop) { 3347 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 3348 "panel orientation", 3349 drm_panel_orientation_enum_list, 3350 ARRAY_SIZE(drm_panel_orientation_enum_list)); 3351 if (!prop) 3352 return -ENOMEM; 3353 3354 dev->mode_config.panel_orientation_property = prop; 3355 } 3356 3357 drm_object_attach_property(&connector->base, prop, 3358 info->panel_orientation); 3359 return 0; 3360 } 3361 EXPORT_SYMBOL(drm_connector_set_panel_orientation); 3362 3363 /** 3364 * drm_connector_set_panel_orientation_with_quirk - set the 3365 * connector's panel_orientation after checking for quirks 3366 * @connector: connector for which to init the panel-orientation property. 3367 * @panel_orientation: drm_panel_orientation value to set 3368 * @width: width in pixels of the panel, used for panel quirk detection 3369 * @height: height in pixels of the panel, used for panel quirk detection 3370 * 3371 * Like drm_connector_set_panel_orientation(), but with a check for platform 3372 * specific (e.g. DMI based) quirks overriding the passed in panel_orientation. 3373 * 3374 * Returns: 3375 * Zero on success, negative errno on failure. 3376 */ 3377 int drm_connector_set_panel_orientation_with_quirk( 3378 struct drm_connector *connector, 3379 enum drm_panel_orientation panel_orientation, 3380 int width, int height) 3381 { 3382 int orientation_quirk; 3383 3384 orientation_quirk = drm_get_panel_orientation_quirk(width, height); 3385 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 3386 panel_orientation = orientation_quirk; 3387 3388 return drm_connector_set_panel_orientation(connector, 3389 panel_orientation); 3390 } 3391 EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk); 3392 3393 /** 3394 * drm_connector_set_orientation_from_panel - 3395 * set the connector's panel_orientation from panel's callback. 3396 * @connector: connector for which to init the panel-orientation property. 3397 * @panel: panel that can provide orientation information. 3398 * 3399 * Drm drivers should call this function before drm_dev_register(). 3400 * Orientation is obtained from panel's .get_orientation() callback. 3401 * 3402 * Returns: 3403 * Zero on success, negative errno on failure. 3404 */ 3405 int drm_connector_set_orientation_from_panel( 3406 struct drm_connector *connector, 3407 struct drm_panel *panel) 3408 { 3409 enum drm_panel_orientation orientation; 3410 3411 if (panel && panel->funcs && panel->funcs->get_orientation) 3412 orientation = panel->funcs->get_orientation(panel); 3413 else 3414 orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 3415 3416 return drm_connector_set_panel_orientation(connector, orientation); 3417 } 3418 EXPORT_SYMBOL(drm_connector_set_orientation_from_panel); 3419 3420 static const struct drm_prop_enum_list privacy_screen_enum[] = { 3421 { PRIVACY_SCREEN_DISABLED, "Disabled" }, 3422 { PRIVACY_SCREEN_ENABLED, "Enabled" }, 3423 { PRIVACY_SCREEN_DISABLED_LOCKED, "Disabled-locked" }, 3424 { PRIVACY_SCREEN_ENABLED_LOCKED, "Enabled-locked" }, 3425 }; 3426 3427 /** 3428 * drm_connector_create_privacy_screen_properties - create the drm connecter's 3429 * privacy-screen properties. 3430 * @connector: connector for which to create the privacy-screen properties 3431 * 3432 * This function creates the "privacy-screen sw-state" and "privacy-screen 3433 * hw-state" properties for the connector. They are not attached. 3434 */ 3435 void 3436 drm_connector_create_privacy_screen_properties(struct drm_connector *connector) 3437 { 3438 if (connector->privacy_screen_sw_state_property) 3439 return; 3440 3441 /* Note sw-state only supports the first 2 values of the enum */ 3442 connector->privacy_screen_sw_state_property = 3443 drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM, 3444 "privacy-screen sw-state", 3445 privacy_screen_enum, 2); 3446 3447 connector->privacy_screen_hw_state_property = 3448 drm_property_create_enum(connector->dev, 3449 DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM, 3450 "privacy-screen hw-state", 3451 privacy_screen_enum, 3452 ARRAY_SIZE(privacy_screen_enum)); 3453 } 3454 EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties); 3455 3456 /** 3457 * drm_connector_attach_privacy_screen_properties - attach the drm connecter's 3458 * privacy-screen properties. 3459 * @connector: connector on which to attach the privacy-screen properties 3460 * 3461 * This function attaches the "privacy-screen sw-state" and "privacy-screen 3462 * hw-state" properties to the connector. The initial state of both is set 3463 * to "Disabled". 3464 */ 3465 void 3466 drm_connector_attach_privacy_screen_properties(struct drm_connector *connector) 3467 { 3468 if (!connector->privacy_screen_sw_state_property) 3469 return; 3470 3471 drm_object_attach_property(&connector->base, 3472 connector->privacy_screen_sw_state_property, 3473 PRIVACY_SCREEN_DISABLED); 3474 3475 drm_object_attach_property(&connector->base, 3476 connector->privacy_screen_hw_state_property, 3477 PRIVACY_SCREEN_DISABLED); 3478 } 3479 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties); 3480 3481 static void drm_connector_update_privacy_screen_properties( 3482 struct drm_connector *connector, bool set_sw_state) 3483 { 3484 enum drm_privacy_screen_status sw_state, hw_state; 3485 3486 drm_privacy_screen_get_state(connector->privacy_screen, 3487 &sw_state, &hw_state); 3488 3489 if (set_sw_state) 3490 connector->state->privacy_screen_sw_state = sw_state; 3491 drm_object_property_set_value(&connector->base, 3492 connector->privacy_screen_hw_state_property, hw_state); 3493 } 3494 3495 static int drm_connector_privacy_screen_notifier( 3496 struct notifier_block *nb, unsigned long action, void *data) 3497 { 3498 struct drm_connector *connector = 3499 container_of(nb, struct drm_connector, privacy_screen_notifier); 3500 struct drm_device *dev = connector->dev; 3501 3502 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 3503 drm_connector_update_privacy_screen_properties(connector, true); 3504 drm_modeset_unlock(&dev->mode_config.connection_mutex); 3505 3506 drm_sysfs_connector_property_event(connector, 3507 connector->privacy_screen_sw_state_property); 3508 drm_sysfs_connector_property_event(connector, 3509 connector->privacy_screen_hw_state_property); 3510 3511 return NOTIFY_DONE; 3512 } 3513 3514 /** 3515 * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to 3516 * the connector 3517 * @connector: connector to attach the privacy-screen to 3518 * @priv: drm_privacy_screen to attach 3519 * 3520 * Create and attach the standard privacy-screen properties and register 3521 * a generic notifier for generating sysfs-connector-status-events 3522 * on external changes to the privacy-screen status. 3523 * This function takes ownership of the passed in drm_privacy_screen and will 3524 * call drm_privacy_screen_put() on it when the connector is destroyed. 3525 */ 3526 void drm_connector_attach_privacy_screen_provider( 3527 struct drm_connector *connector, struct drm_privacy_screen *priv) 3528 { 3529 connector->privacy_screen = priv; 3530 connector->privacy_screen_notifier.notifier_call = 3531 drm_connector_privacy_screen_notifier; 3532 3533 drm_connector_create_privacy_screen_properties(connector); 3534 drm_connector_update_privacy_screen_properties(connector, true); 3535 drm_connector_attach_privacy_screen_properties(connector); 3536 } 3537 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider); 3538 3539 /** 3540 * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state 3541 * @connector_state: connector-state to update the privacy-screen for 3542 * 3543 * This function calls drm_privacy_screen_set_sw_state() on the connector's 3544 * privacy-screen. 3545 * 3546 * If the connector has no privacy-screen, then this is a no-op. 3547 */ 3548 void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state) 3549 { 3550 struct drm_connector *connector = connector_state->connector; 3551 int ret; 3552 3553 if (!connector->privacy_screen) 3554 return; 3555 3556 ret = drm_privacy_screen_set_sw_state(connector->privacy_screen, 3557 connector_state->privacy_screen_sw_state); 3558 if (ret) { 3559 drm_err(connector->dev, "Error updating privacy-screen sw_state\n"); 3560 return; 3561 } 3562 3563 /* The hw_state property value may have changed, update it. */ 3564 drm_connector_update_privacy_screen_properties(connector, false); 3565 } 3566 EXPORT_SYMBOL(drm_connector_update_privacy_screen); 3567 3568 int drm_connector_set_obj_prop(struct drm_mode_object *obj, 3569 struct drm_property *property, 3570 uint64_t value) 3571 { 3572 int ret = -EINVAL; 3573 struct drm_connector *connector = obj_to_connector(obj); 3574 3575 /* Do DPMS ourselves */ 3576 if (property == connector->dev->mode_config.dpms_property) { 3577 ret = (*connector->funcs->dpms)(connector, (int)value); 3578 } else if (connector->funcs->set_property) 3579 ret = connector->funcs->set_property(connector, property, value); 3580 3581 if (!ret) 3582 drm_object_property_set_value(&connector->base, property, value); 3583 return ret; 3584 } 3585 3586 int drm_connector_property_set_ioctl(struct drm_device *dev, 3587 void *data, struct drm_file *file_priv) 3588 { 3589 struct drm_mode_connector_set_property *conn_set_prop = data; 3590 struct drm_mode_obj_set_property obj_set_prop = { 3591 .value = conn_set_prop->value, 3592 .prop_id = conn_set_prop->prop_id, 3593 .obj_id = conn_set_prop->connector_id, 3594 .obj_type = DRM_MODE_OBJECT_CONNECTOR 3595 }; 3596 3597 /* It does all the locking and checking we need */ 3598 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv); 3599 } 3600 3601 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) 3602 { 3603 /* For atomic drivers only state objects are synchronously updated and 3604 * protected by modeset locks, so check those first. 3605 */ 3606 if (connector->state) 3607 return connector->state->best_encoder; 3608 return connector->encoder; 3609 } 3610 3611 static bool 3612 drm_mode_expose_to_userspace(const struct drm_display_mode *mode, 3613 const struct list_head *modes, 3614 const struct drm_file *file_priv) 3615 { 3616 /* 3617 * If user-space hasn't configured the driver to expose the stereo 3D 3618 * modes, don't expose them. 3619 */ 3620 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) 3621 return false; 3622 /* 3623 * If user-space hasn't configured the driver to expose the modes 3624 * with aspect-ratio, don't expose them. However if such a mode 3625 * is unique, let it be exposed, but reset the aspect-ratio flags 3626 * while preparing the list of user-modes. 3627 */ 3628 if (!file_priv->aspect_ratio_allowed) { 3629 const struct drm_display_mode *mode_itr; 3630 3631 list_for_each_entry(mode_itr, modes, head) { 3632 if (mode_itr->expose_to_userspace && 3633 drm_mode_match(mode_itr, mode, 3634 DRM_MODE_MATCH_TIMINGS | 3635 DRM_MODE_MATCH_CLOCK | 3636 DRM_MODE_MATCH_FLAGS | 3637 DRM_MODE_MATCH_3D_FLAGS)) 3638 return false; 3639 } 3640 } 3641 3642 return true; 3643 } 3644 3645 int drm_mode_getconnector(struct drm_device *dev, void *data, 3646 struct drm_file *file_priv) 3647 { 3648 struct drm_mode_get_connector *out_resp = data; 3649 struct drm_connector *connector; 3650 struct drm_encoder *encoder; 3651 struct drm_display_mode *mode; 3652 int mode_count = 0; 3653 int encoders_count = 0; 3654 int ret = 0; 3655 int copied = 0; 3656 struct drm_mode_modeinfo u_mode; 3657 struct drm_mode_modeinfo __user *mode_ptr; 3658 uint32_t __user *encoder_ptr; 3659 bool is_current_master; 3660 3661 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 3662 return -EOPNOTSUPP; 3663 3664 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); 3665 3666 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id); 3667 if (!connector) 3668 return -ENOENT; 3669 3670 encoders_count = hweight32(connector->possible_encoders); 3671 3672 if ((out_resp->count_encoders >= encoders_count) && encoders_count) { 3673 copied = 0; 3674 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); 3675 3676 drm_connector_for_each_possible_encoder(connector, encoder) { 3677 if (put_user(encoder->base.id, encoder_ptr + copied)) { 3678 ret = -EFAULT; 3679 goto out; 3680 } 3681 copied++; 3682 } 3683 } 3684 out_resp->count_encoders = encoders_count; 3685 3686 out_resp->connector_id = connector->base.id; 3687 out_resp->connector_type = connector->connector_type; 3688 out_resp->connector_type_id = connector->connector_type_id; 3689 3690 is_current_master = drm_is_current_master(file_priv); 3691 3692 mutex_lock(&dev->mode_config.mutex); 3693 if (out_resp->count_modes == 0) { 3694 if (is_current_master) 3695 connector->funcs->fill_modes(connector, 3696 dev->mode_config.max_width, 3697 dev->mode_config.max_height); 3698 else 3699 drm_dbg_kms(dev, "User-space requested a forced probe on [CONNECTOR:%d:%s] but is not the DRM master, demoting to read-only probe\n", 3700 connector->base.id, connector->name); 3701 } 3702 3703 out_resp->mm_width = connector->display_info.width_mm; 3704 out_resp->mm_height = connector->display_info.height_mm; 3705 out_resp->subpixel = connector->display_info.subpixel_order; 3706 out_resp->connection = connector->status; 3707 3708 /* delayed so we get modes regardless of pre-fill_modes state */ 3709 list_for_each_entry(mode, &connector->modes, head) { 3710 WARN_ON(mode->expose_to_userspace); 3711 3712 if (drm_mode_expose_to_userspace(mode, &connector->modes, 3713 file_priv)) { 3714 mode->expose_to_userspace = true; 3715 mode_count++; 3716 } 3717 } 3718 3719 /* 3720 * This ioctl is called twice, once to determine how much space is 3721 * needed, and the 2nd time to fill it. 3722 */ 3723 if ((out_resp->count_modes >= mode_count) && mode_count) { 3724 copied = 0; 3725 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; 3726 list_for_each_entry(mode, &connector->modes, head) { 3727 if (!mode->expose_to_userspace) 3728 continue; 3729 3730 /* Clear the tag for the next time around */ 3731 mode->expose_to_userspace = false; 3732 3733 drm_mode_convert_to_umode(&u_mode, mode); 3734 /* 3735 * Reset aspect ratio flags of user-mode, if modes with 3736 * aspect-ratio are not supported. 3737 */ 3738 if (!file_priv->aspect_ratio_allowed) 3739 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK; 3740 if (copy_to_user(mode_ptr + copied, 3741 &u_mode, sizeof(u_mode))) { 3742 ret = -EFAULT; 3743 3744 /* 3745 * Clear the tag for the rest of 3746 * the modes for the next time around. 3747 */ 3748 list_for_each_entry_continue(mode, &connector->modes, head) 3749 mode->expose_to_userspace = false; 3750 3751 mutex_unlock(&dev->mode_config.mutex); 3752 3753 goto out; 3754 } 3755 copied++; 3756 } 3757 } else { 3758 /* Clear the tag for the next time around */ 3759 list_for_each_entry(mode, &connector->modes, head) 3760 mode->expose_to_userspace = false; 3761 } 3762 3763 out_resp->count_modes = mode_count; 3764 mutex_unlock(&dev->mode_config.mutex); 3765 3766 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 3767 encoder = drm_connector_get_encoder(connector); 3768 if (encoder) 3769 out_resp->encoder_id = encoder->base.id; 3770 else 3771 out_resp->encoder_id = 0; 3772 3773 /* Only grab properties after probing, to make sure EDID and other 3774 * properties reflect the latest status. 3775 */ 3776 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic, 3777 file_priv->plane_color_pipeline, 3778 (uint32_t __user *)(unsigned long)(out_resp->props_ptr), 3779 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), 3780 &out_resp->count_props); 3781 drm_modeset_unlock(&dev->mode_config.connection_mutex); 3782 3783 out: 3784 drm_connector_put(connector); 3785 3786 return ret; 3787 } 3788 3789 /** 3790 * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode 3791 * @fwnode: fwnode for which to find the matching drm_connector 3792 * 3793 * This functions looks up a drm_connector based on its associated fwnode. When 3794 * a connector is found a reference to the connector is returned. The caller must 3795 * call drm_connector_put() to release this reference when it is done with the 3796 * connector. 3797 * 3798 * Returns: A reference to the found connector or an ERR_PTR(). 3799 */ 3800 struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode) 3801 { 3802 struct drm_connector *connector, *found = ERR_PTR(-ENODEV); 3803 3804 if (!fwnode) 3805 return ERR_PTR(-ENODEV); 3806 3807 mutex_lock(&connector_list_lock); 3808 3809 list_for_each_entry(connector, &connector_list, global_connector_list_entry) { 3810 if (connector->fwnode == fwnode || 3811 (connector->fwnode && connector->fwnode->secondary == fwnode)) { 3812 drm_connector_get(connector); 3813 found = connector; 3814 break; 3815 } 3816 } 3817 3818 mutex_unlock(&connector_list_lock); 3819 3820 return found; 3821 } 3822 3823 /** 3824 * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector 3825 * @connector_fwnode: fwnode_handle to report the event on 3826 * @status: hot plug detect logical state 3827 * 3828 * On some hardware a hotplug event notification may come from outside the display 3829 * driver / device. An example of this is some USB Type-C setups where the hardware 3830 * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD 3831 * status bit to the GPU's DP HPD pin. 3832 * 3833 * This function can be used to report these out-of-band events after obtaining 3834 * a drm_connector reference through calling drm_connector_find_by_fwnode(). 3835 */ 3836 void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode, 3837 enum drm_connector_status status) 3838 { 3839 struct drm_connector *connector; 3840 3841 connector = drm_connector_find_by_fwnode(connector_fwnode); 3842 if (IS_ERR(connector)) 3843 return; 3844 3845 if (connector->funcs->oob_hotplug_event) 3846 connector->funcs->oob_hotplug_event(connector, status); 3847 3848 drm_connector_put(connector); 3849 } 3850 EXPORT_SYMBOL(drm_connector_oob_hotplug_event); 3851 3852 /** 3853 * drm_connector_get_color_format - Return connector color format of @conn_state 3854 * @conn_state: pointer to the &struct drm_connector_state to go check 3855 * 3856 */ 3857 enum drm_connector_color_format 3858 drm_connector_get_color_format(const struct drm_connector_state *conn_state) 3859 { 3860 struct drm_connector *connector = conn_state->connector; 3861 3862 if (connector->funcs->color_format) 3863 return connector->funcs->color_format(conn_state); 3864 3865 return conn_state->color_format; 3866 } 3867 EXPORT_SYMBOL(drm_connector_get_color_format); 3868 3869 /** 3870 * DOC: Tile group 3871 * 3872 * Tile groups are used to represent tiled monitors with a unique integer 3873 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle, 3874 * we store this in a tile group, so we have a common identifier for all tiles 3875 * in a monitor group. The property is called "TILE". Drivers can manage tile 3876 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and 3877 * drm_mode_get_tile_group(). But this is only needed for internal panels where 3878 * the tile group information is exposed through a non-standard way. 3879 */ 3880 3881 static void drm_tile_group_free(struct kref *kref) 3882 { 3883 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); 3884 struct drm_device *dev = tg->dev; 3885 3886 mutex_lock(&dev->mode_config.idr_mutex); 3887 idr_remove(&dev->mode_config.tile_idr, tg->id); 3888 mutex_unlock(&dev->mode_config.idr_mutex); 3889 kfree(tg); 3890 } 3891 3892 /** 3893 * drm_mode_put_tile_group - drop a reference to a tile group. 3894 * @dev: DRM device 3895 * @tg: tile group to drop reference to. 3896 * 3897 * drop reference to tile group and free if 0. 3898 */ 3899 void drm_mode_put_tile_group(struct drm_device *dev, 3900 struct drm_tile_group *tg) 3901 { 3902 kref_put(&tg->refcount, drm_tile_group_free); 3903 } 3904 EXPORT_SYMBOL(drm_mode_put_tile_group); 3905 3906 /** 3907 * drm_mode_get_tile_group - get a reference to an existing tile group 3908 * @dev: DRM device 3909 * @topology_id: 9-byte unique ID per monitor. 3910 * 3911 * Use the unique bytes to get a reference to an existing tile group. 3912 * 3913 * RETURNS: 3914 * tile group or NULL if not found. 3915 */ 3916 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 3917 const char topology_id[9]) 3918 { 3919 struct drm_tile_group *tg; 3920 int id; 3921 3922 mutex_lock(&dev->mode_config.idr_mutex); 3923 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { 3924 if (!memcmp(tg->group_data, topology_id, sizeof(tg->group_data))) { 3925 if (!kref_get_unless_zero(&tg->refcount)) 3926 tg = NULL; 3927 mutex_unlock(&dev->mode_config.idr_mutex); 3928 return tg; 3929 } 3930 } 3931 mutex_unlock(&dev->mode_config.idr_mutex); 3932 return NULL; 3933 } 3934 EXPORT_SYMBOL(drm_mode_get_tile_group); 3935 3936 /** 3937 * drm_mode_create_tile_group - create a tile group from a displayid description 3938 * @dev: DRM device 3939 * @topology_id: 9-byte unique ID per monitor. 3940 * 3941 * Create a tile group for the unique monitor, and get a unique 3942 * identifier for the tile group. 3943 * 3944 * RETURNS: 3945 * new tile group or NULL. 3946 */ 3947 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 3948 const char topology_id[9]) 3949 { 3950 struct drm_tile_group *tg; 3951 int ret; 3952 3953 tg = kzalloc_obj(*tg); 3954 if (!tg) 3955 return NULL; 3956 3957 kref_init(&tg->refcount); 3958 memcpy(tg->group_data, topology_id, sizeof(tg->group_data)); 3959 tg->dev = dev; 3960 3961 mutex_lock(&dev->mode_config.idr_mutex); 3962 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); 3963 if (ret >= 0) { 3964 tg->id = ret; 3965 } else { 3966 kfree(tg); 3967 tg = NULL; 3968 } 3969 3970 mutex_unlock(&dev->mode_config.idr_mutex); 3971 return tg; 3972 } 3973 EXPORT_SYMBOL(drm_mode_create_tile_group); 3974 3975 /** 3976 * drm_connector_attach_panel_type_property - attaches panel type property 3977 * @connector: connector to attach the property on. 3978 * 3979 * This is used to add support for panel type detection. 3980 */ 3981 void drm_connector_attach_panel_type_property(struct drm_connector *connector) 3982 { 3983 struct drm_device *dev = connector->dev; 3984 struct drm_property *prop = dev->mode_config.panel_type_property; 3985 3986 if (!prop) 3987 return; 3988 3989 drm_object_attach_property(&connector->base, prop, DRM_MODE_PANEL_TYPE_UNKNOWN); 3990 } 3991 EXPORT_SYMBOL(drm_connector_attach_panel_type_property); 3992