/* * Copyright (C) 2008 Maarten Maathuis. * All Rights Reserved. * * 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, sublicense, 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 NONINFRINGEMENT. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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. *
*/
/* Use preferred mode if there is one.. */ if (mode->type & DRM_MODE_TYPE_PREFERRED) {
NV_DEBUG(drm, "native mode from preferred\n"); return drm_mode_duplicate(dev, mode);
}
/* Otherwise, take the resolution with the largest width, then * height, then vertical refresh
*/ if (mode->hdisplay < high_w) continue;
if (mode->hdisplay == high_w && mode->vdisplay < high_h) continue;
if (property == dev->mode_config.scaling_mode_property) { switch (val) { case DRM_MODE_SCALE_NONE: /* We allow 'None' for EDID modes, even on a fixed * panel (some exist with support for lower refresh * rates, which people might want to use for power- * saving purposes). * * Non-EDID modes will force the use of GPU scaling * to the native mode regardless of this setting.
*/ switch (connector->connector_type) { case DRM_MODE_CONNECTOR_LVDS: case DRM_MODE_CONNECTOR_eDP: /* ... except prior to G80, where the code * doesn't support such things.
*/ if (disp->disp.object.oclass < NV50_DISP) return -EINVAL; break; default: break;
} break; case DRM_MODE_SCALE_FULLSCREEN: case DRM_MODE_SCALE_CENTER: case DRM_MODE_SCALE_ASPECT: break; default: return -EINVAL;
}
MODULE_PARM_DESC(hdmimhz, "Force a maximum HDMI pixel clock (in MHz)"); int nouveau_hdmimhz = 0;
module_param_named(hdmimhz, nouveau_hdmimhz, int, 0400);
if (nvif_object_constructed(&nv_encoder->outp.object)) { enum nvif_outp_detect_status status;
if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
ret = nouveau_dp_detect(conn, nv_encoder); if (ret == NOUVEAU_DP_MST) return NULL; if (ret != NOUVEAU_DP_SST) continue;
return nv_encoder;
} else {
status = nvif_outp_detect(&nv_encoder->outp); switch (status) { case PRESENT: return nv_encoder; case NOT_PRESENT: continue; case UNKNOWN: break; default:
WARN_ON(1); break;
}
}
}
if (switcheroo_ddc)
vga_switcheroo_lock_ddc(pdev); if (nvkm_probe_i2c(nv_encoder->i2c, 0x50))
found = nv_encoder; if (switcheroo_ddc)
vga_switcheroo_unlock_ddc(pdev);
/* Outputs are only polled while runtime active, so resuming the * device here is unnecessary (and would deadlock upon runtime suspend * because it waits for polling to finish). We do however, want to * prevent the autosuspend timer from elapsing during this operation * if possible.
*/ if (drm_kms_helper_is_poll_worker()) {
pm_runtime_get_noresume(dev->dev);
} else {
ret = pm_runtime_get_sync(dev->dev); if (ret < 0 && ret != -EACCES) {
pm_runtime_put_autosuspend(dev->dev);
nouveau_connector_set_edid(nv_connector, NULL); return conn_status;
}
}
if (nv_encoder->i2c) { if ((vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC) &&
nv_connector->type == DCB_CONNECTOR_LVDS)
new_edid = drm_get_edid_switcheroo(connector, nv_encoder->i2c); else
new_edid = drm_get_edid(connector, nv_encoder->i2c);
} else {
ret = nvif_outp_edid_get(&nv_encoder->outp, (u8 **)&new_edid); if (ret < 0) return connector_status_disconnected;
}
nouveau_connector_set_edid(nv_connector, new_edid); if (!nv_connector->edid) {
NV_ERROR(drm, "DDC responded, but no EDID for %s\n",
connector->name); goto detect_analog;
}
/* Override encoder type for DVI-I based on whether EDID * says the display is digital or analog, both use the * same i2c channel so the value returned from ddc_detect * isn't necessarily correct.
*/
nv_partner = NULL; if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS)
nv_partner = find_encoder(connector, DCB_OUTPUT_ANALOG); if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
nv_partner = find_encoder(connector, DCB_OUTPUT_TMDS);
if (nv_partner && ((nv_encoder->dcb->type == DCB_OUTPUT_ANALOG &&
nv_partner->dcb->type == DCB_OUTPUT_TMDS) ||
(nv_encoder->dcb->type == DCB_OUTPUT_TMDS &&
nv_partner->dcb->type == DCB_OUTPUT_ANALOG))) { if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL)
type = DCB_OUTPUT_TMDS; else
type = DCB_OUTPUT_ANALOG;
nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS); if (!nv_encoder) goto out;
/* Try retrieving EDID via DDC */ if (!drm->vbios.fp_no_ddc) {
status = nouveau_connector_detect(connector, force); if (status == connector_status_connected) {
edid = nv_connector->edid; goto out;
}
}
/* On some laptops (Sony, i'm looking at you) there appears to * be no direct way of accessing the panel's EDID. The only * option available to us appears to be to ask ACPI for help.. * * It's important this check's before trying straps, one of the * said manufacturer's laptops are configured in such a way * the nouveau decides an entry in the VBIOS FP mode table is * valid - it's not (rh#613284)
*/ if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
edid = nouveau_acpi_edid(dev, connector); if (edid) {
status = connector_status_connected; goto out;
}
}
/* If no EDID found above, and the VBIOS indicates a hardcoded * modeline is avalilable for the panel, set it as the panel's * native mode and exit.
*/ if (nouveau_bios_fp_mode(dev, NULL) && (drm->vbios.fp_no_ddc ||
nv_encoder->dcb->lvdsconf.use_straps_for_mode)) {
status = connector_status_connected; goto out;
}
/* Still nothing, some VBIOS images have a hardcoded EDID block * stored for the panel stored in them.
*/ if (!drm->vbios.fp_no_ddc) {
edid = (struct edid *)nouveau_bios_embedded_edid(dev); if (edid) {
edid = kmemdup(edid, EDID_LENGTH, GFP_KERNEL); if (edid)
status = connector_status_connected;
}
}
out: #ifdefined(CONFIG_ACPI_BUTTON) || \
(defined(CONFIG_ACPI_BUTTON_MODULE) && defined(MODULE)) if (status == connector_status_connected &&
!nouveau_ignorelid && !acpi_lid_open())
status = connector_status_unknown; #endif
nouveau_connector_set_edid(nv_connector, edid); if (nv_encoder)
nouveau_connector_set_encoder(connector, nv_encoder); return status;
}
if (nv_connector->type == DCB_CONNECTOR_DVI_I) { if (connector->force == DRM_FORCE_ON_DIGITAL)
type = DCB_OUTPUT_TMDS; else
type = DCB_OUTPUT_ANALOG;
} else
type = DCB_OUTPUT_ANY;
nv_encoder = find_encoder(connector, type); if (!nv_encoder) {
NV_ERROR(drm, "can't find encoder to force %s on!\n",
connector->name); return;
}
/* if the edid is feeling nice enough to provide this info, use it */ if (nv_connector->edid && connector->display_info.bpc) return;
/* EDID 1.4 is *supposed* to be supported on eDP, but, Apple... */ if (nv_connector->type == DCB_CONNECTOR_eDP) {
connector->display_info.bpc = 6; return;
}
/* we're out of options unless we're LVDS, default to 8bpc */ if (nv_encoder->dcb->type != DCB_OUTPUT_LVDS) {
connector->display_info.bpc = 8; return;
}
connector->display_info.bpc = 6;
/* LVDS: panel straps */ if (bios->fp_no_ddc) { if (bios->fp.if_is_24bit)
connector->display_info.bpc = 8; return;
}
/* LVDS: DDC panel, need to first determine the number of links to * know which if_is_24bit flag to check...
*/ if (nv_connector->edid &&
nv_connector->type == DCB_CONNECTOR_LVDS_SPWG)
duallink = ((u8 *)nv_connector->edid)[121] == 2; else
duallink = mode->clock >= bios->fp.duallink_transition_clk;
/* destroy the native mode, the attached monitor could have changed.
*/ if (nv_connector->native_mode) {
drm_mode_destroy(dev, nv_connector->native_mode);
nv_connector->native_mode = NULL;
}
if (nv_connector->edid)
ret = drm_add_edid_modes(connector, nv_connector->edid); else if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS &&
(nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
drm->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) { struct drm_display_mode mode;
/* Determine display colour depth for everything except LVDS now, * DP requires this before mode_valid() is called.
*/ if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
nouveau_connector_detect_depth(connector);
/* Find the native mode if this is a digital panel, if we didn't * find any modes through DDC previously add the native mode to * the list of modes.
*/ if (!nv_connector->native_mode)
nv_connector->native_mode = nouveau_conn_native_mode(connector); if (ret == 0 && nv_connector->native_mode) { struct drm_display_mode *mode;
mode = drm_mode_duplicate(dev, nv_connector->native_mode); if (!mode) return 0;
drm_mode_probed_add(connector, mode);
ret = 1;
}
/* Determine LVDS colour depth, must happen after determining * "native" mode as some VBIOS tables require us to use the * pixel clock as part of the lookup...
*/ if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS && nv_connector->native_mode)
nouveau_connector_detect_depth(connector);
if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
ret = get_encoder_i2c_funcs(encoder)->get_modes(encoder, connector);
if (nv_connector->type == DCB_CONNECTOR_LVDS ||
nv_connector->type == DCB_CONNECTOR_LVDS_SPWG ||
nv_connector->type == DCB_CONNECTOR_eDP)
ret += nouveau_connector_scaler_modes_add(connector);
if (nv_connector->base.display_info.is_hdmi) {
info = &nv_connector->base.display_info;
duallink_scale = 1;
}
if (info) { if (nouveau_hdmimhz > 0) return nouveau_hdmimhz * 1000; /* Note: these limits are conservative, some Fermi's * can do 297 MHz. Unclear how this can be determined.
*/ if (drm->client.device.info.chipset >= 0x120) { constint max_tmds_clock =
info->hdmi.scdc.scrambling.supported ?
594000 : 340000; return info->max_tmds_clock ?
min(info->max_tmds_clock, max_tmds_clock) :
max_tmds_clock;
} if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_KEPLER) return 297000; if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_FERMI) return 225000;
}
nv_encoder = find_encoder(&nv_connector->base, DCB_OUTPUT_DP); if (!nv_encoder) return -ENODEV; if (WARN_ON(msg->size > 16)) return -E2BIG;
ret = nvif_outp_dp_aux_xfer(&nv_encoder->outp,
msg->request, &size, msg->address, msg->buffer); if (ret >= 0) {
msg->reply = ret; return size;
}
return ret;
}
staticint
drm_conntype_from_dcb(enum dcb_connector_type dcb)
{ switch (dcb) { case DCB_CONNECTOR_VGA : return DRM_MODE_CONNECTOR_VGA; case DCB_CONNECTOR_TV_0 : case DCB_CONNECTOR_TV_1 : case DCB_CONNECTOR_TV_3 : return DRM_MODE_CONNECTOR_TV; case DCB_CONNECTOR_DMS59_0 : case DCB_CONNECTOR_DMS59_1 : case DCB_CONNECTOR_DVI_I : return DRM_MODE_CONNECTOR_DVII; case DCB_CONNECTOR_DVI_D : return DRM_MODE_CONNECTOR_DVID; case DCB_CONNECTOR_LVDS : case DCB_CONNECTOR_LVDS_SPWG: return DRM_MODE_CONNECTOR_LVDS; case DCB_CONNECTOR_DMS59_DP0: case DCB_CONNECTOR_DMS59_DP1: case DCB_CONNECTOR_DP : case DCB_CONNECTOR_mDP : case DCB_CONNECTOR_USB_C : return DRM_MODE_CONNECTOR_DisplayPort; case DCB_CONNECTOR_eDP : return DRM_MODE_CONNECTOR_eDP; case DCB_CONNECTOR_HDMI_0 : case DCB_CONNECTOR_HDMI_1 : case DCB_CONNECTOR_HDMI_C : return DRM_MODE_CONNECTOR_HDMIA; case DCB_CONNECTOR_WFD : return DRM_MODE_CONNECTOR_VIRTUAL; default: break;
}
if (disp->disp.conn_mask & BIT(nv_connector->index)) {
ret = nvif_conn_ctor(&disp->disp, nv_connector->base.name, nv_connector->index,
&nv_connector->conn); if (ret) {
kfree(nv_connector); return ERR_PTR(ret);
}
switch (nv_connector->conn.info.type) { case NVIF_CONN_VGA : type = DCB_CONNECTOR_VGA; break; case NVIF_CONN_DVI_I : type = DCB_CONNECTOR_DVI_I; break; case NVIF_CONN_DVI_D : type = DCB_CONNECTOR_DVI_D; break; case NVIF_CONN_LVDS : type = DCB_CONNECTOR_LVDS; break; case NVIF_CONN_LVDS_SPWG: type = DCB_CONNECTOR_LVDS_SPWG; break; case NVIF_CONN_DP : type = DCB_CONNECTOR_DP; break; case NVIF_CONN_EDP : type = DCB_CONNECTOR_eDP; break; case NVIF_CONN_HDMI : type = DCB_CONNECTOR_HDMI_0; break; default:
WARN_ON(1); return NULL;
}
if (dcb)
nv_connector->type = dcb[0]; else
nv_connector->type = DCB_CONNECTOR_NONE;
/* attempt to parse vbios connector type and hotplug gpio */ if (nv_connector->type != DCB_CONNECTOR_NONE) { if (drm_conntype_from_dcb(nv_connector->type) ==
DRM_MODE_CONNECTOR_Unknown) {
NV_WARN(drm, "unknown connector type %02x\n",
nv_connector->type);
nv_connector->type = DCB_CONNECTOR_NONE;
}
}
/* no vbios data, or an unknown dcb connector type - attempt to * figure out something suitable ourselves
*/ if (nv_connector->type == DCB_CONNECTOR_NONE &&
!WARN_ON(drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA)) { struct dcb_table *dcbt = &drm->vbios.dcb;
u32 encoders = 0; int i;
for (i = 0; i < dcbt->entries; i++) { if (dcbt->entry[i].connector == nv_connector->index)
encoders |= (1 << dcbt->entry[i].type);
}
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.