/* * Copyright (c) 2006 Luc Verhaegen (quirks list) * Copyright (c) 2007-2008 Intel Corporation * Jesse Barnes <jesse.barnes@intel.com> * Copyright 2010 Red Hat, Inc. * * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from * FB layer. * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sub license, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE.
*/
/* * EDID blocks out in the wild have a variety of bugs, try to collect * them here (note that userspace may work around broken monitors first, * but fixes should make their way here so that the kernel "just works" * on as many displays as possible).
*/
enum drm_edid_internal_quirk { /* First detailed mode wrong, use largest 60Hz mode */
EDID_QUIRK_PREFER_LARGE_60 = DRM_EDID_QUIRK_NUM, /* Reported 135MHz pixel clock is too high, needs adjustment */
EDID_QUIRK_135_CLOCK_TOO_HIGH, /* Prefer the largest mode at 75 Hz */
EDID_QUIRK_PREFER_LARGE_75, /* Detail timing is in cm not mm */
EDID_QUIRK_DETAILED_IN_CM, /* Detailed timing descriptors have bogus size values, so just take the * maximum size and use that.
*/
EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE, /* use +hsync +vsync for detailed mode */
EDID_QUIRK_DETAILED_SYNC_PP, /* Force reduced-blanking timings for detailed modes */
EDID_QUIRK_FORCE_REDUCED_BLANKING, /* Force 8bpc */
EDID_QUIRK_FORCE_8BPC, /* Force 12bpc */
EDID_QUIRK_FORCE_12BPC, /* Force 6bpc */
EDID_QUIRK_FORCE_6BPC, /* Force 10bpc */
EDID_QUIRK_FORCE_10BPC, /* Non desktop display (i.e. HMD) */
EDID_QUIRK_NON_DESKTOP, /* Cap the DSC target bitrate to 15bpp */
EDID_QUIRK_CAP_DSC_15BPP,
};
staticconstvoid *edid_block_data(conststruct edid *edid, int index)
{
BUILD_BUG_ON(sizeof(*edid) != EDID_LENGTH);
return edid + index;
}
staticconstvoid *edid_extension_block_data(conststruct edid *edid, int index)
{ return edid_block_data(edid, index + 1);
}
/* EDID block count indicated in EDID, may exceed allocated size */ staticint __drm_edid_block_count(conststruct drm_edid *drm_edid)
{ int num_blocks;
/* Starting point */
num_blocks = edid_block_count(drm_edid->edid);
/* HF-EEODB override */ if (drm_edid->size >= edid_size_by_blocks(2)) { int eeodb;
/* * Note: HF-EEODB may specify a smaller extension count than the * regular one. Unlike in buffer allocation, here we can use it.
*/
eeodb = edid_hfeeodb_block_count(drm_edid->edid); if (eeodb)
num_blocks = eeodb;
}
/* * Initializer helper for legacy interfaces, where we have no choice but to * trust edid size. Not for general purpose use.
*/ staticconststruct drm_edid *drm_edid_legacy_init(struct drm_edid *drm_edid, conststruct edid *edid)
{ if (!edid) return NULL;
/** * drm_edid_header_is_valid - sanity check the header of the base EDID block * @_edid: pointer to raw base EDID block * * Sanity check the header of the base EDID block. * * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
*/ int drm_edid_header_is_valid(constvoid *_edid)
{ conststruct edid *edid = _edid; int i, score = 0;
for (i = 0; i < sizeof(edid_header); i++) { if (edid->header[i] == edid_header[i])
score++;
}
/* * Validate a base or extension EDID block and optionally dump bad blocks to * the console.
*/ staticbool drm_edid_block_valid(void *_block, int block_num, bool print_bad_edid, bool *edid_corrupt)
{ struct edid *block = _block; enum edid_block_status status; bool is_base_block = block_num == 0; bool valid;
if (WARN_ON(!block)) returnfalse;
status = edid_block_check(block, is_base_block); if (status == EDID_BLOCK_HEADER_REPAIR) {
DRM_DEBUG_KMS("Fixing EDID header, your hardware may be failing\n");
edid_header_fix(block);
/* Retry with fixed header, update status if that worked. */
status = edid_block_check(block, is_base_block); if (status == EDID_BLOCK_OK)
status = EDID_BLOCK_HEADER_FIXED;
}
if (edid_corrupt) { /* * Unknown major version isn't corrupt but we can't use it. Only * the base block can reset edid_corrupt to false.
*/ if (is_base_block &&
(status == EDID_BLOCK_OK || status == EDID_BLOCK_VERSION))
*edid_corrupt = false; elseif (status != EDID_BLOCK_OK)
*edid_corrupt = true;
}
/* Determine whether we can use this block with this status. */
valid = edid_block_status_valid(status, edid_block_tag(block));
if (!valid && print_bad_edid && status != EDID_BLOCK_ZERO) {
pr_notice("Raw EDID:\n");
edid_block_dump(KERN_NOTICE, block, block_num);
}
return valid;
}
/** * drm_edid_is_valid - sanity check EDID data * @edid: EDID data * * Sanity-check an entire EDID record (including extensions) * * Return: True if the EDID data is valid, false otherwise.
*/ bool drm_edid_is_valid(struct edid *edid)
{ int i;
if (!edid) returnfalse;
for (i = 0; i < edid_block_count(edid); i++) { void *block = (void *)edid_block_data(edid, i);
if (!drm_edid_block_valid(block, i, true, NULL)) returnfalse;
}
returntrue;
}
EXPORT_SYMBOL(drm_edid_is_valid);
/** * drm_edid_valid - sanity check EDID data * @drm_edid: EDID data * * Sanity check an EDID. Cross check block count against allocated size and * checksum the blocks. * * Return: True if the EDID data is valid, false otherwise.
*/ bool drm_edid_valid(conststruct drm_edid *drm_edid)
{ int i;
if (!drm_edid) returnfalse;
if (edid_size_by_blocks(__drm_edid_block_count(drm_edid)) != drm_edid->size) returnfalse;
for (i = 0; i < drm_edid_block_count(drm_edid); i++) { constvoid *block = drm_edid_block_data(drm_edid, i);
if (!edid_block_valid(block, i == 0)) returnfalse;
}
returntrue;
}
EXPORT_SYMBOL(drm_edid_valid);
staticstruct edid *edid_filter_invalid_blocks(struct edid *edid,
size_t *alloc_size)
{ struct edid *new; int i, valid_blocks = 0;
/* * Note: If the EDID uses HF-EEODB, but has invalid blocks, we'll revert * back to regular extension count here. We don't want to start * modifying the HF-EEODB extension too.
*/ for (i = 0; i < edid_block_count(edid); i++) { constvoid *src_block = edid_block_data(edid, i);
if (edid_block_valid(src_block, i == 0)) { void *dst_block = (void *)edid_block_data(edid, valid_blocks);
new = krealloc(edid, *alloc_size, GFP_KERNEL); if (!new)
kfree(edid);
returnnew;
}
#define DDC_SEGMENT_ADDR 0x30 /** * drm_do_probe_ddc_edid() - get EDID information via I2C * @data: I2C device adapter * @buf: EDID data buffer to be filled * @block: 128 byte EDID block to start fetching from * @len: EDID data buffer length to fetch * * Try to fetch EDID information by calling I2C driver functions. * * Return: 0 on success or -1 on failure.
*/ staticint
drm_do_probe_ddc_edid(void *data, u8 *buf, unsignedint block, size_t len)
{ struct i2c_adapter *adapter = data; unsignedchar start = block * EDID_LENGTH; unsignedchar segment = block >> 1; unsignedchar xfers = segment ? 3 : 2; int ret, retries = 5;
/* * The core I2C driver will automatically retry the transfer if the * adapter reports EAGAIN. However, we find that bit-banging transfers * are susceptible to errors under a heavily loaded machine and * generate spurious NAKs and timeouts. Retrying the transfer * of the individual block a few times seems to overcome this.
*/ do { struct i2c_msg msgs[] = {
{
.addr = DDC_SEGMENT_ADDR,
.flags = 0,
.len = 1,
.buf = &segment,
}, {
.addr = DDC_ADDR,
.flags = 0,
.len = 1,
.buf = &start,
}, {
.addr = DDC_ADDR,
.flags = I2C_M_RD,
.len = len,
.buf = buf,
}
};
/* * Avoid sending the segment addr to not upset non-compliant * DDC monitors.
*/
ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
if (ret == -ENXIO) {
DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
adapter->name); break;
}
} while (ret != xfers && --retries);
return ret == xfers ? 0 : -1;
}
staticvoid connector_bad_edid(struct drm_connector *connector, conststruct edid *edid, int num_blocks)
{ int i;
u8 last_block;
/* * 0x7e in the EDID is the number of extension blocks. The EDID * is 1 (base block) + num_ext_blocks big. That means we can think * of 0x7e in the EDID of the _index_ of the last block in the * combined chunk of memory.
*/
last_block = edid->extensions;
/* Calculate real checksum for the last edid extension block data */ if (last_block < num_blocks)
connector->real_edid_checksum =
edid_block_compute_checksum(edid + last_block);
if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS)) return;
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] EDID is invalid:\n",
connector->base.id, connector->name); for (i = 0; i < num_blocks; i++)
edid_block_dump(KERN_DEBUG, edid + i, i);
}
/* Get override or firmware EDID */ staticconststruct drm_edid *drm_edid_override_get(struct drm_connector *connector)
{ conststruct drm_edid *override = NULL;
mutex_lock(&connector->edid_override_mutex);
if (connector->edid_override)
override = drm_edid_dup(connector->edid_override);
mutex_unlock(&connector->edid_override_mutex);
if (!override)
override = drm_edid_load_firmware(connector);
return IS_ERR(override) ? NULL : override;
}
/* For debugfs edid_override implementation */ int drm_edid_override_show(struct drm_connector *connector, struct seq_file *m)
{ conststruct drm_edid *drm_edid;
mutex_lock(&connector->edid_override_mutex);
drm_edid = connector->edid_override; if (drm_edid)
seq_write(m, drm_edid->edid, drm_edid->size);
mutex_unlock(&connector->edid_override_mutex);
return0;
}
/* For debugfs edid_override implementation */ int drm_edid_override_set(struct drm_connector *connector, constvoid *edid,
size_t size)
{ conststruct drm_edid *drm_edid;
/** * drm_edid_override_connector_update - add modes from override/firmware EDID * @connector: connector we're probing * * Add modes from the override/firmware EDID, if available. Only to be used from * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe * failed during drm_get_edid() and caused the override/firmware EDID to be * skipped. * * Return: The number of modes added or 0 if we couldn't find any.
*/ int drm_edid_override_connector_update(struct drm_connector *connector)
{ conststruct drm_edid *override; int num_modes = 0;
override = drm_edid_override_get(connector); if (override) { if (drm_edid_connector_update(connector, override) == 0)
num_modes = drm_edid_connector_add_modes(connector);
for (try = 0; try < 4; try++) { if (read_block(context, block, block_num, EDID_LENGTH)) return EDID_BLOCK_READ_FAIL;
status = edid_block_check(block, is_base_block); if (status == EDID_BLOCK_HEADER_REPAIR) {
edid_header_fix(block);
/* Retry with fixed header, update status if that worked. */
status = edid_block_check(block, is_base_block); if (status == EDID_BLOCK_OK)
status = EDID_BLOCK_HEADER_FIXED;
}
if (edid_block_status_valid(status, edid_block_tag(block))) break;
/* Fail early for unrepairable base block all zeros. */ if (try == 0 && is_base_block && status == EDID_BLOCK_ZERO) break;
}
alloc_size = edid_size(edid); new = krealloc(edid, alloc_size, GFP_KERNEL); if (!new) goto fail;
edid = new;
num_blocks = edid_block_count(edid); for (i = 1; i < num_blocks; i++) { void *block = (void *)edid_block_data(edid, i);
status = edid_block_read(block, i, read_block, context);
edid_block_status_print(status, block, i);
if (!edid_block_status_valid(status, edid_block_tag(block))) { if (status == EDID_BLOCK_READ_FAIL) goto fail;
invalid_blocks++;
} elseif (i == 1) { /* * If the first EDID extension is a CTA extension, and * the first Data Block is HF-EEODB, override the * extension block count. * * Note: HF-EEODB could specify a smaller extension * count too, but we can't risk allocating a smaller * amount.
*/ int eeodb = edid_hfeeodb_block_count(edid);
if (eeodb > num_blocks) {
num_blocks = eeodb;
alloc_size = edid_size_by_blocks(num_blocks); new = krealloc(edid, alloc_size, GFP_KERNEL); if (!new) goto fail;
edid = new;
}
}
}
if (invalid_blocks) {
connector_bad_edid(connector, edid, num_blocks);
/** * drm_edid_raw - Get a pointer to the raw EDID data. * @drm_edid: drm_edid container * * Get a pointer to the raw EDID data. * * This is for transition only. Avoid using this like the plague. * * Return: Pointer to raw EDID data.
*/ conststruct edid *drm_edid_raw(conststruct drm_edid *drm_edid)
{ if (!drm_edid || !drm_edid->size) return NULL;
/* * Do not return pointers where relying on EDID extension count would * lead to buffer overflow.
*/ if (WARN_ON(edid_size(drm_edid->edid) > drm_edid->size)) return NULL;
/** * drm_edid_alloc - Allocate a new drm_edid container * @edid: Pointer to raw EDID data * @size: Size of memory allocated for EDID * * Allocate a new drm_edid container. Do not calculate edid size from edid, pass * the actual size that has been allocated for the data. There is no validation * of the raw EDID data against the size, but at least the EDID base block must * fit in the buffer. * * The returned pointer must be freed using drm_edid_free(). * * Return: drm_edid container, or NULL on errors
*/ conststruct drm_edid *drm_edid_alloc(constvoid *edid, size_t size)
{ conststruct drm_edid *drm_edid;
if (!edid || !size || size < EDID_LENGTH) return NULL;
edid = kmemdup(edid, size, GFP_KERNEL); if (!edid) return NULL;
drm_edid = _drm_edid_alloc(edid, size); if (!drm_edid)
kfree(edid);
return drm_edid;
}
EXPORT_SYMBOL(drm_edid_alloc);
/** * drm_edid_dup - Duplicate a drm_edid container * @drm_edid: EDID to duplicate * * The returned pointer must be freed using drm_edid_free(). * * Returns: drm_edid container copy, or NULL on errors
*/ conststruct drm_edid *drm_edid_dup(conststruct drm_edid *drm_edid)
{ if (!drm_edid) return NULL;
/** * drm_get_edid - get EDID data, if available * @connector: connector we're probing * @adapter: I2C adapter to use for DDC * * Poke the given I2C channel to grab EDID data if possible. If found, * attach it to the connector. * * Return: Pointer to valid EDID or NULL if we couldn't find any.
*/ struct edid *drm_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
{ struct edid *edid;
if (connector->force == DRM_FORCE_OFF) return NULL;
if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) return NULL;
/** * drm_edid_read_custom - Read EDID data using given EDID block read function * @connector: Connector to use * @read_block: EDID block read function * @context: Private data passed to the block read function * * When the I2C adapter connected to the DDC bus is hidden behind a device that * exposes a different interface to read EDID blocks this function can be used * to get EDID data using a custom block read function. * * As in the general case the DDC bus is accessible by the kernel at the I2C * level, drivers must make all reasonable efforts to expose it as an I2C * adapter and use drm_edid_read() or drm_edid_read_ddc() instead of abusing * this function. * * The EDID may be overridden using debugfs override_edid or firmware EDID * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority * order. Having either of them bypasses actual EDID reads. * * The returned pointer must be freed using drm_edid_free(). * * Return: Pointer to EDID, or NULL if probe/read failed.
*/ conststruct drm_edid *drm_edid_read_custom(struct drm_connector *connector,
read_block_fn read_block, void *context)
{ conststruct drm_edid *drm_edid; struct edid *edid;
size_t size = 0;
edid = _drm_do_get_edid(connector, read_block, context, &size); if (!edid) return NULL;
/* Sanity check for now */
drm_WARN_ON(connector->dev, !size);
drm_edid = _drm_edid_alloc(edid, size); if (!drm_edid)
kfree(edid);
/** * drm_edid_read_ddc - Read EDID data using given I2C adapter * @connector: Connector to use * @adapter: I2C adapter to use for DDC * * Read EDID using the given I2C adapter. * * The EDID may be overridden using debugfs override_edid or firmware EDID * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority * order. Having either of them bypasses actual EDID reads. * * Prefer initializing connector->ddc with drm_connector_init_with_ddc() and * using drm_edid_read() instead of this function. * * The returned pointer must be freed using drm_edid_free(). * * Return: Pointer to EDID, or NULL if probe/read failed.
*/ conststruct drm_edid *drm_edid_read_ddc(struct drm_connector *connector, struct i2c_adapter *adapter)
{ conststruct drm_edid *drm_edid;
if (connector->force == DRM_FORCE_OFF) return NULL;
if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter)) return NULL;
/** * drm_edid_read - Read EDID data using connector's I2C adapter * @connector: Connector to use * * Read EDID using the connector's I2C adapter. * * The EDID may be overridden using debugfs override_edid or firmware EDID * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority * order. Having either of them bypasses actual EDID reads. * * The returned pointer must be freed using drm_edid_free(). * * Return: Pointer to EDID, or NULL if probe/read failed.
*/ conststruct drm_edid *drm_edid_read(struct drm_connector *connector)
{ if (drm_WARN_ON(connector->dev, !connector->ddc)) return NULL;
/** * drm_edid_get_panel_id - Get a panel's ID from EDID * @drm_edid: EDID that contains panel ID. * * This function uses the first block of the EDID of a panel and (assuming * that the EDID is valid) extracts the ID out of it. The ID is a 32-bit value * (16 bits of manufacturer ID and 16 bits of per-manufacturer ID) that's * supposed to be different for each different modem of panel. * * Return: A 32-bit ID that should be different for each make/model of panel. * See the functions drm_edid_encode_panel_id() and * drm_edid_decode_panel_id() for some details on the structure of this * ID. Return 0 if the EDID size is less than a base block.
*/
u32 drm_edid_get_panel_id(conststruct drm_edid *drm_edid)
{ conststruct edid *edid = drm_edid->edid;
if (drm_edid->size < EDID_LENGTH) return0;
/* * We represent the ID as a 32-bit number so it can easily be compared * with "==". * * NOTE that we deal with endianness differently for the top half * of this ID than for the bottom half. The bottom half (the product * id) gets decoded as little endian by the EDID_PRODUCT_ID because * that's how everyone seems to interpret it. The top half (the mfg_id) * gets stored as big endian because that makes * drm_edid_encode_panel_id() and drm_edid_decode_panel_id() easier * to write (it's easier to extract the ASCII). It doesn't really * matter, though, as long as the number here is unique.
*/ return (u32)edid->mfg_id[0] << 24 |
(u32)edid->mfg_id[1] << 16 |
(u32)EDID_PRODUCT_ID(edid);
}
EXPORT_SYMBOL(drm_edid_get_panel_id);
/** * drm_edid_read_base_block - Get a panel's EDID base block * @adapter: I2C adapter to use for DDC * * This function returns the drm_edid containing the first block of the EDID of * a panel. * * This function is intended to be used during early probing on devices where * more than one panel might be present. Because of its intended use it must * assume that the EDID of the panel is correct, at least as far as the base * block is concerned (in other words, we don't process any overrides here). * * Caller should call drm_edid_free() after use. * * NOTE: it's expected that this function and drm_do_get_edid() will both * be read the EDID, but there is no caching between them. Since we're only * reading the first block, hopefully this extra overhead won't be too big. * * WARNING: Only use this function when the connector is unknown. For example, * during the early probe of panel. The EDID read from the function is temporary * and should be replaced by the full EDID returned from other drm_edid_read. * * Return: Pointer to allocated EDID base block, or NULL on any failure.
*/ conststruct drm_edid *drm_edid_read_base_block(struct i2c_adapter *adapter)
{ enum edid_block_status status; void *base_block;
base_block = kzalloc(EDID_LENGTH, GFP_KERNEL); if (!base_block) return NULL;
status = edid_block_read(base_block, 0, drm_do_probe_ddc_edid, adapter);
/** * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output * @connector: connector we're probing * @adapter: I2C adapter to use for DDC * * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily * switch DDC to the GPU which is retrieving EDID. * * Return: Pointer to valid EDID or %NULL if we couldn't find any.
*/ struct edid *drm_get_edid_switcheroo(struct drm_connector *connector, struct i2c_adapter *adapter)
{ struct drm_device *dev = connector->dev; struct pci_dev *pdev = to_pci_dev(dev->dev); struct edid *edid;
if (drm_WARN_ON_ONCE(dev, !dev_is_pci(dev->dev))) return NULL;
/** * drm_edid_read_switcheroo - get EDID data for a vga_switcheroo output * @connector: connector we're probing * @adapter: I2C adapter to use for DDC * * Wrapper around drm_edid_read_ddc() for laptops with dual GPUs using one set * of outputs. The wrapper adds the requisite vga_switcheroo calls to * temporarily switch DDC to the GPU which is retrieving EDID. * * Return: Pointer to valid EDID or %NULL if we couldn't find any.
*/ conststruct drm_edid *drm_edid_read_switcheroo(struct drm_connector *connector, struct i2c_adapter *adapter)
{ struct drm_device *dev = connector->dev; struct pci_dev *pdev = to_pci_dev(dev->dev); conststruct drm_edid *drm_edid;
if (drm_WARN_ON_ONCE(dev, !dev_is_pci(dev->dev))) return NULL;
/** * drm_edid_duplicate - duplicate an EDID and the extensions * @edid: EDID to duplicate * * Return: Pointer to duplicated EDID or NULL on allocation failure.
*/ struct edid *drm_edid_duplicate(conststruct edid *edid)
{ if (!edid) return NULL;
/** * edid_get_quirks - return quirk flags for a given EDID * @drm_edid: EDID to process * * This tells subsequent routines what fixes they need to apply. * * Return: A u32 represents the quirks to apply.
*/ static u32 edid_get_quirks(conststruct drm_edid *drm_edid)
{ conststruct edid_quirk *quirk; int i;
for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
quirk = &edid_quirk_list[i]; if (drm_edid_match(drm_edid, &quirk->ident)) return quirk->quirks;
}
/* * Walk the mode list for connector, clearing the preferred status on existing * modes and setting it anew for the right mode ala quirks.
*/ staticvoid edid_fixup_preferred(struct drm_connector *connector)
{ struct drm_display_mode *t, *cur_mode, *preferred_mode; int target_refresh = 0; int cur_vrefresh, preferred_vrefresh;
if (list_empty(&connector->probed_modes)) return;
if (drm_edid_has_internal_quirk(connector, EDID_QUIRK_PREFER_LARGE_60))
target_refresh = 60; if (drm_edid_has_internal_quirk(connector, EDID_QUIRK_PREFER_LARGE_75))
target_refresh = 75;
/* Largest mode is preferred */ if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
preferred_mode = cur_mode;
cur_vrefresh = drm_mode_vrefresh(cur_mode);
preferred_vrefresh = drm_mode_vrefresh(preferred_mode); /* At a given size, try to get closest to target refresh */ if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
preferred_mode = cur_mode;
}
}
/* * drm_mode_find_dmt - Create a copy of a mode if present in DMT * @dev: Device to duplicate against * @hsize: Mode width * @vsize: Mode height * @fresh: Mode refresh rate * @rb: Mode reduced-blanking-ness * * Walk the DMT mode list looking for a match for the given parameters. * * Return: A newly allocated copy of the mode, or NULL if not found.
*/ struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, int hsize, int vsize, int fresh, bool rb)
{ int i;
for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) { conststruct drm_display_mode *ptr = &drm_dmt_modes[i];
if (hsize != ptr->hdisplay) continue; if (vsize != ptr->vdisplay) continue; if (fresh != drm_mode_vrefresh(ptr)) continue; if (rb != mode_is_rb(ptr)) continue;
/* * 0 is reserved. The spec says 0x01 fill for unused timings. Some old * monitors fill with ascii space (0x20) instead.
*/ staticint
bad_std_timing(u8 a, u8 b)
{ return (a == 0x00 && b == 0x00) ||
(a == 0x01 && b == 0x01) ||
(a == 0x20 && b == 0x20);
}
staticint drm_mode_hsync(conststruct drm_display_mode *mode)
{ if (mode->htotal <= 0) return0;
staticstruct drm_display_mode *
drm_gtf2_mode(struct drm_device *dev, conststruct drm_edid *drm_edid, int hsize, int vsize, int vrefresh_rate)
{ struct drm_display_mode *mode;
/* * This is potentially wrong if there's ever a monitor with * more than one ranges section, each claiming a different * secondary GTF curve. Please don't do that.
*/
mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0); if (!mode) return NULL;
/* * Take the standard timing params (in this case width, aspect, and refresh) * and convert them into a real mode using CVT/GTF/DMT.
*/ staticstruct drm_display_mode *drm_mode_std(struct drm_connector *connector, conststruct drm_edid *drm_edid, conststruct std_timing *t)
{ struct drm_device *dev = connector->dev; struct drm_display_mode *m, *mode = NULL; int hsize, vsize; int vrefresh_rate; unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
>> EDID_TIMING_ASPECT_SHIFT; unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
>> EDID_TIMING_VFREQ_SHIFT; int timing_level = standard_timing_level(drm_edid);
if (bad_std_timing(t->hsize, t->vfreq_aspect)) return NULL;
/* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
hsize = t->hsize * 8 + 248; /* vrefresh_rate = vfreq + 60 */
vrefresh_rate = vfreq + 60; /* the vdisplay is calculated based on the aspect ratio */ if (aspect_ratio == 0) { if (drm_edid->edid->revision < 3)
vsize = hsize; else
vsize = (hsize * 10) / 16;
} elseif (aspect_ratio == 1)
vsize = (hsize * 3) / 4; elseif (aspect_ratio == 2)
vsize = (hsize * 4) / 5; else
vsize = (hsize * 9) / 16;
/* * If this connector already has a mode for this size and refresh * rate (because it came from detailed or CVT info), use that * instead. This way we don't have to guess at interlace or * reduced blanking.
*/
list_for_each_entry(m, &connector->probed_modes, head) if (m->hdisplay == hsize && m->vdisplay == vsize &&
drm_mode_vrefresh(m) == vrefresh_rate) return NULL;
/* check whether it can be found in default mode table */ if (drm_monitor_supports_rb(drm_edid)) {
mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, true); if (mode) return mode;
}
mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false); if (mode) return mode;
/* okay, generate it */ switch (timing_level) { case LEVEL_DMT: break; case LEVEL_GTF:
mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0); break; case LEVEL_GTF2:
mode = drm_gtf2_mode(dev, drm_edid, hsize, vsize, vrefresh_rate); break; case LEVEL_CVT:
mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0, false); break;
} return mode;
}
/* * EDID is delightfully ambiguous about how interlaced modes are to be * encoded. Our internal representation is of frame height, but some * HDTV detailed timings are encoded as field height. * * The format list here is from CEA, in frame size. Technically we * should be checking refresh rate too. Whatever.
*/ staticvoid
drm_mode_do_interlace_quirk(struct drm_display_mode *mode, conststruct detailed_pixel_timing *pt)
{ int i; staticconststruct { int w, h;
} cea_interlaced[] = {
{ 1920, 1080 },
{ 720, 480 },
{ 1440, 480 },
{ 2880, 480 },
{ 720, 576 },
{ 1440, 576 },
{ 2880, 576 },
};
if (!(pt->misc & DRM_EDID_PT_INTERLACED)) return;
for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) { if ((mode->hdisplay == cea_interlaced[i].w) &&
(mode->vdisplay == cea_interlaced[i].h / 2)) {
mode->vdisplay *= 2;
mode->vsync_start *= 2;
mode->vsync_end *= 2;
mode->vtotal *= 2;
mode->vtotal |= 1;
}
}
if (pt->misc & DRM_EDID_PT_STEREO) {
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Stereo mode not supported\n",
connector->base.id, connector->name); return NULL;
} if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Composite sync not supported\n",
connector->base.id, connector->name);
}
/* it is incorrect if hsync/vsync width is zero */ if (!hsync_pulse_width || !vsync_pulse_width) {
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Incorrect Detailed timing. Wrong Hsync/Vsync pulse width\n",
connector->base.id, connector->name); return NULL;
}
if (drm_edid_has_internal_quirk(connector, EDID_QUIRK_FORCE_REDUCED_BLANKING)) {
mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false); if (!mode) return NULL;
goto set_size;
}
mode = drm_mode_create(dev); if (!mode) return NULL;
/* 1.4 with CVT support gives us real precision, yay */ if (edid->revision >= 4 && t[10] == DRM_EDID_CVT_SUPPORT_FLAG) return (t[9] * 10000) - ((t[12] >> 2) * 250);
/* 1.3 is pathetic, so fuzz up a bit */ return t[9] * 10000 + 5001;
}
/* * Get established modes from EDID and add them. Each EDID block contains a * bitmap of the supported "established modes" list (defined above). Tease them * out and add them to the global modes list.
*/ staticint add_established_modes(struct drm_connector *connector, conststruct drm_edid *drm_edid)
{ struct drm_device *dev = connector->dev; conststruct edid *edid = drm_edid->edid; unsignedlong est_bits = edid->established_timings.t1 |
(edid->established_timings.t2 << 8) |
((edid->established_timings.mfg_rsvd & 0x80) << 9); int i, modes = 0; struct detailed_mode_closure closure = {
.connector = connector,
.drm_edid = drm_edid,
};
for (i = 0; i <= EDID_EST_TIMINGS; i++) { if (est_bits & (1<<i)) { struct drm_display_mode *newmode;
/* * Get standard modes from EDID and add them. Standard modes can be calculated * using the appropriate standard (DMT, GTF, or CVT). Grab them from EDID and * add them to the list.
*/ staticint add_standard_modes(struct drm_connector *connector, conststruct drm_edid *drm_edid)
{ int i, modes = 0; struct detailed_mode_closure closure = {
.connector = connector,
.drm_edid = drm_edid,
};
for (i = 0; i < EDID_STD_TIMINGS; i++) { struct drm_display_mode *newmode;
if (!is_detailed_timing_descriptor(timing)) return;
newmode = drm_mode_detailed(closure->connector,
closure->drm_edid, timing); if (!newmode) return;
if (closure->preferred)
newmode->type |= DRM_MODE_TYPE_PREFERRED;
/* * Detailed modes are limited to 10kHz pixel clock resolution, * so fix up anything that looks like CEA/HDMI mode, but the clock * is just slightly off.
*/
fixup_detailed_cea_mode_clock(closure->connector, newmode);
/* * Search EDID for CEA extension block. * * FIXME: Prefer not returning pointers to raw EDID data.
*/ const u8 *drm_edid_find_extension(conststruct drm_edid *drm_edid, int ext_id, int *ext_index)
{ const u8 *edid_ext = NULL; int i;
/* No EDID or EDID extensions */ if (!drm_edid || !drm_edid_extension_block_count(drm_edid)) return NULL;
/* Find CEA extension */ for (i = *ext_index; i < drm_edid_extension_block_count(drm_edid); i++) {
edid_ext = drm_edid_extension_block_data(drm_edid, i); if (edid_block_tag(edid_ext) == ext_id) break;
}
if (i >= drm_edid_extension_block_count(drm_edid)) return NULL;
*ext_index = i + 1;
return edid_ext;
}
/* Return true if the EDID has a CTA extension or a DisplayID CTA data block */ staticbool drm_edid_has_cta_extension(conststruct drm_edid *drm_edid)
{ conststruct displayid_block *block; struct displayid_iter iter; struct drm_edid_iter edid_iter; const u8 *ext; bool found = false;
/* Look for a top level CEA extension block */
drm_edid_iter_begin(drm_edid, &edid_iter);
drm_edid_iter_for_each(ext, &edid_iter) { if (ext[0] == CEA_EXT) {
found = true; break;
}
}
drm_edid_iter_end(&edid_iter);
if (found) returntrue;
/* CEA blocks can also be found embedded in a DisplayID block */
displayid_iter_edid_begin(drm_edid, &iter);
displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_CTA) {
found = true; break;
}
}
displayid_iter_end(&iter);
/* * Calculate the alternate clock for the CEA mode * (60Hz vs. 59.94Hz etc.)
*/ staticunsignedint
cea_mode_alternate_clock(conststruct drm_display_mode *cea_mode)
{ unsignedint clock = cea_mode->clock;
if (drm_mode_vrefresh(cea_mode) % 6 != 0) return clock;
/* * edid_cea_modes contains the 59.94Hz * variant for 240 and 480 line modes, * and the 60Hz variant otherwise.
*/ if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
clock = DIV_ROUND_CLOSEST(clock * 1001, 1000); else
clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
return clock;
}
staticbool
cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
{ /* * For certain VICs the spec allows the vertical * front porch to vary by one or two lines. * * cea_modes[] stores the variant with the shortest * vertical front porch. We can adjust the mode to * get the other variants by simply increasing the * vertical front porch length.
*/
BUILD_BUG_ON(cea_mode_for_vic(8)->vtotal != 262 ||
cea_mode_for_vic(9)->vtotal != 262 ||
cea_mode_for_vic(12)->vtotal != 262 ||
cea_mode_for_vic(13)->vtotal != 262 ||
cea_mode_for_vic(23)->vtotal != 312 ||
cea_mode_for_vic(24)->vtotal != 312 ||
cea_mode_for_vic(27)->vtotal != 312 ||
cea_mode_for_vic(28)->vtotal != 312);
do { if (drm_mode_match(to_match, &cea_mode, match_flags)) return vic;
} while (cea_mode_alternate_timings(vic, &cea_mode));
}
return0;
}
/** * drm_match_cea_mode - look for a CEA mode matching given mode * @to_match: display mode * * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861 * mode.
*/
u8 drm_match_cea_mode(conststruct drm_display_mode *to_match)
{ unsignedint match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
u8 vic;
if (!to_match->clock) return0;
if (to_match->picture_aspect_ratio)
match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
if (drm_mode_match(to_match, hdmi_mode, match_flags)) return vic;
}
return0;
}
/* * drm_match_hdmi_mode - look for a HDMI mode matching given mode * @to_match: display mode * * An HDMI mode is one defined in the HDMI vendor specific block. * * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
*/ static u8 drm_match_hdmi_mode(conststruct drm_display_mode *to_match)
{ unsignedint match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
u8 vic;
if (!to_match->clock) return0;
if (to_match->picture_aspect_ratio)
match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
/* Don't add CTA modes if the CTA extension block is missing */ if (!drm_edid_has_cta_extension(drm_edid)) return0;
/* * Go through all probed modes and create a new mode * with the alternate clock for certain CEA modes.
*/
list_for_each_entry(mode, &connector->probed_modes, head) { conststruct drm_display_mode *cea_mode = NULL; struct drm_display_mode *newmode;
u8 vic = drm_match_cea_mode(mode); unsignedint clock1, clock2;
if (mode->clock != clock1 && mode->clock != clock2) continue;
newmode = drm_mode_duplicate(dev, cea_mode); if (!newmode) continue;
/* Carry over the stereo flags */
newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
/* * The current mode could be either variant. Make * sure to pick the "other" clock for the new mode.
*/ if (mode->clock != clock1)
newmode->clock = clock1; else
newmode->clock = clock2;
/* * Return a display mode for the 0-based vic_index'th VIC across all CTA VDBs in * the EDID, or NULL on errors.
*/ staticstruct drm_display_mode *
drm_display_mode_from_vic_index(struct drm_connector *connector, int vic_index)
{ conststruct drm_display_info *info = &connector->display_info; struct drm_device *dev = connector->dev;
if (!info->vics || vic_index >= info->vics_len || !info->vics[vic_index]) return NULL;
/* * do_y420vdb_modes - Parse YCBCR 420 only modes * @connector: connector corresponding to the HDMI sink * @svds: start of the data block of CEA YCBCR 420 VDB * @len: length of the CEA YCBCR 420 VDB * * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB) * which contains modes which can be supported in YCBCR 420 * output format only.
*/ staticint do_y420vdb_modes(struct drm_connector *connector, const u8 *svds, u8 svds_len)
{ struct drm_device *dev = connector->dev; int modes = 0, i;
for (i = 0; i < svds_len; i++) {
u8 vic = svd_to_vic(svds[i]); struct drm_display_mode *newmode;
/** * drm_display_mode_from_cea_vic() - return a mode for CEA VIC * @dev: DRM device * @video_code: CEA VIC of the mode * * Creates a new mode matching the specified CEA VIC. * * Returns: A new drm_display_mode on success or NULL on failure
*/ struct drm_display_mode *
drm_display_mode_from_cea_vic(struct drm_device *dev,
u8 video_code)
{ conststruct drm_display_mode *cea_mode; struct drm_display_mode *newmode;
cea_mode = cea_mode_for_vic(video_code); if (!cea_mode) return NULL;
newmode = drm_mode_duplicate(dev, cea_mode); if (!newmode) return NULL;
/* Add modes based on VICs parsed in parse_cta_vdb() */ staticint add_cta_vdb_modes(struct drm_connector *connector)
{ conststruct drm_display_info *info = &connector->display_info; int i, modes = 0;
if (!info->vics) return0;
for (i = 0; i < info->vics_len; i++) { struct drm_display_mode *mode;
/* * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block * @connector: connector corresponding to the HDMI sink * @db: start of the CEA vendor specific block * @len: length of the CEA block payload, ie. one can access up to db[len] * * Parses the HDMI VSDB looking for modes to add to @connector. This function * also adds the stereo 3d modes when applicable.
*/ staticint
do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len)
{ int modes = 0, offset = 0, i, multi_present = 0, multi_len;
u8 vic_len, hdmi_3d_len = 0;
u16 mask;
u16 structure_all;
if (len < 8) goto out;
/* no HDMI_Video_Present */ if (!(db[8] & (1 << 5))) goto out;
offset += hdmi_vsdb_latency_length(db);
/* the declared length is not long enough for the 2 first bytes
* of additional video format capabilities */ if (len < (8 + offset + 2)) goto out;
staticint
cea_revision(const u8 *cea)
{ /* * FIXME is this correct for the DispID variant? * The DispID spec doesn't really specify whether * this is the revision of the CEA extension or * the DispID CEA data block. And the only value * given as an example is 0.
*/ return cea[1];
}
/* * CTA Data Block iterator. * * Iterate through all CTA Data Blocks in both EDID CTA Extensions and DisplayID * CTA Data Blocks. * * struct cea_db *db: * struct cea_db_iter iter; * * cea_db_iter_edid_begin(edid, &iter); * cea_db_iter_for_each(db, &iter) { * // do stuff with db * } * cea_db_iter_end(&iter);
*/ struct cea_db_iter { struct drm_edid_iter edid_iter; struct displayid_iter displayid_iter;
/* Current Data Block Collection. */ const u8 *collection;
/* Current Data Block index in current collection. */ int index;
/* End index in current collection. */ int end;
};
drm_edid_iter_for_each(ext, &iter->edid_iter) { int size;
/* Only support CTA Extension revision 3+ */ if (ext[0] != CEA_EXT || cea_revision(ext) < 3) continue;
size = cea_db_collection_size(ext); if (!size) continue;
iter->index = 4;
iter->end = iter->index + size;
return ext;
}
return NULL;
}
/* * References: * - DisplayID v1.3 Appendix C: CEA Data Block within a DisplayID Data Block * - DisplayID v2.0 section 4.10 CTA DisplayID Data Block * * Note that the above do not specify any connection between DisplayID Data * Block revision and CTA Extension versions.
*/ staticconstvoid *__cea_db_iter_displayid_next(struct cea_db_iter *iter)
{ conststruct displayid_block *block;
displayid_iter_for_each(block, &iter->displayid_iter) { if (block->tag != DATA_BLOCK_CTA) continue;
/* * The displayid iterator has already verified the block bounds * in displayid_iter_block().
*/
iter->index = sizeof(*block);
iter->end = iter->index + block->num_bytes;
if (iter->collection) { /* Current collection should always be valid. */
db = __cea_db_iter_current_block(iter); if (WARN_ON(!db)) {
iter->collection = NULL; return NULL;
}
/* Next block in CTA Data Block Collection */
iter->index += sizeof(*db) + cea_db_payload_len(db);
db = __cea_db_iter_current_block(iter); if (db) return db;
}
for (;;) { /* * Find the next CTA Data Block Collection. First iterate all * the EDID CTA Extensions, then all the DisplayID CTA blocks. * * Per DisplayID v1.3 Appendix B: DisplayID as an EDID * Extension, it's recommended that DisplayID extensions are * exposed after all of the CTA Extensions.
*/
iter->collection = __cea_db_iter_edid_next(iter); if (!iter->collection)
iter->collection = __cea_db_iter_displayid_next(iter);
if (!iter->collection) return NULL;
db = __cea_db_iter_current_block(iter); if (db) return db;
}
}
#define cea_db_iter_for_each(__db, __iter) \ while (((__db) = __cea_db_iter_next(__iter)))
/* * Get the HF-EEODB override extension block count from EDID. * * The passed in EDID may be partially read, as long as it has at least two * blocks (base block and one extension block) if EDID extension count is > 0. * * Note that this is *not* how you should parse CTA Data Blocks in general; this * is only to handle partially read EDIDs. Normally, use the CTA Data Block * iterators instead. * * References: * - HDMI 2.1 section 10.3.6 HDMI Forum EDID Extension Override Data Block
*/ staticint edid_hfeeodb_extension_block_count(conststruct edid *edid)
{ const u8 *cta;
/* No extensions according to base block, no HF-EEODB. */ if (!edid_extension_block_count(edid)) return0;
/* HF-EEODB is always in the first EDID extension block only */
cta = edid_extension_block_data(edid, 0); if (edid_block_tag(cta) != CEA_EXT || cea_revision(cta) < 3) return0;
/* Need to have the data block collection, and at least 3 bytes. */ if (cea_db_collection_size(cta) < 3) return0;
/* * Sinks that include the HF-EEODB in their E-EDID shall include one and * only one instance of the HF-EEODB in the E-EDID, occupying bytes 4 * through 6 of Block 1 of the E-EDID.
*/ if (!cea_db_is_hdmi_forum_eeodb(&cta[4])) return0;
return cta[4 + 2];
}
/* * CTA-861 YCbCr 4:2:0 Capability Map Data Block (CTA Y420CMDB) * * Y420CMDB contains a bitmap which gives the index of CTA modes from CTA VDB, * which can support YCBCR 420 sampling output also (apart from RGB/YCBCR444 * etc). For example, if the bit 0 in bitmap is set, first mode in VDB can * support YCBCR420 output too.
*/ staticvoid parse_cta_y420cmdb(struct drm_connector *connector, conststruct cea_db *db, u64 *y420cmdb_map)
{ struct drm_display_info *info = &connector->display_info; int i, map_len = cea_db_payload_len(db) - 1; const u8 *data = cea_db_data(db) + 1;
u64 map = 0;
if (map_len == 0) { /* All CEA modes support ycbcr420 sampling also.*/
map = U64_MAX; goto out;
}
/* * This map indicates which of the existing CEA block modes * from VDB can support YCBCR420 output too. So if bit=0 is * set, first mode from VDB can support YCBCR420 output too. * We will parse and keep this map, before parsing VDB itself * to avoid going through the same block again and again. * * Spec is not clear about max possible size of this block. * Clamping max bitmap block size at 8 bytes. Every byte can * address 8 CEA modes, in this way this map can address * 8*8 = first 64 SVDs.
*/ if (WARN_ON_ONCE(map_len > 8))
map_len = 8;
for (i = 0; i < map_len; i++)
map |= (u64)data[i] << (8 * i);
out: if (map)
info->color_formats |= DRM_COLOR_FORMAT_YCBCR420;
/* * From the specification (CTA-861-G), for calculating the maximum * luminance we need to use: * Luminance = 50*2**(CV/32) * Where CV is a one-byte value. * For calculating this expression we may need float point precision; * to avoid this complexity level, we take advantage that CV is divided * by a constant. From the Euclids division algorithm, we know that CV * can be written as: CV = 32*q + r. Next, we replace CV in the * Luminance expression and get 50*(2**q)*(2**(r/32)), hence we just * need to pre-compute the value of r/32. For pre-computing the values * We just used the following Ruby line: * (0...32).each {|cv| puts (50*2**(cv/32.0)).round} * The results of the above expressions can be verified at * pre_computed_values.
*/
q = max_avg >> 5;
r = max_avg % 32;
max = (1 << q) * pre_computed_values[r];
/* min luminance: maxLum * (CV/255)^2 / 100 */
q = DIV_ROUND_CLOSEST(min_cll, 255);
min = max * DIV_ROUND_CLOSEST((q * q), 100);
for (i = name_len; i < desc_len; i++) { if (desc[i] == '\n') break; /* Allow white space before EDID string terminator. */ if (!isspace(desc[i])) return;
}
closure->matched = true;
}
/** * drm_edid_match - match drm_edid with given identity * @drm_edid: EDID * @ident: the EDID identity to match with * * Check if the EDID matches with the given identity. * * Return: True if the given identity matched with EDID, false otherwise.
*/ bool drm_edid_match(conststruct drm_edid *drm_edid, conststruct drm_edid_ident *ident)
{ if (!drm_edid || drm_edid_get_panel_id(drm_edid) != ident->panel_id) returnfalse;
/* Match with name only if it's not NULL. */ if (ident->name) { struct drm_edid_match_closure closure = {
.ident = ident,
.matched = false,
};
drm_for_each_detailed_block(drm_edid, monitor_name, &edid_name); for (mnl = 0; edid_name && mnl < 13; mnl++) { if (edid_name[mnl] == 0x0a) break;
name[mnl] = edid_name[mnl];
}
return mnl;
}
/** * drm_edid_get_monitor_name - fetch the monitor name from the edid * @edid: monitor EDID information * @name: pointer to a character array to hold the name of the monitor * @bufsize: The size of the name buffer (should be at least 14 chars.) *
*/ void drm_edid_get_monitor_name(conststruct edid *edid, char *name, int bufsize)
{ int name_length = 0;
/* * drm_edid_to_eld - build ELD from EDID * @connector: connector corresponding to the HDMI/DP sink * @drm_edid: EDID to parse * * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
*/ staticvoid drm_edid_to_eld(struct drm_connector *connector, conststruct drm_edid *drm_edid)
{ conststruct drm_display_info *info = &connector->display_info; conststruct cea_db *db; struct cea_db_iter iter;
uint8_t *eld = connector->eld; int total_sad_count = 0; int mnl;
cea_db_iter_edid_begin(drm_edid, &iter);
cea_db_iter_for_each(db, &iter) { if (cea_db_tag(db) == CTA_DB_AUDIO) { struct cea_sad *sads; int i;
count = cea_db_payload_len(db) / 3; /* SAD is 3B */
sads = kcalloc(count, sizeof(*sads), GFP_KERNEL);
*psads = sads; if (!sads) return -ENOMEM; for (i = 0; i < count; i++)
drm_edid_cta_sad_set(&sads[i], &db->data[i * 3]); break;
}
}
cea_db_iter_end(&iter);
DRM_DEBUG_KMS("Found %d Short Audio Descriptors\n", count);
return count;
}
/** * drm_edid_to_sad - extracts SADs from EDID * @edid: EDID to parse * @sads: pointer that will be set to the extracted SADs * * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it. * * Note: The returned pointer needs to be freed using kfree(). * * Return: The number of found SADs or negative number on error.
*/ int drm_edid_to_sad(conststruct edid *edid, struct cea_sad **sads)
{ struct drm_edid drm_edid;
DRM_DEBUG_KMS("Found %d Speaker Allocation Data Blocks\n", count);
return count;
}
/** * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID * @edid: EDID to parse * @sadb: pointer to the speaker block * * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it. * * Note: The returned pointer needs to be freed using kfree(). * * Return: The number of found Speaker Allocation Blocks or negative number on * error.
*/ int drm_edid_to_speaker_allocation(conststruct edid *edid, u8 **sadb)
{ struct drm_edid drm_edid;
/** * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay * @connector: connector associated with the HDMI/DP sink * @mode: the display mode * * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if * the sink doesn't support audio or video.
*/ int drm_av_sync_delay(struct drm_connector *connector, conststruct drm_display_mode *mode)
{ int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE); int a, v;
if (!connector->latency_present[0]) return0; if (!connector->latency_present[1])
i = 0;
a = connector->audio_latency[i];
v = connector->video_latency[i];
/* * HDMI/DP sink doesn't support audio or video?
*/ if (a == 255 || v == 255) return0;
/* * Convert raw EDID values to millisecond. * Treat unknown latency as 0ms.
*/ if (a)
a = min(2 * (a - 1), 500); if (v)
v = min(2 * (v - 1), 500);
return max(v - a, 0);
}
EXPORT_SYMBOL(drm_av_sync_delay);
/* * Because HDMI identifier is in Vendor Specific Block, * search it from all data blocks of CEA extension.
*/
cea_db_iter_edid_begin(drm_edid, &iter);
cea_db_iter_for_each(db, &iter) { if (cea_db_is_hdmi_vsdb(db)) {
hdmi = true; break;
}
}
cea_db_iter_end(&iter);
return hdmi;
}
/** * drm_detect_hdmi_monitor - detect whether monitor is HDMI * @edid: monitor EDID information * * Parse the CEA extension according to CEA-861-B. * * Drivers that have added the modes parsed from EDID to drm_display_info * should use &drm_display_info.is_hdmi instead of calling this function. * * Return: True if the monitor is HDMI, false if not or unknown.
*/ bool drm_detect_hdmi_monitor(conststruct edid *edid)
{ struct drm_edid drm_edid;
if (has_audio) {
DRM_DEBUG_KMS("Monitor has basic audio support\n"); goto end;
}
cea_db_iter_edid_begin(drm_edid, &iter);
cea_db_iter_for_each(db, &iter) { if (cea_db_tag(db) == CTA_DB_AUDIO) { const u8 *data = cea_db_data(db); int i;
for (i = 0; i < cea_db_payload_len(db); i += 3)
DRM_DEBUG_KMS("CEA audio format %d\n",
(data[i] >> 3) & 0xf);
has_audio = true; break;
}
}
cea_db_iter_end(&iter);
end: return has_audio;
}
/** * drm_detect_monitor_audio - check monitor audio capability * @edid: EDID block to scan * * Monitor should have CEA extension block. * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic * audio' only. If there is any audio extension block and supported * audio format, assume at least 'basic audio' support, even if 'basic * audio' is not defined in EDID. * * Return: True if the monitor supports audio, false otherwise.
*/ bool drm_detect_monitor_audio(conststruct edid *edid)
{ struct drm_edid drm_edid;
/** * drm_default_rgb_quant_range - default RGB quantization range * @mode: display mode * * Determine the default RGB quantization range for the mode, * as specified in CEA-861. * * Return: The default RGB quantization range for the mode
*/ enum hdmi_quantization_range
drm_default_rgb_quant_range(conststruct drm_display_mode *mode)
{ /* All CEA modes other than VIC 1 use limited quantization range. */ return drm_match_cea_mode(mode) > 1 ?
HDMI_QUANTIZATION_RANGE_LIMITED :
HDMI_QUANTIZATION_RANGE_FULL;
}
EXPORT_SYMBOL(drm_default_rgb_quant_range);
/* CTA-861 Video Data Block (CTA VDB) */ staticvoid parse_cta_vdb(struct drm_connector *connector, conststruct cea_db *db)
{ struct drm_display_info *info = &connector->display_info; int i, vic_index, len = cea_db_payload_len(db); const u8 *svds = cea_db_data(db);
u8 *vics;
if (!len) return;
/* Gracefully handle multiple VDBs, however unlikely that is */
vics = krealloc(info->vics, info->vics_len + len, GFP_KERNEL); if (!vics) return;
for (i = 0; i < len; i++) {
u8 vic = svd_to_vic(svds[i]);
if (!drm_valid_cea_vic(vic))
vic = 0;
info->vics[vic_index++] = vic;
}
}
/* * Update y420_cmdb_modes based on previously parsed CTA VDB and Y420CMDB. * * Translate the y420cmdb_map based on VIC indexes to y420_cmdb_modes indexed * using the VICs themselves.
*/ staticvoid update_cta_y420cmdb(struct drm_connector *connector, u64 y420cmdb_map)
{ struct drm_display_info *info = &connector->display_info; struct drm_hdmi_info *hdmi = &info->hdmi; int i, len = min_t(int, info->vics_len, BITS_PER_TYPE(y420cmdb_map));
for (i = 0; i < len; i++) {
u8 vic = info->vics[i];
if (hf_scds[6] & 0x80) {
hdmi->scdc.supported = true; if (hf_scds[6] & 0x40)
hdmi->scdc.read_request = true;
}
/* * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz. * And as per the spec, three factors confirm this: * * Availability of a HF-VSDB block in EDID (check) * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check) * * SCDC support available (let's check) * Lets check it out.
*/
if (hf_scds[5]) { struct drm_scdc *scdc = &hdmi->scdc;
/* max clock is 5000 KHz times block value */
max_tmds_clock = hf_scds[5] * 5000;
if (max_tmds_clock > 340000) {
info->max_tmds_clock = max_tmds_clock;
}
if (scdc->supported) {
scdc->scrambling.supported = true;
/* Few sinks support scrambling for clocks < 340M */ if ((hf_scds[6] & 0x8))
scdc->scrambling.low_rates = true;
}
}
if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
dc_bpc = 10;
info->edid_hdmi_rgb444_dc_modes |= DRM_EDID_HDMI_DC_30;
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink does deep color 30.\n",
connector->base.id, connector->name);
}
if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
dc_bpc = 12;
info->edid_hdmi_rgb444_dc_modes |= DRM_EDID_HDMI_DC_36;
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink does deep color 36.\n",
connector->base.id, connector->name);
}
if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
dc_bpc = 16;
info->edid_hdmi_rgb444_dc_modes |= DRM_EDID_HDMI_DC_48;
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink does deep color 48.\n",
connector->base.id, connector->name);
}
if (dc_bpc == 0) {
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] No deep color support on this HDMI sink.\n",
connector->base.id, connector->name); return;
}
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] Assigning HDMI sink color depth as %d bpc.\n",
connector->base.id, connector->name, dc_bpc);
info->bpc = dc_bpc;
/* YCRCB444 is optional according to spec. */ if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
info->edid_hdmi_ycbcr444_dc_modes = info->edid_hdmi_rgb444_dc_modes;
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink does YCRCB444 in deep color.\n",
connector->base.id, connector->name);
}
/* * Spec says that if any deep color mode is supported at all, * then deep color 36 bit must be supported.
*/ if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink should do DC_36, but does not!\n",
connector->base.id, connector->name);
}
}
if (len >= 6)
info->dvi_dual = db[6] & 1; if (len >= 7)
info->max_tmds_clock = db[7] * 5000;
/* * Try to infer whether the sink supports HDMI infoframes. * * HDMI infoframe support was first added in HDMI 1.4. Assume the sink * supports infoframes if HDMI_Video_present is set.
*/ if (len >= 8 && db[8] & BIT(5))
info->has_hdmi_infoframe = true;
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI: DVI dual %d, max TMDS clock %d kHz\n",
connector->base.id, connector->name,
info->dvi_dual, info->max_tmds_clock);
drm_edid_iter_begin(drm_edid, &edid_iter);
drm_edid_iter_for_each(edid_ext, &edid_iter) { if (edid_ext[0] != CEA_EXT) continue;
if (!info->cea_rev)
info->cea_rev = edid_ext[1];
if (info->cea_rev != edid_ext[1])
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] CEA extension version mismatch %u != %u\n",
connector->base.id, connector->name,
info->cea_rev, edid_ext[1]);
/* The existence of a CTA extension should imply RGB support */
info->color_formats = DRM_COLOR_FORMAT_RGB444; if (edid_ext[3] & EDID_CEA_YCRCB444)
info->color_formats |= DRM_COLOR_FORMAT_YCBCR444; if (edid_ext[3] & EDID_CEA_YCRCB422)
info->color_formats |= DRM_COLOR_FORMAT_YCBCR422; if (edid_ext[3] & EDID_BASIC_AUDIO)
info->has_audio = true;
if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return;
/* * These limits are used to determine the VRR refresh * rate range. Only the "range limits only" variant * of the range descriptor seems to guarantee that * any and all timings are accepted by the sink, as * opposed to just timings conforming to the indicated * formula (GTF/GTF2/CVT). Thus other variants of the * range descriptor are not accepted here.
*/ if (range->flags != DRM_EDID_RANGE_LIMITS_ONLY_FLAG) return;
/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset * all of the values which would have been set from EDID
*/ staticvoid drm_reset_display_info(struct drm_connector *connector)
{ struct drm_display_info *info = &connector->display_info;
/* * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3? * * For such displays, the DFP spec 1.0, section 3.10 "EDID support" * tells us to assume 8 bpc color depth if the EDID doesn't have * extensions which tell otherwise.
*/ if (info->bpc == 0 && edid->revision == 3 &&
edid->input & DRM_EDID_DIGITAL_DFP_1_X) {
info->bpc = 8;
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] Assigning DFP sink color depth as %d bpc.\n",
connector->base.id, connector->name, info->bpc);
}
/* Only defined for 1.4 with digital displays */ if (edid->revision < 4) goto out;
switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) { case DRM_EDID_DIGITAL_DEPTH_6:
info->bpc = 6; break; case DRM_EDID_DIGITAL_DEPTH_8:
info->bpc = 8; break; case DRM_EDID_DIGITAL_DEPTH_10:
info->bpc = 10; break; case DRM_EDID_DIGITAL_DEPTH_12:
info->bpc = 12; break; case DRM_EDID_DIGITAL_DEPTH_14:
info->bpc = 14; break; case DRM_EDID_DIGITAL_DEPTH_16:
info->bpc = 16; break; case DRM_EDID_DIGITAL_DEPTH_UNDEF: default:
info->bpc = 0; break;
}
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
connector->base.id, connector->name, info->bpc);
if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
info->color_formats |= DRM_COLOR_FORMAT_YCBCR444; if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
info->color_formats |= DRM_COLOR_FORMAT_YCBCR422;
/* TODO: support RB-v2 & RB-v3 */ if (timing_formula > 1) return NULL;
/* TODO: support video-optimized refresh rate */ if (timings->flags & (1 << 4))
drm_dbg_kms(dev, "Fractional vrefresh is not implemented, proceeding with non-video-optimized refresh rate");
ret = drm_connector_set_tile_property(connector); if (ret) {
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Tile property update failed (%d)\n",
connector->base.id, connector->name, ret); goto out;
}
out: return ret;
}
/* For sysfs edid show implementation */
ssize_t drm_edid_connector_property_show(struct drm_connector *connector, char *buf, loff_t off, size_t count)
{ constvoid *edid;
size_t size;
ssize_t ret = 0;
mutex_lock(&connector->dev->mode_config.mutex);
if (!connector->edid_blob_ptr) goto unlock;
edid = connector->edid_blob_ptr->data;
size = connector->edid_blob_ptr->length; if (!edid) goto unlock;
if (off >= size) goto unlock;
if (off + count > size)
count = size - off;
memcpy(buf, edid + off, count);
ret = count;
unlock:
mutex_unlock(&connector->dev->mode_config.mutex);
return ret;
}
/** * drm_edid_connector_update - Update connector information from EDID * @connector: Connector * @drm_edid: EDID * * Update the connector display info, ELD, HDR metadata, relevant properties, * etc. from the passed in EDID. * * If EDID is NULL, reset the information. * * Must be called before calling drm_edid_connector_add_modes(). * * Return: 0 on success, negative error on errors.
*/ int drm_edid_connector_update(struct drm_connector *connector, conststruct drm_edid *drm_edid)
{
update_display_info(connector, drm_edid);
/** * drm_edid_connector_add_modes - Update probed modes from the EDID property * @connector: Connector * * Add the modes from the previously updated EDID property to the connector * probed modes list. * * drm_edid_connector_update() must have been called before this to update the * EDID property. * * Return: The number of modes added, or 0 if we couldn't find any.
*/ int drm_edid_connector_add_modes(struct drm_connector *connector)
{ conststruct drm_edid *drm_edid = NULL; int count;
if (connector->edid_blob_ptr)
drm_edid = drm_edid_alloc(connector->edid_blob_ptr->data,
connector->edid_blob_ptr->length);
/** * drm_connector_update_edid_property - update the edid property of a connector * @connector: drm connector * @edid: new value of the edid property * * This function creates a new blob modeset object and assigns its id to the * connector's edid property. * Since we also parse tile information from EDID's displayID block, we also * set the connector's tile property here. See drm_connector_set_tile_property() * for more details. * * This function is deprecated. Use drm_edid_connector_update() instead. * * Returns: * Zero on success, negative errno on failure.
*/ int drm_connector_update_edid_property(struct drm_connector *connector, conststruct edid *edid)
{ struct drm_edid drm_edid;
/** * drm_add_edid_modes - add modes from EDID data, if available * @connector: connector we're probing * @edid: EDID data * * Add the specified modes to the connector's mode list. Also fills out the * &drm_display_info structure and ELD in @connector with any information which * can be derived from the edid. * * This function is deprecated. Use drm_edid_connector_add_modes() instead. * * Return: The number of modes added or 0 if we couldn't find any.
*/ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
{ struct drm_edid _drm_edid; conststruct drm_edid *drm_edid;
/** * drm_add_modes_noedid - add modes for the connectors without EDID * @connector: connector we're probing * @hdisplay: the horizontal display limit * @vdisplay: the vertical display limit * * Add the specified modes to the connector's mode list. Only when the * hdisplay/vdisplay is not beyond the given limit, it will be added. * * Return: The number of modes added or 0 if we couldn't find any.
*/ int drm_add_modes_noedid(struct drm_connector *connector, unsignedint hdisplay, unsignedint vdisplay)
{ int i, count = ARRAY_SIZE(drm_dmt_modes), num_modes = 0; struct drm_display_mode *mode; struct drm_device *dev = connector->dev;
for (i = 0; i < count; i++) { conststruct drm_display_mode *ptr = &drm_dmt_modes[i];
if (hdisplay && vdisplay) { /* * Only when two are valid, they will be used to check * whether the mode should be added to the mode list of * the connector.
*/ if (ptr->hdisplay > hdisplay ||
ptr->vdisplay > vdisplay) continue;
} if (drm_mode_vrefresh(ptr) > 61) continue;
mode = drm_mode_duplicate(dev, ptr); if (mode) {
drm_mode_probed_add(connector, mode);
num_modes++;
}
} return num_modes;
}
EXPORT_SYMBOL(drm_add_modes_noedid);
staticbool is_hdmi2_sink(conststruct drm_connector *connector)
{ /* * FIXME: sil-sii8620 doesn't have a connector around when * we need one, so we have to be prepared for a NULL connector.
*/ if (!connector) returntrue;
/* No HDMI VIC when signalling 3D video format */ if (mode->flags & DRM_MODE_FLAG_3D_MASK) return0;
return drm_match_hdmi_mode(mode);
}
static u8 drm_mode_cea_vic(conststruct drm_connector *connector, conststruct drm_display_mode *mode)
{ /* * HDMI spec says if a mode is found in HDMI 1.4b 4K modes * we should send its VIC in vendor infoframes, else send the * VIC in AVI infoframes. Lets check if this mode is present in * HDMI 1.4b 4K modes
*/ if (drm_mode_hdmi_vic(connector, mode)) return0;
return drm_match_cea_mode(mode);
}
/* * Avoid sending VICs defined in HDMI 2.0 in AVI infoframes to sinks that * conform to HDMI 1.4. * * HDMI 1.4 (CTA-861-D) VIC range: [1..64] * HDMI 2.0 (CTA-861-F) VIC range: [1..107] * * If the sink lists the VIC in CTA VDB, assume it's fine, regardless of HDMI * version.
*/ static u8 vic_for_avi_infoframe(conststruct drm_connector *connector, u8 vic)
{ if (!is_hdmi2_sink(connector) && vic > 64 &&
!cta_vdb_has_vic(connector, vic)) return0;
return vic;
}
/** * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with * data from a DRM display mode * @frame: HDMI AVI infoframe * @connector: the connector * @mode: DRM display mode * * Return: 0 on success or a negative error code on failure.
*/ int
drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, conststruct drm_connector *connector, conststruct drm_display_mode *mode)
{ enum hdmi_picture_aspect picture_aspect;
u8 vic, hdmi_vic;
if (!frame || !mode) return -EINVAL;
hdmi_avi_infoframe_init(frame);
if (mode->flags & DRM_MODE_FLAG_DBLCLK)
frame->pixel_repeat = 1;
/* * As some drivers don't support atomic, we can't use connector state. * So just initialize the frame with default values, just the same way * as it's done with other properties here.
*/
frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
frame->itc = 0;
/* * Populate picture aspect ratio from either * user input (if specified) or from the CEA/HDMI mode lists.
*/
picture_aspect = mode->picture_aspect_ratio; if (picture_aspect == HDMI_PICTURE_ASPECT_NONE) { if (vic)
picture_aspect = drm_get_cea_aspect_ratio(vic); elseif (hdmi_vic)
picture_aspect = drm_get_hdmi_aspect_ratio(hdmi_vic);
}
/* * The infoframe can't convey anything but none, 4:3 * and 16:9, so if the user has asked for anything else * we can only satisfy it by specifying the right VIC.
*/ if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) { if (vic) { if (picture_aspect != drm_get_cea_aspect_ratio(vic)) return -EINVAL;
} elseif (hdmi_vic) { if (picture_aspect != drm_get_hdmi_aspect_ratio(hdmi_vic)) return -EINVAL;
} else { return -EINVAL;
}
/** * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe * quantization range information * @frame: HDMI AVI infoframe * @connector: the connector * @mode: DRM display mode * @rgb_quant_range: RGB quantization range (Q)
*/ void
drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame, conststruct drm_connector *connector, conststruct drm_display_mode *mode, enum hdmi_quantization_range rgb_quant_range)
{ conststruct drm_display_info *info = &connector->display_info;
/* * CEA-861: * "A Source shall not send a non-zero Q value that does not correspond * to the default RGB Quantization Range for the transmitted Picture * unless the Sink indicates support for the Q bit in a Video * Capabilities Data Block." * * HDMI 2.0 recommends sending non-zero Q when it does match the * default RGB quantization range for the mode, even when QS=0.
*/ if (info->rgb_quant_range_selectable ||
rgb_quant_range == drm_default_rgb_quant_range(mode))
frame->quantization_range = rgb_quant_range; else
frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
/* * CEA-861-F: * "When transmitting any RGB colorimetry, the Source should set the * YQ-field to match the RGB Quantization Range being transmitted * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB, * set YQ=1) and the Sink shall ignore the YQ-field." * * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused * by non-zero YQ when receiving RGB. There doesn't seem to be any * good way to tell which version of CEA-861 the sink supports, so * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based * on CEA-861-F.
*/ if (!is_hdmi2_sink(connector) ||
rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
frame->ycc_quantization_range =
HDMI_YCC_QUANTIZATION_RANGE_LIMITED; else
frame->ycc_quantization_range =
HDMI_YCC_QUANTIZATION_RANGE_FULL;
}
EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
switch (layout) { case DRM_MODE_FLAG_3D_FRAME_PACKING: return HDMI_3D_STRUCTURE_FRAME_PACKING; case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE: return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE; case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE: return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE; case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL: return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL; case DRM_MODE_FLAG_3D_L_DEPTH: return HDMI_3D_STRUCTURE_L_DEPTH; case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH: return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH; case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM; case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF; default: return HDMI_3D_STRUCTURE_INVALID;
}
}
/** * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with * data from a DRM display mode * @frame: HDMI vendor infoframe * @connector: the connector * @mode: DRM display mode * * Note that there's is a need to send HDMI vendor infoframes only when using a * 4k or stereoscopic 3D mode. So when giving any other mode as input this * function will return -EINVAL, error that can be safely ignored. * * Return: 0 on success or a negative error code on failure.
*/ int
drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame, conststruct drm_connector *connector, conststruct drm_display_mode *mode)
{ /* * FIXME: sil-sii8620 doesn't have a connector around when * we need one, so we have to be prepared for a NULL connector.
*/ bool has_hdmi_infoframe = connector ?
connector->display_info.has_hdmi_infoframe : false; int err;
if (!frame || !mode) return -EINVAL;
if (!has_hdmi_infoframe) return -EINVAL;
err = hdmi_vendor_infoframe_init(frame); if (err < 0) return err;
/* * Even if it's not absolutely necessary to send the infoframe * (ie.vic==0 and s3d_struct==0) we will still send it if we * know that the sink can handle it. This is based on a * suggestion in HDMI 2.0 Appendix F. Apparently some sinks * have trouble realizing that they should switch from 3D to 2D * mode if the source simply stops sending the infoframe when * it wants to switch from 3D to 2D.
*/
frame->vic = drm_mode_hdmi_vic(connector, mode);
frame->s3d_struct = s3d_structure_from_display_mode(mode);
drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] tile cap 0x%x, size %dx%d, num tiles %dx%d, location %dx%d, vend %c%c%c",
connector->base.id, connector->name,
tile->tile_cap,
connector->tile_h_size, connector->tile_v_size,
connector->num_h_tile, connector->num_v_tile,
connector->tile_h_loc, connector->tile_v_loc,
tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
tg = drm_mode_get_tile_group(connector->dev, tile->topology_id); if (!tg)
tg = drm_mode_create_tile_group(connector->dev, tile->topology_id); if (!tg) return;
if (connector->tile_group != tg) { /* if we haven't got a pointer,
take the reference, drop ref to old tile group */ if (connector->tile_group)
drm_mode_put_tile_group(connector->dev, connector->tile_group);
connector->tile_group = tg;
} else { /* if same tile group, then release the ref we just took. */
drm_mode_put_tile_group(connector->dev, tg);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.