[4/4] drm/i915: Adding panel filter for VGA
diff mbox

Message ID 1439191571-25847-4-git-send-email-xiong.y.zhang@intel.com
State New
Headers show

Commit Message

Xiong Zhang Aug. 10, 2015, 7:26 a.m. UTC
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com>
---
 drivers/gpu/drm/i915/intel_crt.c | 81 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 4 deletions(-)

Patch
diff mbox

diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
index 521af2c..f8eedfc 100644
--- a/drivers/gpu/drm/i915/intel_crt.c
+++ b/drivers/gpu/drm/i915/intel_crt.c
@@ -288,24 +288,37 @@  intel_crt_mode_valid(struct drm_connector *connector,
 		     struct drm_display_mode *mode)
 {
 	struct drm_device *dev = connector->dev;
+	struct intel_connector *intel_connector = to_intel_connector(connector);
+	struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
+	int max_clock = 0, clock;
 
-	int max_clock = 0;
 	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
 		return MODE_NO_DBLESCAN;
 
-	if (mode->clock < 25000)
+	clock = mode->clock;
+	if (!intel_panel_scale_none(&intel_connector->panel)) {
+		if (mode->hdisplay > fixed_mode->hdisplay)
+			return MODE_PANEL;
+
+		if (mode->vdisplay > fixed_mode->vdisplay)
+			return MODE_PANEL;
+
+		clock = fixed_mode->clock;
+	}
+
+	if (clock < 25000)
 		return MODE_CLOCK_LOW;
 
 	if (IS_GEN2(dev))
 		max_clock = 350000;
 	else
 		max_clock = 400000;
-	if (mode->clock > max_clock)
+	if (clock > max_clock)
 		return MODE_CLOCK_HIGH;
 
 	/* The FDI receiver on LPT only supports 8bpc and only has 2 lanes. */
 	if (HAS_PCH_LPT(dev) &&
-	    (ironlake_get_lanes_required(mode->clock, 270000, 24) > 2))
+	    (ironlake_get_lanes_required(clock, 270000, 24) > 2))
 		return MODE_CLOCK_HIGH;
 
 	return MODE_OK;
@@ -315,6 +328,22 @@  static bool intel_crt_compute_config(struct intel_encoder *encoder,
 				     struct intel_crtc_state *pipe_config)
 {
 	struct drm_device *dev = encoder->base.dev;
+	struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
+	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
+	struct intel_crt *intel_crt = intel_encoder_to_crt(encoder);
+	struct intel_connector *intel_connector = intel_crt->connector;
+
+	if (!intel_panel_scale_none(&intel_connector->panel)) {
+		intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
+				       adjusted_mode);
+
+		if (!HAS_PCH_SPLIT(dev))
+			intel_gmch_panel_fitting(intel_crtc, pipe_config,
+				     intel_connector->panel.fitting_mode);
+		else
+			intel_pch_panel_fitting(intel_crtc, pipe_config,
+				    intel_connector->panel.fitting_mode);
+	}
 
 	if (HAS_PCH_SPLIT(dev))
 		pipe_config->has_pch_encoder = true;
@@ -489,6 +518,7 @@  static struct edid *intel_crt_get_edid(struct drm_connector *connector,
 static int intel_crt_ddc_get_modes(struct drm_connector *connector,
 				struct i2c_adapter *adapter)
 {
+	struct intel_connector *intel_connector = to_intel_connector(connector);
 	struct edid *edid;
 	int ret;
 
@@ -499,6 +529,20 @@  static int intel_crt_ddc_get_modes(struct drm_connector *connector,
 	ret = intel_connector_update_modes(connector, edid);
 	kfree(edid);
 
+	if (ret && intel_connector->panel.fixed_mode == NULL) {
+		struct drm_display_mode *fixed_mode = NULL, *scan;
+
+		list_for_each_entry(scan, &connector->probed_modes, head) {
+			if (scan->type & DRM_MODE_TYPE_PREFERRED)
+				fixed_mode = drm_mode_duplicate(connector->dev,
+								scan);
+		}
+
+		if (fixed_mode)
+			intel_panel_init(&intel_connector->panel,
+					 fixed_mode, NULL);
+	}
+
 	return ret;
 }
 
@@ -768,6 +812,18 @@  static int intel_crt_set_property(struct drm_connector *connector,
 				  struct drm_property *property,
 				  uint64_t value)
 {
+	struct intel_connector *intel_connector = to_intel_connector(connector);
+
+	if (property == connector->dev->mode_config.scaling_mode_property) {
+		if (intel_connector->panel.fitting_mode == value)
+			return 0;
+
+		intel_connector->panel.fitting_mode = value;
+
+		if (connector->encoder && connector->encoder->crtc)
+			intel_crtc_restore_mode(connector->encoder->crtc);
+	}
+
 	return 0;
 }
 
@@ -844,6 +900,21 @@  static const struct dmi_system_id intel_no_crt[] = {
 	{ }
 };
 
+static void
+intel_crt_add_properties(struct drm_connector *connector)
+{
+	struct intel_connector *intel_connector = to_intel_connector(connector);
+
+	/* Each pipe has pannel filter since Ironlake. */
+	if (INTEL_INFO(connector->dev)->gen >= 5) {
+		drm_mode_create_scaling_mode_property(connector->dev);
+		drm_object_attach_property(&connector->base,
+				connector->dev->mode_config.scaling_mode_property,
+				DRM_MODE_SCALE_NONE);
+		intel_connector->panel.fitting_mode = DRM_MODE_SCALE_NONE;
+	}
+}
+
 void intel_crt_init(struct drm_device *dev)
 {
 	struct drm_connector *connector;
@@ -870,6 +941,8 @@  void intel_crt_init(struct drm_device *dev)
 	drm_connector_init(dev, &intel_connector->base,
 			   &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
 
+	intel_crt_add_properties(connector);
+
 	drm_encoder_init(dev, &crt->base.base, &intel_crt_enc_funcs,
 			 DRM_MODE_ENCODER_DAC);