drm/i915: Reject user modes that don't match fixed mode's refresh rate
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Wed, 29 Sep 2021 18:45:36 +0000 (21:45 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 30 Sep 2021 08:20:40 +0000 (11:20 +0300)
When using a panel with a fixed mode we don't change the refresh
rate of the display. Reject any user requested mode which doesn't
match that fixed refresh rate.

Unfortunately when Xorg sees the scaling_mode property on the
connecor it likes to automagically cook up modes whose refresh
rate is a fair bit off from the fixed refresh rate we use. So
we have to give it some extra latitude so that we don't start to
reject all of it.

v2: sDVO now uses intel_panel_compute_config() too
v3: Add a debug message to inform the user what happened

References: https://gitlab.freedesktop.org/drm/intel/-/issues/2939
References: https://gitlab.freedesktop.org/drm/intel/-/issues/3969
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210929184536.8332-1-ville.syrjala@linux.intel.com
drivers/gpu/drm/i915/display/intel_panel.c

index 77c1ca3..a0c8e43 100644 (file)
@@ -53,6 +53,21 @@ int intel_panel_compute_config(struct intel_connector *connector,
        if (!fixed_mode)
                return 0;
 
+       /*
+        * We don't want to lie too much to the user about the refresh
+        * rate they're going to get. But we have to allow a bit of latitude
+        * for Xorg since it likes to automagically cook up modes with slightly
+        * off refresh rates.
+        */
+       if (abs(drm_mode_vrefresh(adjusted_mode) - drm_mode_vrefresh(fixed_mode)) > 1) {
+               drm_dbg_kms(connector->base.dev,
+                           "[CONNECTOR:%d:%s] Requested mode vrefresh (%d Hz) does not match fixed mode vrefresh (%d Hz)\n",
+                           connector->base.base.id, connector->base.name,
+                           drm_mode_vrefresh(adjusted_mode), drm_mode_vrefresh(fixed_mode));
+
+               return -EINVAL;
+       }
+
        drm_mode_copy(adjusted_mode, fixed_mode);
 
        drm_mode_set_crtcinfo(adjusted_mode, 0);