2021-01-25 12:08:18 -08:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/*
|
|
|
|
* Copyright © 2020 Intel Corporation
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "i915_drv.h"
|
|
|
|
#include "intel_display_types.h"
|
|
|
|
#include "intel_vrr.h"
|
|
|
|
|
|
|
|
bool intel_vrr_is_capable(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
struct intel_dp *intel_dp;
|
|
|
|
const struct drm_display_info *info = &connector->display_info;
|
|
|
|
struct drm_i915_private *i915 = to_i915(connector->dev);
|
|
|
|
|
|
|
|
if (connector->connector_type != DRM_MODE_CONNECTOR_eDP &&
|
|
|
|
connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
intel_dp = intel_attached_dp(to_intel_connector(connector));
|
|
|
|
/*
|
2021-01-22 15:26:31 -08:00
|
|
|
* DP Sink is capable of VRR video timings if
|
2021-01-25 12:08:18 -08:00
|
|
|
* Ignore MSA bit is set in DPCD.
|
|
|
|
* EDID monitor range also should be atleast 10 for reasonable
|
2021-01-22 15:26:31 -08:00
|
|
|
* Adaptive Sync or Variable Refresh Rate end user experience.
|
2021-01-25 12:08:18 -08:00
|
|
|
*/
|
|
|
|
return HAS_VRR(i915) &&
|
|
|
|
drm_dp_sink_can_do_video_without_timing_msa(intel_dp->dpcd) &&
|
|
|
|
info->monitor_range.max_vfreq - info->monitor_range.min_vfreq > 10;
|
|
|
|
}
|
2021-01-22 15:26:35 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
intel_vrr_check_modeset(struct intel_atomic_state *state)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct intel_crtc_state *old_crtc_state, *new_crtc_state;
|
|
|
|
struct intel_crtc *crtc;
|
|
|
|
|
|
|
|
for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
|
|
|
|
new_crtc_state, i) {
|
|
|
|
if (new_crtc_state->uapi.vrr_enabled !=
|
|
|
|
old_crtc_state->uapi.vrr_enabled)
|
|
|
|
new_crtc_state->uapi.mode_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
intel_vrr_compute_config(struct intel_crtc_state *crtc_state,
|
|
|
|
struct drm_connector_state *conn_state)
|
|
|
|
{
|
|
|
|
struct intel_connector *connector =
|
|
|
|
to_intel_connector(conn_state->connector);
|
|
|
|
struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
|
|
|
|
const struct drm_display_info *info = &connector->base.display_info;
|
|
|
|
int vmin, vmax;
|
|
|
|
|
|
|
|
if (!intel_vrr_is_capable(&connector->base))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!crtc_state->uapi.vrr_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vmin = DIV_ROUND_UP(adjusted_mode->crtc_clock * 1000,
|
|
|
|
adjusted_mode->crtc_htotal * info->monitor_range.max_vfreq);
|
|
|
|
vmax = adjusted_mode->crtc_clock * 1000 /
|
|
|
|
(adjusted_mode->crtc_htotal * info->monitor_range.min_vfreq);
|
|
|
|
|
|
|
|
vmin = max_t(int, vmin, adjusted_mode->crtc_vtotal);
|
|
|
|
vmax = max_t(int, vmax, adjusted_mode->crtc_vtotal);
|
|
|
|
|
|
|
|
if (vmin >= vmax)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flipline determines the min vblank length the hardware will
|
|
|
|
* generate, and flipline>=vmin+1, hence we reduce vmin by one
|
|
|
|
* to make sure we can get the actual min vblank length.
|
|
|
|
*/
|
|
|
|
crtc_state->vrr.vmin = vmin - 1;
|
|
|
|
crtc_state->vrr.vmax = vmax;
|
|
|
|
crtc_state->vrr.enable = true;
|
|
|
|
|
|
|
|
crtc_state->vrr.flipline = crtc_state->vrr.vmin + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: s/4/framestart_delay+1/ to get consistent
|
|
|
|
* earliest/latest points for register latching regardless
|
|
|
|
* of the framestart_delay used?
|
|
|
|
*
|
|
|
|
* FIXME: this really needs the extra scanline to provide consistent
|
|
|
|
* behaviour for all framestart_delay values. Otherwise with
|
|
|
|
* framestart_delay==3 we will end up extending the min vblank by
|
|
|
|
* one extra line.
|
|
|
|
*/
|
|
|
|
crtc_state->vrr.pipeline_full =
|
|
|
|
min(255, crtc_state->vrr.vmin - adjusted_mode->crtc_vdisplay - 4 - 1);
|
|
|
|
}
|