drm/i915: Refactor EDID fixed mode search
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 21 Mar 2019 13:24:41 +0000 (15:24 +0200)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Fri, 22 Mar 2019 16:41:39 +0000 (18:41 +0200)
Both LVDS and eDP have the same code to look up the preferred mode
from the connector probed_modes list. Move the code to a common
location.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190321132446.22394-1-ville.syrjala@linux.intel.com
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Jani Nikula <jani.nikula@intel.com>
drivers/gpu/drm/i915/intel_dp.c
drivers/gpu/drm/i915/intel_drv.h
drivers/gpu/drm/i915/intel_lvds.c
drivers/gpu/drm/i915/intel_panel.c

index 7c043e8f6298f3a4f994ae39d626601558fcb6c7..5096e99ffaadcaa3d7a84024cc1f8bab0bee396d 100644 (file)
@@ -7057,7 +7057,6 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
        struct drm_display_mode *fixed_mode = NULL;
        struct drm_display_mode *downclock_mode = NULL;
        bool has_dpcd;
-       struct drm_display_mode *scan;
        enum pipe pipe = INVALID_PIPE;
        intel_wakeref_t wakeref;
        struct edid *edid;
@@ -7110,15 +7109,9 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
        }
        intel_connector->edid = edid;
 
-       /* prefer fixed mode from EDID if available */
-       list_for_each_entry(scan, &connector->probed_modes, head) {
-               if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
-                       fixed_mode = drm_mode_duplicate(dev, scan);
-                       downclock_mode = intel_dp_drrs_init(
-                                               intel_connector, fixed_mode);
-                       break;
-               }
-       }
+       fixed_mode = intel_panel_edid_fixed_mode(intel_connector);
+       if (fixed_mode)
+               downclock_mode = intel_dp_drrs_init(intel_connector, fixed_mode);
 
        /* fallback to VBT if available for eDP */
        if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
index 0ffa083a7af7e7a84e87da30f2b9419c053fbdd1..30cb9f39c7a29f5e3ef872b7a20a5b49967a5042 100644 (file)
@@ -2157,6 +2157,8 @@ extern struct drm_display_mode *intel_find_panel_downclock(
                                struct drm_i915_private *dev_priv,
                                struct drm_display_mode *fixed_mode,
                                struct drm_connector *connector);
+struct drm_display_mode *
+intel_panel_edid_fixed_mode(struct intel_connector *connector);
 
 #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
 int intel_backlight_device_register(struct intel_connector *connector);
index 845792aa0abee89d8cfb8ee7f2947230aaa0bbb7..0686ad1f12df7b40eed696c526319d8feb0cba84 100644 (file)
@@ -810,7 +810,6 @@ void intel_lvds_init(struct drm_i915_private *dev_priv)
        struct intel_connector *intel_connector;
        struct drm_connector *connector;
        struct drm_encoder *encoder;
-       struct drm_display_mode *scan; /* *modes, *bios_mode; */
        struct drm_display_mode *fixed_mode = NULL;
        struct drm_display_mode *downclock_mode = NULL;
        struct edid *edid;
@@ -949,16 +948,9 @@ void intel_lvds_init(struct drm_i915_private *dev_priv)
        }
        intel_connector->edid = edid;
 
-       list_for_each_entry(scan, &connector->probed_modes, head) {
-               if (scan->type & DRM_MODE_TYPE_PREFERRED) {
-                       DRM_DEBUG_KMS("using preferred mode from EDID: ");
-                       drm_mode_debug_printmodeline(scan);
-
-                       fixed_mode = drm_mode_duplicate(dev, scan);
-                       if (fixed_mode)
-                               goto out;
-               }
-       }
+       fixed_mode = intel_panel_edid_fixed_mode(intel_connector);
+       if (fixed_mode)
+               goto out;
 
        /* Failed to get EDID, what about VBT? */
        if (dev_priv->vbt.lfp_lvds_vbt_mode) {
index edd5540639b0e7aca4e0a3d28bcd5c529aa05c05..f42137512010e19a521216700f74cea1a7799dbd 100644 (file)
@@ -99,6 +99,33 @@ intel_find_panel_downclock(struct drm_i915_private *dev_priv,
                return NULL;
 }
 
+struct drm_display_mode *
+intel_panel_edid_fixed_mode(struct intel_connector *connector)
+{
+       struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
+       const struct drm_display_mode *scan;
+
+       /* prefer fixed mode from EDID if available */
+       list_for_each_entry(scan, &connector->base.probed_modes, head) {
+               struct drm_display_mode *fixed_mode;
+
+               if ((scan->type & DRM_MODE_TYPE_PREFERRED) == 0)
+                       continue;
+
+               fixed_mode = drm_mode_duplicate(&dev_priv->drm, scan);
+               if (!fixed_mode)
+                       return NULL;
+
+               DRM_DEBUG_KMS("[CONNECTOR:%d:%s] using preferred mode from EDID: ",
+                             connector->base.base.id, connector->base.name);
+               drm_mode_debug_printmodeline(fixed_mode);
+
+               return fixed_mode;
+       }
+
+       return NULL;
+}
+
 /* adjusted_mode has been preset to be the panel's fixed mode */
 void
 intel_pch_panel_fitting(struct intel_crtc *intel_crtc,