ac697f4
From b03543857fd75876b96e10d4320b775e95041bb7 Mon Sep 17 00:00:00 2001
ac697f4
From: Takashi Iwai <tiwai@suse.de>
ac697f4
Date: Tue, 20 Mar 2012 12:07:05 +0000
ac697f4
Subject: drm/i915: Check VBIOS value for determining LVDS dual channel mode, too
ac697f4
ac697f4
Currently i915 driver checks [PCH_]LVDS register bits to decide
ac697f4
whether to set up the dual-link or the single-link mode.  This relies
ac697f4
implicitly on that BIOS initializes the register properly at boot.
ac697f4
However, BIOS doesn't initialize it always.  When the machine is
ac697f4
booted with the closed lid, BIOS skips the LVDS reg initialization.
ac697f4
This ends up in blank output on a machine with a dual-link LVDS when
ac697f4
you open the lid after the boot.
ac697f4
ac697f4
This patch adds a workaround for that problem by checking the initial
ac697f4
LVDS register value in VBT.
ac697f4
ac697f4
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37742
ac697f4
Tested-By: Paulo Zanoni <paulo.r.zanoni@intel.com>
ac697f4
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
ac697f4
Reviewed-by: Adam Jackson <ajax@redhat.com>
ac697f4
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ac697f4
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
ac697f4
---
ac697f4
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
ac697f4
index b6098b0..4cbed7f 100644
ac697f4
--- a/drivers/gpu/drm/i915/i915_drv.h
ac697f4
+++ b/drivers/gpu/drm/i915/i915_drv.h
ac697f4
@@ -406,6 +406,8 @@ typedef struct drm_i915_private {
ac697f4
 	unsigned int lvds_use_ssc:1;
ac697f4
 	unsigned int display_clock_mode:1;
ac697f4
 	int lvds_ssc_freq;
ac697f4
+	unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
ac697f4
+	unsigned int lvds_val; /* used for checking LVDS channel mode */
ac697f4
 	struct {
ac697f4
 		int rate;
ac697f4
 		int lanes;
ac697f4
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
ac697f4
index 0ae76d6..e4317da 100644
ac697f4
--- a/drivers/gpu/drm/i915/intel_bios.c
ac697f4
+++ b/drivers/gpu/drm/i915/intel_bios.c
ac697f4
@@ -173,6 +173,28 @@ get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
ac697f4
 	return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
ac697f4
 }
ac697f4
 
ac697f4
+/* get lvds_fp_timing entry
ac697f4
+ * this function may return NULL if the corresponding entry is invalid
ac697f4
+ */
ac697f4
+static const struct lvds_fp_timing *
ac697f4
+get_lvds_fp_timing(const struct bdb_header *bdb,
ac697f4
+		   const struct bdb_lvds_lfp_data *data,
ac697f4
+		   const struct bdb_lvds_lfp_data_ptrs *ptrs,
ac697f4
+		   int index)
ac697f4
+{
ac697f4
+	size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
ac697f4
+	u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
ac697f4
+	size_t ofs;
ac697f4
+
ac697f4
+	if (index >= ARRAY_SIZE(ptrs->ptr))
ac697f4
+		return NULL;
ac697f4
+	ofs = ptrs->ptr[index].fp_timing_offset;
ac697f4
+	if (ofs < data_ofs ||
ac697f4
+	    ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
ac697f4
+		return NULL;
ac697f4
+	return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
ac697f4
+}
ac697f4
+
ac697f4
 /* Try to find integrated panel data */
ac697f4
 static void
ac697f4
 parse_lfp_panel_data(struct drm_i915_private *dev_priv,
ac697f4
@@ -182,6 +204,7 @@ parse_lfp_panel_data(struct drm_i915_private *dev_priv,
ac697f4
 	const struct bdb_lvds_lfp_data *lvds_lfp_data;
ac697f4
 	const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
ac697f4
 	const struct lvds_dvo_timing *panel_dvo_timing;
ac697f4
+	const struct lvds_fp_timing *fp_timing;
ac697f4
 	struct drm_display_mode *panel_fixed_mode;
ac697f4
 	int i, downclock;
ac697f4
 
ac697f4
@@ -243,6 +266,19 @@ parse_lfp_panel_data(struct drm_i915_private *dev_priv,
ac697f4
 			      "Normal Clock %dKHz, downclock %dKHz\n",
ac697f4
 			      panel_fixed_mode->clock, 10*downclock);
ac697f4
 	}
ac697f4
+
ac697f4
+	fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
ac697f4
+				       lvds_lfp_data_ptrs,
ac697f4
+				       lvds_options->panel_type);
ac697f4
+	if (fp_timing) {
ac697f4
+		/* check the resolution, just to be sure */
ac697f4
+		if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
ac697f4
+		    fp_timing->y_res == panel_fixed_mode->vdisplay) {
ac697f4
+			dev_priv->bios_lvds_val = fp_timing->lvds_reg_val;
ac697f4
+			DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
ac697f4
+				      dev_priv->bios_lvds_val);
ac697f4
+		}
ac697f4
+	}
ac697f4
 }
ac697f4
 
ac697f4
 /* Try to find sdvo panel data */
ac697f4
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
ac697f4
index 683002fb..a76ac2e 100644
ac697f4
--- a/drivers/gpu/drm/i915/intel_display.c
ac697f4
+++ b/drivers/gpu/drm/i915/intel_display.c
ac697f4
@@ -360,6 +360,27 @@ static const intel_limit_t intel_limits_ironlake_display_port = {
ac697f4
 	.find_pll = intel_find_pll_ironlake_dp,
ac697f4
 };
ac697f4
 
ac697f4
+static bool is_dual_link_lvds(struct drm_i915_private *dev_priv,
ac697f4
+			      unsigned int reg)
ac697f4
+{
ac697f4
+	unsigned int val;
ac697f4
+
ac697f4
+	if (dev_priv->lvds_val)
ac697f4
+		val = dev_priv->lvds_val;
ac697f4
+	else {
ac697f4
+		/* BIOS should set the proper LVDS register value at boot, but
ac697f4
+		 * in reality, it doesn't set the value when the lid is closed;
ac697f4
+		 * we need to check "the value to be set" in VBT when LVDS
ac697f4
+		 * register is uninitialized.
ac697f4
+		 */
ac697f4
+		val = I915_READ(reg);
ac697f4
+		if (!(val & ~LVDS_DETECTED))
ac697f4
+			val = dev_priv->bios_lvds_val;
ac697f4
+		dev_priv->lvds_val = val;
ac697f4
+	}
ac697f4
+	return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
ac697f4
+}
ac697f4
+
ac697f4
 static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
ac697f4
 						int refclk)
ac697f4
 {
ac697f4
@@ -368,8 +389,7 @@ static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
ac697f4
 	const intel_limit_t *limit;
ac697f4
 
ac697f4
 	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
ac697f4
-		if ((I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) ==
ac697f4
-		    LVDS_CLKB_POWER_UP) {
ac697f4
+		if (is_dual_link_lvds(dev_priv, PCH_LVDS)) {
ac697f4
 			/* LVDS dual channel */
ac697f4
 			if (refclk == 100000)
ac697f4
 				limit = &intel_limits_ironlake_dual_lvds_100m;
ac697f4
@@ -397,8 +417,7 @@ static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
ac697f4
 	const intel_limit_t *limit;
ac697f4
 
ac697f4
 	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
ac697f4
-		if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
ac697f4
-		    LVDS_CLKB_POWER_UP)
ac697f4
+		if (is_dual_link_lvds(dev_priv, LVDS))
ac697f4
 			/* LVDS with dual channel */
ac697f4
 			limit = &intel_limits_g4x_dual_channel_lvds;
ac697f4
 		else
ac697f4
@@ -536,8 +555,7 @@ intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
ac697f4
 		 * reliably set up different single/dual channel state, if we
ac697f4
 		 * even can.
ac697f4
 		 */
ac697f4
-		if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
ac697f4
-		    LVDS_CLKB_POWER_UP)
ac697f4
+		if (is_dual_link_lvds(dev_priv, LVDS))
ac697f4
 			clock.p2 = limit->p2.p2_fast;
ac697f4
 		else
ac697f4
 			clock.p2 = limit->p2.p2_slow;
ac697f4
--
ac697f4
cgit v0.9.0.2-2-gbebe