Subversion Repositories Kolibri OS

Rev

Rev 3120 | Rev 3263 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3120 Rev 3243
Line 49... Line 49...
49
    return (n != 0 && ((n & (n - 1)) == 0));
49
    return (n != 0 && ((n & (n - 1)) == 0));
50
}
50
}
Line 51... Line 51...
51
 
51
 
Line 52... Line -...
52
#define MAX_ERRNO       4095
-
 
53
 
-
 
54
#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
-
 
55
 
-
 
56
static inline long IS_ERR(const void *ptr)
-
 
57
{
-
 
58
    return IS_ERR_VALUE((unsigned long)ptr);
-
 
59
}
-
 
60
 
-
 
61
static inline void *ERR_PTR(long error)
-
 
62
{
-
 
Line 63... Line -...
63
    return (void *) error;
-
 
64
}
-
 
65
 
52
#define MAX_ERRNO       4095
66
 
53
 
67
#define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
54
 
Line 68... Line 55...
68
 
55
 
69
bool intel_pipe_has_type(struct drm_crtc *crtc, int type);
56
bool intel_pipe_has_type(struct drm_crtc *crtc, int type);
70
static void intel_increase_pllclock(struct drm_crtc *crtc);
57
static void intel_increase_pllclock(struct drm_crtc *crtc);
71
//static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
58
static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
Line 101... Line 88...
101
};
88
};
Line 102... Line 89...
102
 
89
 
103
/* FDI */
90
/* FDI */
Line -... Line 91...
-
 
91
#define IRONLAKE_FDI_FREQ       2700000 /* in kHz for mode->clock */
-
 
92
 
-
 
93
int
-
 
94
intel_pch_rawclk(struct drm_device *dev)
-
 
95
{
-
 
96
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
97
 
-
 
98
	WARN_ON(!HAS_PCH_SPLIT(dev));
-
 
99
 
-
 
100
	return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
104
#define IRONLAKE_FDI_FREQ       2700000 /* in kHz for mode->clock */
101
}
105
 
102
 
106
static bool
103
static bool
107
intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
104
intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
108
		    int target, int refclk, intel_clock_t *match_clock,
105
		    int target, int refclk, intel_clock_t *match_clock,
Line 401... Line 398...
401
	.find_pll = intel_vlv_find_best_pll,
398
	.find_pll = intel_vlv_find_best_pll,
402
};
399
};
Line 403... Line 400...
403
 
400
 
404
static const intel_limit_t intel_limits_vlv_hdmi = {
401
static const intel_limit_t intel_limits_vlv_hdmi = {
405
	.dot = { .min = 20000, .max = 165000 },
402
	.dot = { .min = 20000, .max = 165000 },
406
	.vco = { .min = 5994000, .max = 4000000 },
403
	.vco = { .min = 4000000, .max = 5994000},
407
	.n = { .min = 1, .max = 7 },
404
	.n = { .min = 1, .max = 7 },
408
	.m = { .min = 60, .max = 300 }, /* guess */
405
	.m = { .min = 60, .max = 300 }, /* guess */
409
	.m1 = { .min = 2, .max = 3 },
406
	.m1 = { .min = 2, .max = 3 },
410
	.m2 = { .min = 11, .max = 156 },
407
	.m2 = { .min = 11, .max = 156 },
Line 414... Line 411...
414
		.p2_slow = 2, .p2_fast = 20 },
411
		.p2_slow = 2, .p2_fast = 20 },
415
	.find_pll = intel_vlv_find_best_pll,
412
	.find_pll = intel_vlv_find_best_pll,
416
};
413
};
Line 417... Line 414...
417
 
414
 
418
static const intel_limit_t intel_limits_vlv_dp = {
415
static const intel_limit_t intel_limits_vlv_dp = {
419
	.dot = { .min = 162000, .max = 270000 },
416
	.dot = { .min = 25000, .max = 270000 },
420
	.vco = { .min = 5994000, .max = 4000000 },
417
	.vco = { .min = 4000000, .max = 6000000 },
421
	.n = { .min = 1, .max = 7 },
418
	.n = { .min = 1, .max = 7 },
422
	.m = { .min = 60, .max = 300 }, /* guess */
419
	.m = { .min = 22, .max = 450 },
423
	.m1 = { .min = 2, .max = 3 },
420
	.m1 = { .min = 2, .max = 3 },
424
	.m2 = { .min = 11, .max = 156 },
421
	.m2 = { .min = 11, .max = 156 },
425
	.p = { .min = 10, .max = 30 },
422
	.p = { .min = 10, .max = 30 },
426
	.p1 = { .min = 2, .max = 3 },
423
	.p1 = { .min = 2, .max = 3 },
Line 552... Line 549...
552
				limit = &intel_limits_ironlake_single_lvds_100m;
549
				limit = &intel_limits_ironlake_single_lvds_100m;
553
			else
550
			else
554
				limit = &intel_limits_ironlake_single_lvds;
551
				limit = &intel_limits_ironlake_single_lvds;
555
		}
552
		}
556
	} else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
553
	} else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
557
			HAS_eDP)
554
		   intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
558
		limit = &intel_limits_ironlake_display_port;
555
		limit = &intel_limits_ironlake_display_port;
559
	else
556
	else
560
		limit = &intel_limits_ironlake_dac;
557
		limit = &intel_limits_ironlake_dac;
Line 561... Line 558...
561
 
558
 
Line 948... Line 945...
948
	best_clock->p2 = bestp2;
945
	best_clock->p2 = bestp2;
Line 949... Line 946...
949
 
946
 
950
	return true;
947
	return true;
Line -... Line 948...
-
 
948
}
-
 
949
 
-
 
950
enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
-
 
951
					     enum pipe pipe)
-
 
952
{
-
 
953
	struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
-
 
954
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
955
 
-
 
956
	return intel_crtc->cpu_transcoder;
951
}
957
}
952
 
958
 
953
static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
959
static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
954
{
960
{
Line 1020... Line 1026...
1020
 *
1026
 *
1021
 */
1027
 */
1022
void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
1028
void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
1023
{
1029
{
1024
	struct drm_i915_private *dev_priv = dev->dev_private;
1030
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
1031
	enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
-
 
1032
								      pipe);
Line 1025... Line 1033...
1025
 
1033
 
1026
	if (INTEL_INFO(dev)->gen >= 4) {
1034
	if (INTEL_INFO(dev)->gen >= 4) {
Line 1027... Line 1035...
1027
		int reg = PIPECONF(pipe);
1035
		int reg = PIPECONF(cpu_transcoder);
1028
 
1036
 
1029
		/* Wait for the Pipe State to go off */
1037
		/* Wait for the Pipe State to go off */
1030
		if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
1038
		if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
Line 1124... Line 1132...
1124
			  enum pipe pipe, bool state)
1132
			  enum pipe pipe, bool state)
1125
{
1133
{
1126
	int reg;
1134
	int reg;
1127
	u32 val;
1135
	u32 val;
1128
	bool cur_state;
1136
	bool cur_state;
-
 
1137
	enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
-
 
1138
								      pipe);
Line 1129... Line 1139...
1129
 
1139
 
1130
	if (IS_HASWELL(dev_priv->dev)) {
1140
	if (IS_HASWELL(dev_priv->dev)) {
1131
		/* On Haswell, DDI is used instead of FDI_TX_CTL */
1141
		/* On Haswell, DDI is used instead of FDI_TX_CTL */
1132
		reg = DDI_FUNC_CTL(pipe);
1142
		reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
1133
		val = I915_READ(reg);
1143
		val = I915_READ(reg);
1134
		cur_state = !!(val & PIPE_DDI_FUNC_ENABLE);
1144
		cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
1135
	} else {
1145
	} else {
1136
	reg = FDI_TX_CTL(pipe);
1146
	reg = FDI_TX_CTL(pipe);
1137
	val = I915_READ(reg);
1147
	val = I915_READ(reg);
1138
	cur_state = !!(val & FDI_TX_ENABLE);
1148
	cur_state = !!(val & FDI_TX_ENABLE);
Line 1149... Line 1159...
1149
{
1159
{
1150
	int reg;
1160
	int reg;
1151
	u32 val;
1161
	u32 val;
1152
	bool cur_state;
1162
	bool cur_state;
Line 1153... Line -...
1153
 
-
 
1154
	if (IS_HASWELL(dev_priv->dev) && pipe > 0) {
-
 
1155
			DRM_ERROR("Attempting to enable FDI_RX on Haswell pipe > 0\n");
-
 
1156
			return;
-
 
1157
	} else {
1163
 
1158
	reg = FDI_RX_CTL(pipe);
1164
	reg = FDI_RX_CTL(pipe);
1159
	val = I915_READ(reg);
1165
	val = I915_READ(reg);
1160
	cur_state = !!(val & FDI_RX_ENABLE);
-
 
1161
	}
1166
	cur_state = !!(val & FDI_RX_ENABLE);
1162
	WARN(cur_state != state,
1167
	WARN(cur_state != state,
1163
	     "FDI RX state assertion failure (expected %s, current %s)\n",
1168
	     "FDI RX state assertion failure (expected %s, current %s)\n",
1164
	     state_string(state), state_string(cur_state));
1169
	     state_string(state), state_string(cur_state));
1165
}
1170
}
Line 1189... Line 1194...
1189
				      enum pipe pipe)
1194
				      enum pipe pipe)
1190
{
1195
{
1191
	int reg;
1196
	int reg;
1192
	u32 val;
1197
	u32 val;
Line 1193... Line -...
1193
 
-
 
1194
	if (IS_HASWELL(dev_priv->dev) && pipe > 0) {
-
 
1195
		DRM_ERROR("Attempting to enable FDI on Haswell with pipe > 0\n");
-
 
1196
		return;
-
 
1197
	}
1198
 
1198
	reg = FDI_RX_CTL(pipe);
1199
	reg = FDI_RX_CTL(pipe);
1199
	val = I915_READ(reg);
1200
	val = I915_READ(reg);
1200
	WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
1201
	WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
Line 1233... Line 1234...
1233
			enum pipe pipe, bool state)
1234
			enum pipe pipe, bool state)
1234
{
1235
{
1235
	int reg;
1236
	int reg;
1236
	u32 val;
1237
	u32 val;
1237
	bool cur_state;
1238
	bool cur_state;
-
 
1239
	enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
-
 
1240
								      pipe);
Line 1238... Line 1241...
1238
 
1241
 
1239
	/* if we need the pipe A quirk it must be always on */
1242
	/* if we need the pipe A quirk it must be always on */
1240
	if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
1243
	if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
Line 1241... Line 1244...
1241
		state = true;
1244
		state = true;
1242
 
1245
 
1243
	reg = PIPECONF(pipe);
1246
	reg = PIPECONF(cpu_transcoder);
1244
	val = I915_READ(reg);
1247
	val = I915_READ(reg);
1245
	cur_state = !!(val & PIPECONF_ENABLE);
1248
	cur_state = !!(val & PIPECONF_ENABLE);
1246
	WARN(cur_state != state,
1249
	WARN(cur_state != state,
Line 1513... Line 1516...
1513
	POSTING_READ(reg);
1516
	POSTING_READ(reg);
1514
}
1517
}
Line 1515... Line 1518...
1515
 
1518
 
1516
/* SBI access */
1519
/* SBI access */
1517
static void
1520
static void
-
 
1521
intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
1518
intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value)
1522
		enum intel_sbi_destination destination)
1519
{
1523
{
-
 
1524
	unsigned long flags;
Line 1520... Line 1525...
1520
	unsigned long flags;
1525
	u32 tmp;
1521
 
1526
 
1522
	spin_lock_irqsave(&dev_priv->dpio_lock, flags);
-
 
1523
	if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
1527
	spin_lock_irqsave(&dev_priv->dpio_lock, flags);
1524
				100)) {
1528
	if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0, 100)) {
1525
		DRM_ERROR("timeout waiting for SBI to become ready\n");
1529
		DRM_ERROR("timeout waiting for SBI to become ready\n");
Line 1526... Line 1530...
1526
		goto out_unlock;
1530
		goto out_unlock;
1527
	}
-
 
1528
 
1531
	}
-
 
1532
 
1529
	I915_WRITE(SBI_ADDR,
1533
	I915_WRITE(SBI_ADDR, (reg << 16));
1530
			(reg << 16));
1534
	I915_WRITE(SBI_DATA, value);
1531
	I915_WRITE(SBI_DATA,
1535
 
1532
			value);
1536
	if (destination == SBI_ICLK)
-
 
1537
		tmp = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRWR;
Line 1533... Line 1538...
1533
	I915_WRITE(SBI_CTL_STAT,
1538
	else
1534
			SBI_BUSY |
1539
		tmp = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IOWR;
1535
			SBI_CTL_OP_CRWR);
1540
	I915_WRITE(SBI_CTL_STAT, SBI_BUSY | tmp);
1536
 
1541
 
Line 1543... Line 1548...
1543
out_unlock:
1548
out_unlock:
1544
	spin_unlock_irqrestore(&dev_priv->dpio_lock, flags);
1549
	spin_unlock_irqrestore(&dev_priv->dpio_lock, flags);
1545
}
1550
}
Line 1546... Line 1551...
1546
 
1551
 
1547
static u32
1552
static u32
-
 
1553
intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
1548
intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg)
1554
	       enum intel_sbi_destination destination)
1549
{
1555
{
1550
	unsigned long flags;
1556
	unsigned long flags;
Line 1551... Line 1557...
1551
	u32 value = 0;
1557
	u32 value = 0;
1552
 
1558
 
1553
	spin_lock_irqsave(&dev_priv->dpio_lock, flags);
-
 
1554
	if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
1559
	spin_lock_irqsave(&dev_priv->dpio_lock, flags);
1555
				100)) {
1560
	if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0, 100)) {
1556
		DRM_ERROR("timeout waiting for SBI to become ready\n");
1561
		DRM_ERROR("timeout waiting for SBI to become ready\n");
Line 1557... Line 1562...
1557
		goto out_unlock;
1562
		goto out_unlock;
-
 
1563
	}
1558
	}
1564
 
1559
 
1565
	I915_WRITE(SBI_ADDR, (reg << 16));
1560
	I915_WRITE(SBI_ADDR,
1566
 
1561
			(reg << 16));
1567
	if (destination == SBI_ICLK)
-
 
1568
		value = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
Line 1562... Line 1569...
1562
	I915_WRITE(SBI_CTL_STAT,
1569
	else
1563
			SBI_BUSY |
1570
		value = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
1564
			SBI_CTL_OP_CRRD);
1571
	I915_WRITE(SBI_CTL_STAT, value | SBI_BUSY);
1565
 
1572
 
Line 1575... Line 1582...
1575
	spin_unlock_irqrestore(&dev_priv->dpio_lock, flags);
1582
	spin_unlock_irqrestore(&dev_priv->dpio_lock, flags);
1576
	return value;
1583
	return value;
1577
}
1584
}
Line 1578... Line 1585...
1578
 
1585
 
1579
/**
1586
/**
1580
 * intel_enable_pch_pll - enable PCH PLL
1587
 * ironlake_enable_pch_pll - enable PCH PLL
1581
 * @dev_priv: i915 private structure
1588
 * @dev_priv: i915 private structure
1582
 * @pipe: pipe PLL to enable
1589
 * @pipe: pipe PLL to enable
1583
 *
1590
 *
1584
 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1591
 * The PCH PLL needs to be enabled before the PCH transcoder, since it
1585
 * drives the transcoder clock.
1592
 * drives the transcoder clock.
1586
 */
1593
 */
1587
static void intel_enable_pch_pll(struct intel_crtc *intel_crtc)
1594
static void ironlake_enable_pch_pll(struct intel_crtc *intel_crtc)
1588
{
1595
{
1589
	struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
1596
	struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
1590
	struct intel_pch_pll *pll;
1597
	struct intel_pch_pll *pll;
1591
	int reg;
1598
	int reg;
Line 1666... Line 1673...
1666
	udelay(200);
1673
	udelay(200);
Line 1667... Line 1674...
1667
 
1674
 
1668
	pll->on = false;
1675
	pll->on = false;
Line 1669... Line 1676...
1669
}
1676
}
1670
 
1677
 
1671
static void intel_enable_transcoder(struct drm_i915_private *dev_priv,
1678
static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
1672
				    enum pipe pipe)
-
 
1673
{
1679
				    enum pipe pipe)
1674
	int reg;
1680
{
-
 
1681
	struct drm_device *dev = dev_priv->dev;
Line 1675... Line 1682...
1675
	u32 val, pipeconf_val;
1682
	struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1676
	struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1683
	uint32_t reg, val, pipeconf_val;
Line 1677... Line 1684...
1677
 
1684
 
Line 1685... Line 1692...
1685
 
1692
 
1686
	/* FDI must be feeding us bits for PCH ports */
1693
	/* FDI must be feeding us bits for PCH ports */
1687
	assert_fdi_tx_enabled(dev_priv, pipe);
1694
	assert_fdi_tx_enabled(dev_priv, pipe);
Line 1688... Line 1695...
1688
	assert_fdi_rx_enabled(dev_priv, pipe);
1695
	assert_fdi_rx_enabled(dev_priv, pipe);
1689
 
1696
 
-
 
1697
	if (HAS_PCH_CPT(dev)) {
-
 
1698
		/* Workaround: Set the timing override bit before enabling the
-
 
1699
		 * pch transcoder. */
-
 
1700
		reg = TRANS_CHICKEN2(pipe);
1690
	if (IS_HASWELL(dev_priv->dev) && pipe > 0) {
1701
		val = I915_READ(reg);
1691
		DRM_ERROR("Attempting to enable transcoder on Haswell with pipe > 0\n");
1702
		val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
-
 
1703
		I915_WRITE(reg, val);
1692
		return;
1704
	}
1693
	}
1705
 
1694
	reg = TRANSCONF(pipe);
1706
	reg = TRANSCONF(pipe);
Line 1695... Line 1707...
1695
	val = I915_READ(reg);
1707
	val = I915_READ(reg);
Line 1717... Line 1729...
1717
	I915_WRITE(reg, val | TRANS_ENABLE);
1729
	I915_WRITE(reg, val | TRANS_ENABLE);
1718
	if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
1730
	if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
1719
		DRM_ERROR("failed to enable transcoder %d\n", pipe);
1731
		DRM_ERROR("failed to enable transcoder %d\n", pipe);
1720
}
1732
}
Line -... Line 1733...
-
 
1733
 
-
 
1734
static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
-
 
1735
				      enum transcoder cpu_transcoder)
-
 
1736
{
-
 
1737
	u32 val, pipeconf_val;
-
 
1738
 
-
 
1739
	/* PCH only available on ILK+ */
-
 
1740
	BUG_ON(dev_priv->info->gen < 5);
-
 
1741
 
-
 
1742
	/* FDI must be feeding us bits for PCH ports */
-
 
1743
	assert_fdi_tx_enabled(dev_priv, cpu_transcoder);
-
 
1744
	assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
-
 
1745
 
-
 
1746
	/* Workaround: set timing override bit. */
-
 
1747
	val = I915_READ(_TRANSA_CHICKEN2);
-
 
1748
	val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
-
 
1749
	I915_WRITE(_TRANSA_CHICKEN2, val);
-
 
1750
 
-
 
1751
	val = TRANS_ENABLE;
-
 
1752
	pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
-
 
1753
 
-
 
1754
	if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
-
 
1755
	    PIPECONF_INTERLACED_ILK)
-
 
1756
		val |= TRANS_INTERLACED;
-
 
1757
	else
-
 
1758
		val |= TRANS_PROGRESSIVE;
-
 
1759
 
-
 
1760
	I915_WRITE(TRANSCONF(TRANSCODER_A), val);
-
 
1761
	if (wait_for(I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE, 100))
-
 
1762
		DRM_ERROR("Failed to enable PCH transcoder\n");
-
 
1763
}
1721
 
1764
 
1722
static void intel_disable_transcoder(struct drm_i915_private *dev_priv,
1765
static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1723
				     enum pipe pipe)
1766
				     enum pipe pipe)
1724
{
1767
{
1725
	int reg;
1768
	struct drm_device *dev = dev_priv->dev;
Line 1726... Line 1769...
1726
	u32 val;
1769
	uint32_t reg, val;
1727
 
1770
 
1728
	/* FDI relies on the transcoder */
1771
	/* FDI relies on the transcoder */
Line 1737... Line 1780...
1737
	val &= ~TRANS_ENABLE;
1780
	val &= ~TRANS_ENABLE;
1738
	I915_WRITE(reg, val);
1781
	I915_WRITE(reg, val);
1739
	/* wait for PCH transcoder off, transcoder state */
1782
	/* wait for PCH transcoder off, transcoder state */
1740
	if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
1783
	if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
1741
		DRM_ERROR("failed to disable transcoder %d\n", pipe);
1784
		DRM_ERROR("failed to disable transcoder %d\n", pipe);
-
 
1785
 
-
 
1786
	if (!HAS_PCH_IBX(dev)) {
-
 
1787
		/* Workaround: Clear the timing override chicken bit again. */
-
 
1788
		reg = TRANS_CHICKEN2(pipe);
-
 
1789
		val = I915_READ(reg);
-
 
1790
		val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
-
 
1791
		I915_WRITE(reg, val);
-
 
1792
	}
-
 
1793
}
-
 
1794
 
-
 
1795
static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
-
 
1796
{
-
 
1797
	u32 val;
-
 
1798
 
-
 
1799
	val = I915_READ(_TRANSACONF);
-
 
1800
	val &= ~TRANS_ENABLE;
-
 
1801
	I915_WRITE(_TRANSACONF, val);
-
 
1802
	/* wait for PCH transcoder off, transcoder state */
-
 
1803
	if (wait_for((I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE) == 0, 50))
-
 
1804
		DRM_ERROR("Failed to disable PCH transcoder\n");
-
 
1805
 
-
 
1806
	/* Workaround: clear timing override bit. */
-
 
1807
	val = I915_READ(_TRANSA_CHICKEN2);
-
 
1808
	val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
-
 
1809
	I915_WRITE(_TRANSA_CHICKEN2, val);
1742
}
1810
}
Line 1743... Line 1811...
1743
 
1811
 
1744
/**
1812
/**
1745
 * intel_enable_pipe - enable a pipe, asserting requirements
1813
 * intel_enable_pipe - enable a pipe, asserting requirements
Line 1756... Line 1824...
1756
 * returning.
1824
 * returning.
1757
 */
1825
 */
1758
static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
1826
static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
1759
			      bool pch_port)
1827
			      bool pch_port)
1760
{
1828
{
-
 
1829
	enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
-
 
1830
								      pipe);
-
 
1831
	enum transcoder pch_transcoder;
1761
	int reg;
1832
	int reg;
1762
	u32 val;
1833
	u32 val;
Line -... Line 1834...
-
 
1834
 
-
 
1835
	if (IS_HASWELL(dev_priv->dev))
-
 
1836
		pch_transcoder = TRANSCODER_A;
-
 
1837
	else
-
 
1838
		pch_transcoder = pipe;
1763
 
1839
 
1764
	/*
1840
	/*
1765
	 * A pipe without a PLL won't actually be able to drive bits from
1841
	 * A pipe without a PLL won't actually be able to drive bits from
1766
	 * a plane.  On ILK+ the pipe PLLs are integrated, so we don't
1842
	 * a plane.  On ILK+ the pipe PLLs are integrated, so we don't
1767
	 * need the check.
1843
	 * need the check.
1768
	 */
1844
	 */
1769
	if (!HAS_PCH_SPLIT(dev_priv->dev))
1845
	if (!HAS_PCH_SPLIT(dev_priv->dev))
1770
		assert_pll_enabled(dev_priv, pipe);
1846
		assert_pll_enabled(dev_priv, pipe);
1771
	else {
1847
	else {
1772
		if (pch_port) {
1848
		if (pch_port) {
1773
			/* if driving the PCH, we need FDI enabled */
1849
			/* if driving the PCH, we need FDI enabled */
1774
			assert_fdi_rx_pll_enabled(dev_priv, pipe);
1850
			assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
1775
			assert_fdi_tx_pll_enabled(dev_priv, pipe);
1851
			assert_fdi_tx_pll_enabled(dev_priv, cpu_transcoder);
1776
		}
1852
		}
1777
		/* FIXME: assert CPU port conditions for SNB+ */
1853
		/* FIXME: assert CPU port conditions for SNB+ */
Line 1778... Line 1854...
1778
	}
1854
	}
1779
 
1855
 
1780
	reg = PIPECONF(pipe);
1856
	reg = PIPECONF(cpu_transcoder);
1781
	val = I915_READ(reg);
1857
	val = I915_READ(reg);
Line 1782... Line 1858...
1782
	if (val & PIPECONF_ENABLE)
1858
	if (val & PIPECONF_ENABLE)
Line 1799... Line 1875...
1799
 * Will wait until the pipe has shut down before returning.
1875
 * Will wait until the pipe has shut down before returning.
1800
 */
1876
 */
1801
static void intel_disable_pipe(struct drm_i915_private *dev_priv,
1877
static void intel_disable_pipe(struct drm_i915_private *dev_priv,
1802
			       enum pipe pipe)
1878
			       enum pipe pipe)
1803
{
1879
{
-
 
1880
	enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
-
 
1881
								      pipe);
1804
	int reg;
1882
	int reg;
1805
	u32 val;
1883
	u32 val;
Line 1806... Line 1884...
1806
 
1884
 
1807
    /*
1885
    /*
Line 1812... Line 1890...
1812
 
1890
 
1813
	/* Don't disable pipe A or pipe A PLLs if needed */
1891
	/* Don't disable pipe A or pipe A PLLs if needed */
1814
	if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
1892
	if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
Line 1815... Line 1893...
1815
		return;
1893
		return;
1816
 
1894
 
1817
	reg = PIPECONF(pipe);
1895
	reg = PIPECONF(cpu_transcoder);
1818
	val = I915_READ(reg);
1896
	val = I915_READ(reg);
Line 1819... Line 1897...
1819
	if ((val & PIPECONF_ENABLE) == 0)
1897
	if ((val & PIPECONF_ENABLE) == 0)
Line 1828... Line 1906...
1828
 * trigger in order to latch.  The display address reg provides this.
1906
 * trigger in order to latch.  The display address reg provides this.
1829
 */
1907
 */
1830
void intel_flush_display_plane(struct drm_i915_private *dev_priv,
1908
void intel_flush_display_plane(struct drm_i915_private *dev_priv,
1831
				      enum plane plane)
1909
				      enum plane plane)
1832
{
1910
{
1833
	I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane)));
1911
	if (dev_priv->info->gen >= 4)
1834
	I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane)));
1912
		I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane)));
-
 
1913
	else
-
 
1914
	I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane)));
1835
}
1915
}
Line 1836... Line 1916...
1836
 
1916
 
1837
/**
1917
/**
1838
 * intel_enable_plane - enable a display plane on a given pipe
1918
 * intel_enable_plane - enable a display plane on a given pipe
Line 1923... Line 2003...
1923
	/* Install a fence for tiled scan-out. Pre-i965 always needs a
2003
	/* Install a fence for tiled scan-out. Pre-i965 always needs a
1924
	 * fence, whereas 965+ only requires a fence if using
2004
	 * fence, whereas 965+ only requires a fence if using
1925
	 * framebuffer compression.  For simplicity, we always install
2005
	 * framebuffer compression.  For simplicity, we always install
1926
	 * a fence as the cost is not that onerous.
2006
	 * a fence as the cost is not that onerous.
1927
	 */
2007
	 */
1928
//	if (obj->tiling_mode != I915_TILING_NONE) {
-
 
1929
//		ret = i915_gem_object_get_fence(obj, pipelined);
-
 
1930
//		if (ret)
-
 
1931
//			goto err_unpin;
-
 
1932
//	}
-
 
Line 1933... Line 2008...
1933
 
2008
 
1934
	dev_priv->mm.interruptible = true;
2009
	dev_priv->mm.interruptible = true;
Line 1935... Line 2010...
1935
	return 0;
2010
	return 0;
Line 1947... Line 2022...
1947
//	i915_gem_object_unpin(obj);
2022
//	i915_gem_object_unpin(obj);
1948
}
2023
}
Line 1949... Line 2024...
1949
 
2024
 
1950
/* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
2025
/* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
1951
 * is assumed to be a power-of-two. */
2026
 * is assumed to be a power-of-two. */
1952
static unsigned long gen4_compute_dspaddr_offset_xtiled(int *x, int *y,
2027
unsigned long intel_gen4_compute_offset_xtiled(int *x, int *y,
1953
							unsigned int bpp,
2028
							unsigned int bpp,
1954
							unsigned int pitch)
2029
							unsigned int pitch)
1955
{
2030
{
Line 1990... Line 2065...
1990
 
2065
 
1991
    reg = DSPCNTR(plane);
2066
    reg = DSPCNTR(plane);
1992
    dspcntr = I915_READ(reg);
2067
    dspcntr = I915_READ(reg);
1993
    /* Mask out pixel format bits in case we change it */
2068
    /* Mask out pixel format bits in case we change it */
1994
    dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
2069
    dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
1995
    switch (fb->bits_per_pixel) {
2070
	switch (fb->pixel_format) {
1996
    case 8:
2071
	case DRM_FORMAT_C8:
1997
        dspcntr |= DISPPLANE_8BPP;
2072
        dspcntr |= DISPPLANE_8BPP;
1998
        break;
2073
        break;
1999
    case 16:
2074
	case DRM_FORMAT_XRGB1555:
2000
        if (fb->depth == 15)
-
 
2001
            dspcntr |= DISPPLANE_15_16BPP;
-
 
2002
        else
2075
	case DRM_FORMAT_ARGB1555:
2003
            dspcntr |= DISPPLANE_16BPP;
2076
		dspcntr |= DISPPLANE_BGRX555;
-
 
2077
		break;
-
 
2078
	case DRM_FORMAT_RGB565:
-
 
2079
		dspcntr |= DISPPLANE_BGRX565;
-
 
2080
		break;
-
 
2081
	case DRM_FORMAT_XRGB8888:
-
 
2082
	case DRM_FORMAT_ARGB8888:
2004
        break;
2083
		dspcntr |= DISPPLANE_BGRX888;
-
 
2084
		break;
-
 
2085
	case DRM_FORMAT_XBGR8888:
-
 
2086
	case DRM_FORMAT_ABGR8888:
-
 
2087
		dspcntr |= DISPPLANE_RGBX888;
-
 
2088
		break;
-
 
2089
	case DRM_FORMAT_XRGB2101010:
-
 
2090
	case DRM_FORMAT_ARGB2101010:
2005
    case 24:
2091
		dspcntr |= DISPPLANE_BGRX101010;
-
 
2092
        break;
-
 
2093
	case DRM_FORMAT_XBGR2101010:
2006
    case 32:
2094
	case DRM_FORMAT_ABGR2101010:
2007
        dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
2095
		dspcntr |= DISPPLANE_RGBX101010;
2008
        break;
2096
        break;
2009
    default:
2097
    default:
2010
        DRM_ERROR("Unknown color depth %d\n", fb->bits_per_pixel);
2098
		DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
2011
        return -EINVAL;
2099
        return -EINVAL;
-
 
2100
    }
2012
    }
2101
 
2013
    if (INTEL_INFO(dev)->gen >= 4) {
2102
    if (INTEL_INFO(dev)->gen >= 4) {
2014
        if (obj->tiling_mode != I915_TILING_NONE)
2103
        if (obj->tiling_mode != I915_TILING_NONE)
2015
            dspcntr |= DISPPLANE_TILED;
2104
            dspcntr |= DISPPLANE_TILED;
2016
        else
2105
        else
Line 2021... Line 2110...
2021
 
2110
 
Line 2022... Line 2111...
2022
	linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
2111
	linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
2023
 
2112
 
2024
	if (INTEL_INFO(dev)->gen >= 4) {
2113
	if (INTEL_INFO(dev)->gen >= 4) {
2025
		intel_crtc->dspaddr_offset =
2114
		intel_crtc->dspaddr_offset =
2026
			gen4_compute_dspaddr_offset_xtiled(&x, &y,
2115
			intel_gen4_compute_offset_xtiled(&x, &y,
2027
							   fb->bits_per_pixel / 8,
2116
							   fb->bits_per_pixel / 8,
2028
							   fb->pitches[0]);
2117
							   fb->pitches[0]);
2029
		linear_offset -= intel_crtc->dspaddr_offset;
2118
		linear_offset -= intel_crtc->dspaddr_offset;
Line 2074... Line 2163...
2074
 
2163
 
2075
    reg = DSPCNTR(plane);
2164
    reg = DSPCNTR(plane);
2076
    dspcntr = I915_READ(reg);
2165
    dspcntr = I915_READ(reg);
2077
    /* Mask out pixel format bits in case we change it */
2166
    /* Mask out pixel format bits in case we change it */
2078
    dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
2167
    dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
2079
    switch (fb->bits_per_pixel) {
2168
	switch (fb->pixel_format) {
2080
    case 8:
2169
	case DRM_FORMAT_C8:
2081
        dspcntr |= DISPPLANE_8BPP;
2170
        dspcntr |= DISPPLANE_8BPP;
2082
        break;
-
 
2083
    case 16:
-
 
2084
        if (fb->depth != 16)
2171
        break;
2085
            return -EINVAL;
-
 
2086
 
2172
	case DRM_FORMAT_RGB565:
2087
        dspcntr |= DISPPLANE_16BPP;
2173
		dspcntr |= DISPPLANE_BGRX565;
-
 
2174
        break;
-
 
2175
	case DRM_FORMAT_XRGB8888:
-
 
2176
	case DRM_FORMAT_ARGB8888:
2088
        break;
2177
		dspcntr |= DISPPLANE_BGRX888;
2089
    case 24:
2178
		break;
2090
    case 32:
2179
	case DRM_FORMAT_XBGR8888:
2091
        if (fb->depth == 24)
2180
	case DRM_FORMAT_ABGR8888:
-
 
2181
		dspcntr |= DISPPLANE_RGBX888;
-
 
2182
		break;
2092
            dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
2183
	case DRM_FORMAT_XRGB2101010:
2093
        else if (fb->depth == 30)
2184
	case DRM_FORMAT_ARGB2101010:
2094
            dspcntr |= DISPPLANE_32BPP_30BIT_NO_ALPHA;
2185
		dspcntr |= DISPPLANE_BGRX101010;
-
 
2186
		break;
-
 
2187
	case DRM_FORMAT_XBGR2101010:
2095
        else
2188
	case DRM_FORMAT_ABGR2101010:
2096
            return -EINVAL;
2189
		dspcntr |= DISPPLANE_RGBX101010;
2097
        break;
2190
        break;
2098
    default:
2191
    default:
2099
        DRM_ERROR("Unknown color depth %d\n", fb->bits_per_pixel);
2192
		DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
2100
        return -EINVAL;
2193
        return -EINVAL;
Line 2101... Line 2194...
2101
    }
2194
    }
2102
 
2195
 
Line 2110... Line 2203...
2110
 
2203
 
Line 2111... Line 2204...
2111
    I915_WRITE(reg, dspcntr);
2204
    I915_WRITE(reg, dspcntr);
2112
 
2205
 
2113
	linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
2206
	linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
2114
	intel_crtc->dspaddr_offset =
2207
	intel_crtc->dspaddr_offset =
2115
		gen4_compute_dspaddr_offset_xtiled(&x, &y,
2208
		intel_gen4_compute_offset_xtiled(&x, &y,
2116
						   fb->bits_per_pixel / 8,
2209
						   fb->bits_per_pixel / 8,
Line 2117... Line 2210...
2117
						   fb->pitches[0]);
2210
						   fb->pitches[0]);
2118
	linear_offset -= intel_crtc->dspaddr_offset;
2211
	linear_offset -= intel_crtc->dspaddr_offset;
2119
 
2212
 
2120
	DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2213
	DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
2121
		      obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
2214
		      obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
-
 
2215
	I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
-
 
2216
	I915_MODIFY_DISPBASE(DSPSURF(plane),
-
 
2217
			     obj->gtt_offset + intel_crtc->dspaddr_offset);
2122
	I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
2218
	if (IS_HASWELL(dev)) {
2123
	I915_MODIFY_DISPBASE(DSPSURF(plane),
2219
		I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
-
 
2220
	} else {
2124
			     obj->gtt_offset + intel_crtc->dspaddr_offset);
2221
	I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
Line 2125... Line 2222...
2125
	I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
2222
	I915_WRITE(DSPLINOFF(plane), linear_offset);
2126
	I915_WRITE(DSPLINOFF(plane), linear_offset);
2223
	}
Line 2177... Line 2274...
2177
intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2274
intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
2178
		    struct drm_framebuffer *fb)
2275
		    struct drm_framebuffer *fb)
2179
{
2276
{
2180
	struct drm_device *dev = crtc->dev;
2277
	struct drm_device *dev = crtc->dev;
2181
	struct drm_i915_private *dev_priv = dev->dev_private;
2278
	struct drm_i915_private *dev_priv = dev->dev_private;
2182
	struct drm_i915_master_private *master_priv;
-
 
2183
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2279
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2184
	struct drm_framebuffer *old_fb;
2280
	struct drm_framebuffer *old_fb;
2185
	int ret;
2281
	int ret;
Line 2186... Line 2282...
2186
 
2282
 
Line 2310... Line 2406...
2310
	if (IS_IVYBRIDGE(dev))
2406
	if (IS_IVYBRIDGE(dev))
2311
		I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
2407
		I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
2312
			   FDI_FE_ERRC_ENABLE);
2408
			   FDI_FE_ERRC_ENABLE);
2313
}
2409
}
Line 2314... Line 2410...
2314
 
2410
 
2315
static void cpt_phase_pointer_enable(struct drm_device *dev, int pipe)
2411
static void ivb_modeset_global_resources(struct drm_device *dev)
2316
{
2412
{
-
 
2413
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
2414
	struct intel_crtc *pipe_B_crtc =
2317
	struct drm_i915_private *dev_priv = dev->dev_private;
2415
		to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
-
 
2416
	struct intel_crtc *pipe_C_crtc =
-
 
2417
		to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
2318
	u32 flags = I915_READ(SOUTH_CHICKEN1);
2418
	uint32_t temp;
-
 
2419
 
-
 
2420
	/* When everything is off disable fdi C so that we could enable fdi B
-
 
2421
	 * with all lanes. XXX: This misses the case where a pipe is not using
-
 
2422
	 * any pch resources and so doesn't need any fdi lanes. */
-
 
2423
	if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) {
2319
 
2424
		WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
-
 
2425
		WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
2320
	flags |= FDI_PHASE_SYNC_OVR(pipe);
2426
 
2321
	I915_WRITE(SOUTH_CHICKEN1, flags); /* once to unlock... */
2427
		temp = I915_READ(SOUTH_CHICKEN1);
2322
	flags |= FDI_PHASE_SYNC_EN(pipe);
2428
		temp &= ~FDI_BC_BIFURCATION_SELECT;
2323
	I915_WRITE(SOUTH_CHICKEN1, flags); /* then again to enable */
2429
		DRM_DEBUG_KMS("disabling fdi C rx\n");
-
 
2430
		I915_WRITE(SOUTH_CHICKEN1, temp);
2324
	POSTING_READ(SOUTH_CHICKEN1);
2431
	}
Line 2325... Line 2432...
2325
}
2432
}
2326
 
2433
 
2327
/* The FDI link training functions for ILK/Ibexpeak. */
2434
/* The FDI link training functions for ILK/Ibexpeak. */
Line 2365... Line 2472...
2365
 
2472
 
2366
    POSTING_READ(reg);
2473
    POSTING_READ(reg);
Line 2367... Line 2474...
2367
    udelay(150);
2474
    udelay(150);
2368
 
-
 
2369
    /* Ironlake workaround, enable clock pointer after FDI enable*/
2475
 
2370
    if (HAS_PCH_IBX(dev)) {
2476
    /* Ironlake workaround, enable clock pointer after FDI enable*/
2371
        I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
2477
        I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
2372
        I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
-
 
Line 2373... Line 2478...
2373
               FDI_RX_PHASE_SYNC_POINTER_EN);
2478
        I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
2374
    }
2479
               FDI_RX_PHASE_SYNC_POINTER_EN);
2375
 
2480
 
2376
    reg = FDI_RX_IIR(pipe);
2481
    reg = FDI_RX_IIR(pipe);
Line 2458... Line 2563...
2458
    temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2563
    temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2459
    /* SNB-B */
2564
    /* SNB-B */
2460
    temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2565
    temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2461
    I915_WRITE(reg, temp | FDI_TX_ENABLE);
2566
    I915_WRITE(reg, temp | FDI_TX_ENABLE);
Line -... Line 2567...
-
 
2567
 
-
 
2568
	I915_WRITE(FDI_RX_MISC(pipe),
-
 
2569
		   FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
2462
 
2570
 
2463
    reg = FDI_RX_CTL(pipe);
2571
    reg = FDI_RX_CTL(pipe);
2464
    temp = I915_READ(reg);
2572
    temp = I915_READ(reg);
2465
    if (HAS_PCH_CPT(dev)) {
2573
    if (HAS_PCH_CPT(dev)) {
2466
        temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2574
        temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
Line 2472... Line 2580...
2472
    I915_WRITE(reg, temp | FDI_RX_ENABLE);
2580
    I915_WRITE(reg, temp | FDI_RX_ENABLE);
Line 2473... Line 2581...
2473
 
2581
 
2474
    POSTING_READ(reg);
2582
    POSTING_READ(reg);
Line 2475... Line -...
2475
    udelay(150);
-
 
2476
 
-
 
2477
    if (HAS_PCH_CPT(dev))
-
 
2478
        cpt_phase_pointer_enable(dev, pipe);
2583
    udelay(150);
2479
 
2584
 
2480
	for (i = 0; i < 4; i++) {
2585
	for (i = 0; i < 4; i++) {
2481
        reg = FDI_TX_CTL(pipe);
2586
        reg = FDI_TX_CTL(pipe);
2482
        temp = I915_READ(reg);
2587
        temp = I915_READ(reg);
Line 2578... Line 2683...
2578
    I915_WRITE(reg, temp);
2683
    I915_WRITE(reg, temp);
Line 2579... Line 2684...
2579
 
2684
 
2580
    POSTING_READ(reg);
2685
    POSTING_READ(reg);
Line -... Line 2686...
-
 
2686
    udelay(150);
-
 
2687
 
-
 
2688
	DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
2581
    udelay(150);
2689
		      I915_READ(FDI_RX_IIR(pipe)));
2582
 
2690
 
2583
    /* enable CPU FDI TX and PCH FDI RX */
2691
    /* enable CPU FDI TX and PCH FDI RX */
2584
    reg = FDI_TX_CTL(pipe);
2692
    reg = FDI_TX_CTL(pipe);
2585
    temp = I915_READ(reg);
2693
    temp = I915_READ(reg);
Line 2590... Line 2698...
2590
    temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2698
    temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
2591
    temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2699
    temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
2592
	temp |= FDI_COMPOSITE_SYNC;
2700
	temp |= FDI_COMPOSITE_SYNC;
2593
    I915_WRITE(reg, temp | FDI_TX_ENABLE);
2701
    I915_WRITE(reg, temp | FDI_TX_ENABLE);
Line -... Line 2702...
-
 
2702
 
-
 
2703
	I915_WRITE(FDI_RX_MISC(pipe),
-
 
2704
		   FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
2594
 
2705
 
2595
    reg = FDI_RX_CTL(pipe);
2706
    reg = FDI_RX_CTL(pipe);
2596
    temp = I915_READ(reg);
2707
    temp = I915_READ(reg);
2597
    temp &= ~FDI_LINK_TRAIN_AUTO;
2708
    temp &= ~FDI_LINK_TRAIN_AUTO;
2598
    temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
2709
    temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
Line 2601... Line 2712...
2601
    I915_WRITE(reg, temp | FDI_RX_ENABLE);
2712
    I915_WRITE(reg, temp | FDI_RX_ENABLE);
Line 2602... Line 2713...
2602
 
2713
 
2603
    POSTING_READ(reg);
2714
    POSTING_READ(reg);
Line 2604... Line -...
2604
    udelay(150);
-
 
2605
 
-
 
2606
    if (HAS_PCH_CPT(dev))
-
 
2607
        cpt_phase_pointer_enable(dev, pipe);
2715
    udelay(150);
2608
 
2716
 
2609
	for (i = 0; i < 4; i++) {
2717
	for (i = 0; i < 4; i++) {
2610
        reg = FDI_TX_CTL(pipe);
2718
        reg = FDI_TX_CTL(pipe);
2611
        temp = I915_READ(reg);
2719
        temp = I915_READ(reg);
Line 2621... Line 2729...
2621
        DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2729
        DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
Line 2622... Line 2730...
2622
 
2730
 
2623
        if (temp & FDI_RX_BIT_LOCK ||
2731
        if (temp & FDI_RX_BIT_LOCK ||
2624
            (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
2732
            (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
2625
            I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2733
            I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
2626
            DRM_DEBUG_KMS("FDI train 1 done.\n");
2734
			DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i);
2627
            break;
2735
            break;
2628
        }
2736
        }
2629
    }
2737
    }
2630
    if (i == 4)
2738
    if (i == 4)
Line 2662... Line 2770...
2662
        temp = I915_READ(reg);
2770
        temp = I915_READ(reg);
2663
        DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
2771
        DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
Line 2664... Line 2772...
2664
 
2772
 
2665
        if (temp & FDI_RX_SYMBOL_LOCK) {
2773
        if (temp & FDI_RX_SYMBOL_LOCK) {
2666
            I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2774
            I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
2667
            DRM_DEBUG_KMS("FDI train 2 done.\n");
2775
			DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i);
2668
            break;
2776
            break;
2669
        }
2777
        }
2670
    }
2778
    }
2671
    if (i == 4)
2779
    if (i == 4)
Line 2679... Line 2787...
2679
	struct drm_device *dev = intel_crtc->base.dev;
2787
	struct drm_device *dev = intel_crtc->base.dev;
2680
	struct drm_i915_private *dev_priv = dev->dev_private;
2788
	struct drm_i915_private *dev_priv = dev->dev_private;
2681
	int pipe = intel_crtc->pipe;
2789
	int pipe = intel_crtc->pipe;
2682
	u32 reg, temp;
2790
	u32 reg, temp;
Line 2683... Line -...
2683
 
-
 
2684
	/* Write the TU size bits so error detection works */
-
 
2685
	I915_WRITE(FDI_RX_TUSIZE1(pipe),
-
 
Line 2686... Line 2791...
2686
		   I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
2791
 
2687
 
2792
 
2688
	/* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2793
	/* enable PCH FDI RX PLL, wait warmup plus DMI latency */
2689
	reg = FDI_RX_CTL(pipe);
2794
	reg = FDI_RX_CTL(pipe);
Line 2745... Line 2850...
2745
	/* Wait for the clocks to turn off. */
2850
	/* Wait for the clocks to turn off. */
2746
	POSTING_READ(reg);
2851
	POSTING_READ(reg);
2747
	udelay(100);
2852
	udelay(100);
2748
}
2853
}
Line 2749... Line -...
2749
 
-
 
2750
static void cpt_phase_pointer_disable(struct drm_device *dev, int pipe)
-
 
2751
{
-
 
2752
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
2753
	u32 flags = I915_READ(SOUTH_CHICKEN1);
-
 
2754
 
-
 
2755
	flags &= ~(FDI_PHASE_SYNC_EN(pipe));
-
 
2756
	I915_WRITE(SOUTH_CHICKEN1, flags); /* once to disable... */
-
 
2757
	flags &= ~(FDI_PHASE_SYNC_OVR(pipe));
-
 
2758
	I915_WRITE(SOUTH_CHICKEN1, flags); /* then again to lock */
-
 
2759
	POSTING_READ(SOUTH_CHICKEN1);
-
 
2760
}
2854
 
2761
static void ironlake_fdi_disable(struct drm_crtc *crtc)
2855
static void ironlake_fdi_disable(struct drm_crtc *crtc)
2762
{
2856
{
2763
	struct drm_device *dev = crtc->dev;
2857
	struct drm_device *dev = crtc->dev;
2764
	struct drm_i915_private *dev_priv = dev->dev_private;
2858
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 2782... Line 2876...
2782
	udelay(100);
2876
	udelay(100);
Line 2783... Line 2877...
2783
 
2877
 
2784
	/* Ironlake workaround, disable clock pointer after downing FDI */
2878
	/* Ironlake workaround, disable clock pointer after downing FDI */
2785
	if (HAS_PCH_IBX(dev)) {
2879
	if (HAS_PCH_IBX(dev)) {
2786
		I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
-
 
2787
		I915_WRITE(FDI_RX_CHICKEN(pipe),
-
 
2788
			   I915_READ(FDI_RX_CHICKEN(pipe) &
-
 
2789
				     ~FDI_RX_PHASE_SYNC_POINTER_EN));
-
 
2790
	} else if (HAS_PCH_CPT(dev)) {
-
 
2791
		cpt_phase_pointer_disable(dev, pipe);
2880
		I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
Line 2792... Line 2881...
2792
	}
2881
	}
2793
 
2882
 
2794
	/* still set train pattern 1 */
2883
	/* still set train pattern 1 */
Line 2849... Line 2938...
2849
	intel_finish_fb(crtc->fb);
2938
	intel_finish_fb(crtc->fb);
2850
	mutex_unlock(&dev->struct_mutex);
2939
	mutex_unlock(&dev->struct_mutex);
2851
}
2940
}
2852
#endif
2941
#endif
Line 2853... Line 2942...
2853
 
2942
 
2854
static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
2943
static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
2855
{
2944
{
2856
	struct drm_device *dev = crtc->dev;
2945
	struct drm_device *dev = crtc->dev;
Line 2857... Line 2946...
2857
	struct intel_encoder *intel_encoder;
2946
	struct intel_encoder *intel_encoder;
2858
 
2947
 
2859
	/*
2948
	/*
2860
	 * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
2949
	 * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
2861
	 * must be driven by its own crtc; no sharing is possible.
2950
	 * must be driven by its own crtc; no sharing is possible.
2862
	 */
-
 
2863
	for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-
 
2864
 
-
 
2865
		/* On Haswell, LPT PCH handles the VGA connection via FDI, and Haswell
-
 
2866
		 * CPU handles all others */
-
 
2867
		if (IS_HASWELL(dev)) {
-
 
2868
			/* It is still unclear how this will work on PPT, so throw up a warning */
-
 
2869
			WARN_ON(!HAS_PCH_LPT(dev));
-
 
2870
 
-
 
2871
			if (intel_encoder->type == INTEL_OUTPUT_ANALOG) {
-
 
2872
				DRM_DEBUG_KMS("Haswell detected DAC encoder, assuming is PCH\n");
-
 
2873
				return true;
-
 
2874
			} else {
-
 
2875
				DRM_DEBUG_KMS("Haswell detected encoder %d, assuming is CPU\n",
-
 
2876
					      intel_encoder->type);
-
 
2877
				return false;
-
 
2878
			}
-
 
2879
		}
2951
	 */
2880
 
2952
	for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
2881
		switch (intel_encoder->type) {
2953
		switch (intel_encoder->type) {
2882
		case INTEL_OUTPUT_EDP:
2954
		case INTEL_OUTPUT_EDP:
2883
			if (!intel_encoder_is_pch_edp(&intel_encoder->base))
2955
			if (!intel_encoder_is_pch_edp(&intel_encoder->base))
Line 2887... Line 2959...
2887
	}
2959
	}
Line 2888... Line 2960...
2888
 
2960
 
2889
	return true;
2961
	return true;
Line -... Line 2962...
-
 
2962
}
-
 
2963
 
-
 
2964
static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
-
 
2965
{
-
 
2966
	return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
2890
}
2967
}
2891
 
2968
 
2892
/* Program iCLKIP clock to the desired frequency */
2969
/* Program iCLKIP clock to the desired frequency */
2893
static void lpt_program_iclkip(struct drm_crtc *crtc)
2970
static void lpt_program_iclkip(struct drm_crtc *crtc)
2894
{
2971
{
Line 2902... Line 2979...
2902
	 */
2979
	 */
2903
	I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
2980
	I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
Line 2904... Line 2981...
2904
 
2981
 
2905
	/* Disable SSCCTL */
2982
	/* Disable SSCCTL */
2906
	intel_sbi_write(dev_priv, SBI_SSCCTL6,
2983
	intel_sbi_write(dev_priv, SBI_SSCCTL6,
2907
				intel_sbi_read(dev_priv, SBI_SSCCTL6) |
2984
			intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
-
 
2985
				SBI_SSCCTL_DISABLE,
Line 2908... Line 2986...
2908
					SBI_SSCCTL_DISABLE);
2986
			SBI_ICLK);
2909
 
2987
 
2910
	/* 20MHz is a corner case which is out of range for the 7-bit divisor */
2988
	/* 20MHz is a corner case which is out of range for the 7-bit divisor */
2911
	if (crtc->mode.clock == 20000) {
2989
	if (crtc->mode.clock == 20000) {
Line 2944... Line 3022...
2944
			divsel,
3022
			divsel,
2945
			phasedir,
3023
			phasedir,
2946
			phaseinc);
3024
			phaseinc);
Line 2947... Line 3025...
2947
 
3025
 
2948
	/* Program SSCDIVINTPHASE6 */
3026
	/* Program SSCDIVINTPHASE6 */
2949
	temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6);
3027
	temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
2950
	temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
3028
	temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
2951
	temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
3029
	temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
2952
	temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
3030
	temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
2953
	temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
3031
	temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
2954
	temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
3032
	temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
2955
	temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
-
 
2956
 
3033
	temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
2957
	intel_sbi_write(dev_priv,
-
 
2958
			SBI_SSCDIVINTPHASE6,
-
 
Line 2959... Line 3034...
2959
			temp);
3034
	intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
2960
 
3035
 
2961
	/* Program SSCAUXDIV */
3036
	/* Program SSCAUXDIV */
2962
	temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6);
3037
	temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
2963
	temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3038
	temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
2964
	temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
-
 
2965
	intel_sbi_write(dev_priv,
-
 
2966
			SBI_SSCAUXDIV6,
-
 
Line 2967... Line 3039...
2967
			temp);
3039
	temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
2968
 
3040
	intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
2969
 
3041
 
2970
	/* Enable modulator and associated divider */
3042
	/* Enable modulator and associated divider */
2971
	temp = intel_sbi_read(dev_priv, SBI_SSCCTL6);
-
 
2972
	temp &= ~SBI_SSCCTL_DISABLE;
-
 
Line 2973... Line 3043...
2973
	intel_sbi_write(dev_priv,
3043
	temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
2974
			SBI_SSCCTL6,
3044
	temp &= ~SBI_SSCCTL_DISABLE;
Line 2975... Line 3045...
2975
			temp);
3045
	intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
Line 2996... Line 3066...
2996
	int pipe = intel_crtc->pipe;
3066
	int pipe = intel_crtc->pipe;
2997
	u32 reg, temp;
3067
	u32 reg, temp;
Line 2998... Line 3068...
2998
 
3068
 
Line -... Line 3069...
-
 
3069
	assert_transcoder_disabled(dev_priv, pipe);
-
 
3070
 
-
 
3071
	/* Write the TU size bits before fdi link training, so that error
-
 
3072
	 * detection works. */
-
 
3073
	I915_WRITE(FDI_RX_TUSIZE1(pipe),
2999
	assert_transcoder_disabled(dev_priv, pipe);
3074
		   I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
3000
 
3075
 
Line -... Line 3076...
-
 
3076
	/* For PCH output, training FDI link */
-
 
3077
	dev_priv->display.fdi_link_train(crtc);
-
 
3078
 
-
 
3079
	/* XXX: pch pll's can be enabled any time before we enable the PCH
-
 
3080
	 * transcoder, and we actually should do this to not upset any PCH
-
 
3081
	 * transcoder that already use the clock when we share it.
-
 
3082
	 *
3001
	/* For PCH output, training FDI link */
3083
	 * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
Line 3002... Line 3084...
3002
	dev_priv->display.fdi_link_train(crtc);
3084
	 * unconditionally resets the pll - we need that to have the right LVDS
3003
 
-
 
3004
	intel_enable_pch_pll(intel_crtc);
-
 
3005
 
-
 
3006
	if (HAS_PCH_LPT(dev)) {
3085
	 * enable sequence. */
Line 3007... Line 3086...
3007
		DRM_DEBUG_KMS("LPT detected: programming iCLKIP\n");
3086
	ironlake_enable_pch_pll(intel_crtc);
3008
		lpt_program_iclkip(crtc);
3087
 
3009
	} else if (HAS_PCH_CPT(dev)) {
3088
	if (HAS_PCH_CPT(dev)) {
Line 3041... Line 3120...
3041
	I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
3120
	I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
3042
	I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
3121
	I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
3043
	I915_WRITE(TRANS_VSYNC(pipe),  I915_READ(VSYNC(pipe)));
3122
	I915_WRITE(TRANS_VSYNC(pipe),  I915_READ(VSYNC(pipe)));
3044
	I915_WRITE(TRANS_VSYNCSHIFT(pipe),  I915_READ(VSYNCSHIFT(pipe)));
3123
	I915_WRITE(TRANS_VSYNCSHIFT(pipe),  I915_READ(VSYNCSHIFT(pipe)));
Line 3045... Line -...
3045
 
-
 
3046
	if (!IS_HASWELL(dev))
3124
 
Line 3047... Line 3125...
3047
	intel_fdi_normal_train(crtc);
3125
	intel_fdi_normal_train(crtc);
3048
 
3126
 
3049
	/* For PCH DP, enable TRANS_DP_CTL */
3127
	/* For PCH DP, enable TRANS_DP_CTL */
Line 3074... Line 3152...
3074
			break;
3152
			break;
3075
		case PCH_DP_D:
3153
		case PCH_DP_D:
3076
			temp |= TRANS_DP_PORT_SEL_D;
3154
			temp |= TRANS_DP_PORT_SEL_D;
3077
			break;
3155
			break;
3078
		default:
3156
		default:
3079
			DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n");
-
 
3080
			temp |= TRANS_DP_PORT_SEL_B;
-
 
3081
			break;
3157
			BUG();
3082
		}
3158
		}
Line 3083... Line 3159...
3083
 
3159
 
3084
		I915_WRITE(reg, temp);
3160
		I915_WRITE(reg, temp);
Line 3085... Line 3161...
3085
	}
3161
	}
-
 
3162
 
-
 
3163
	ironlake_enable_pch_transcoder(dev_priv, pipe);
-
 
3164
}
-
 
3165
 
-
 
3166
static void lpt_pch_enable(struct drm_crtc *crtc)
-
 
3167
{
-
 
3168
	struct drm_device *dev = crtc->dev;
-
 
3169
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
3170
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
3171
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
-
 
3172
 
-
 
3173
	assert_transcoder_disabled(dev_priv, TRANSCODER_A);
-
 
3174
 
-
 
3175
	lpt_program_iclkip(crtc);
-
 
3176
 
-
 
3177
	/* Set transcoder timing. */
-
 
3178
	I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder)));
-
 
3179
	I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder)));
-
 
3180
	I915_WRITE(_TRANS_HSYNC_A,  I915_READ(HSYNC(cpu_transcoder)));
-
 
3181
 
-
 
3182
	I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder)));
-
 
3183
	I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder)));
-
 
3184
	I915_WRITE(_TRANS_VSYNC_A,  I915_READ(VSYNC(cpu_transcoder)));
-
 
3185
	I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder)));
3086
 
3186
 
Line 3087... Line 3187...
3087
	intel_enable_transcoder(dev_priv, pipe);
3187
	lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
3088
}
3188
}
3089
 
3189
 
Line 3175... Line 3275...
3175
}
3275
}
Line 3176... Line 3276...
3176
 
3276
 
3177
void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
3277
void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
3178
{
3278
{
3179
	struct drm_i915_private *dev_priv = dev->dev_private;
3279
	struct drm_i915_private *dev_priv = dev->dev_private;
3180
	int dslreg = PIPEDSL(pipe), tc2reg = TRANS_CHICKEN2(pipe);
3280
	int dslreg = PIPEDSL(pipe);
Line 3181... Line 3281...
3181
	u32 temp;
3281
	u32 temp;
3182
 
3282
 
3183
	temp = I915_READ(dslreg);
3283
	temp = I915_READ(dslreg);
3184
	udelay(500);
-
 
3185
	if (wait_for(I915_READ(dslreg) != temp, 5)) {
-
 
3186
		/* Without this, mode sets may fail silently on FDI */
-
 
3187
		I915_WRITE(tc2reg, TRANS_AUTOTRAIN_GEN_STALL_DIS);
-
 
3188
		udelay(250);
3284
	udelay(500);
3189
		I915_WRITE(tc2reg, 0);
3285
	if (wait_for(I915_READ(dslreg) != temp, 5)) {
3190
		if (wait_for(I915_READ(dslreg) != temp, 5))
3286
		if (wait_for(I915_READ(dslreg) != temp, 5))
3191
			DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
3287
			DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
Line 3215... Line 3311...
3215
        temp = I915_READ(PCH_LVDS);
3311
        temp = I915_READ(PCH_LVDS);
3216
        if ((temp & LVDS_PORT_EN) == 0)
3312
        if ((temp & LVDS_PORT_EN) == 0)
3217
            I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
3313
            I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
3218
    }
3314
    }
Line 3219... Line 3315...
3219
 
3315
 
Line 3220... Line 3316...
3220
    is_pch_port = intel_crtc_driving_pch(crtc);
3316
	is_pch_port = ironlake_crtc_driving_pch(crtc);
-
 
3317
 
-
 
3318
	if (is_pch_port) {
-
 
3319
		/* Note: FDI PLL enabling _must_ be done before we enable the
3221
 
3320
		 * cpu pipes, hence this is separate from all the other fdi/pch
3222
	if (is_pch_port) {
3321
		 * enabling. */
3223
		ironlake_fdi_pll_enable(intel_crtc);
3322
		ironlake_fdi_pll_enable(intel_crtc);
3224
	} else {
3323
	} else {
3225
		assert_fdi_tx_disabled(dev_priv, pipe);
3324
		assert_fdi_tx_disabled(dev_priv, pipe);
Line 3230... Line 3329...
3230
		if (encoder->pre_enable)
3329
		if (encoder->pre_enable)
3231
			encoder->pre_enable(encoder);
3330
			encoder->pre_enable(encoder);
Line 3232... Line 3331...
3232
 
3331
 
3233
    /* Enable panel fitting for LVDS */
3332
    /* Enable panel fitting for LVDS */
3234
    if (dev_priv->pch_pf_size &&
3333
    if (dev_priv->pch_pf_size &&
-
 
3334
	    (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
3235
        (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || HAS_eDP)) {
3335
	     intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
3236
        /* Force use of hard-coded filter coefficients
3336
        /* Force use of hard-coded filter coefficients
3237
         * as some pre-programmed values are broken,
3337
         * as some pre-programmed values are broken,
3238
         * e.g. x201.
3338
         * e.g. x201.
-
 
3339
         */
-
 
3340
		if (IS_IVYBRIDGE(dev))
-
 
3341
			I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
-
 
3342
						 PF_PIPE_SEL_IVB(pipe));
3239
         */
3343
		else
3240
        I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
3344
        I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
3241
        I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
3345
        I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
3242
        I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
3346
        I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
Line 3275... Line 3379...
3275
	 * happening.
3379
	 * happening.
3276
	 */
3380
	 */
3277
	intel_wait_for_vblank(dev, intel_crtc->pipe);
3381
	intel_wait_for_vblank(dev, intel_crtc->pipe);
3278
}
3382
}
Line -... Line 3383...
-
 
3383
 
-
 
3384
static void haswell_crtc_enable(struct drm_crtc *crtc)
-
 
3385
{
-
 
3386
	struct drm_device *dev = crtc->dev;
-
 
3387
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
3388
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
3389
	struct intel_encoder *encoder;
-
 
3390
	int pipe = intel_crtc->pipe;
-
 
3391
	int plane = intel_crtc->plane;
-
 
3392
	bool is_pch_port;
-
 
3393
 
-
 
3394
	WARN_ON(!crtc->enabled);
-
 
3395
 
-
 
3396
	if (intel_crtc->active)
-
 
3397
		return;
-
 
3398
 
-
 
3399
	intel_crtc->active = true;
-
 
3400
	intel_update_watermarks(dev);
-
 
3401
 
-
 
3402
	is_pch_port = haswell_crtc_driving_pch(crtc);
-
 
3403
 
-
 
3404
	if (is_pch_port)
-
 
3405
		dev_priv->display.fdi_link_train(crtc);
-
 
3406
 
-
 
3407
	for_each_encoder_on_crtc(dev, crtc, encoder)
-
 
3408
		if (encoder->pre_enable)
-
 
3409
			encoder->pre_enable(encoder);
-
 
3410
 
-
 
3411
	intel_ddi_enable_pipe_clock(intel_crtc);
-
 
3412
 
-
 
3413
	/* Enable panel fitting for eDP */
-
 
3414
	if (dev_priv->pch_pf_size &&
-
 
3415
	    intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
-
 
3416
		/* Force use of hard-coded filter coefficients
-
 
3417
		 * as some pre-programmed values are broken,
-
 
3418
		 * e.g. x201.
-
 
3419
		 */
-
 
3420
		I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
-
 
3421
					 PF_PIPE_SEL_IVB(pipe));
-
 
3422
		I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
-
 
3423
		I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
-
 
3424
	}
-
 
3425
 
-
 
3426
	/*
-
 
3427
	 * On ILK+ LUT must be loaded before the pipe is running but with
-
 
3428
	 * clocks enabled
-
 
3429
	 */
-
 
3430
	intel_crtc_load_lut(crtc);
-
 
3431
 
-
 
3432
	intel_ddi_set_pipe_settings(crtc);
-
 
3433
	intel_ddi_enable_pipe_func(crtc);
-
 
3434
 
-
 
3435
	intel_enable_pipe(dev_priv, pipe, is_pch_port);
-
 
3436
	intel_enable_plane(dev_priv, plane, pipe);
-
 
3437
 
-
 
3438
	if (is_pch_port)
-
 
3439
		lpt_pch_enable(crtc);
-
 
3440
 
-
 
3441
	mutex_lock(&dev->struct_mutex);
-
 
3442
	intel_update_fbc(dev);
-
 
3443
	mutex_unlock(&dev->struct_mutex);
-
 
3444
 
-
 
3445
//	intel_crtc_update_cursor(crtc, true);
-
 
3446
 
-
 
3447
	for_each_encoder_on_crtc(dev, crtc, encoder)
-
 
3448
		encoder->enable(encoder);
-
 
3449
 
-
 
3450
	/*
-
 
3451
	 * There seems to be a race in PCH platform hw (at least on some
-
 
3452
	 * outputs) where an enabled pipe still completes any pageflip right
-
 
3453
	 * away (as if the pipe is off) instead of waiting for vblank. As soon
-
 
3454
	 * as the first vblank happend, everything works as expected. Hence just
-
 
3455
	 * wait for one vblank before returning to avoid strange things
-
 
3456
	 * happening.
-
 
3457
	 */
-
 
3458
	intel_wait_for_vblank(dev, intel_crtc->pipe);
-
 
3459
}
3279
 
3460
 
3280
static void ironlake_crtc_disable(struct drm_crtc *crtc)
3461
static void ironlake_crtc_disable(struct drm_crtc *crtc)
3281
{
3462
{
3282
    struct drm_device *dev = crtc->dev;
3463
    struct drm_device *dev = crtc->dev;
3283
    struct drm_i915_private *dev_priv = dev->dev_private;
3464
    struct drm_i915_private *dev_priv = dev->dev_private;
Line 3313... Line 3494...
3313
		if (encoder->post_disable)
3494
		if (encoder->post_disable)
3314
			encoder->post_disable(encoder);
3495
			encoder->post_disable(encoder);
Line 3315... Line 3496...
3315
 
3496
 
Line 3316... Line 3497...
3316
    ironlake_fdi_disable(crtc);
3497
    ironlake_fdi_disable(crtc);
Line 3317... Line 3498...
3317
 
3498
 
3318
    intel_disable_transcoder(dev_priv, pipe);
3499
	ironlake_disable_pch_transcoder(dev_priv, pipe);
3319
 
3500
 
3320
    if (HAS_PCH_CPT(dev)) {
3501
    if (HAS_PCH_CPT(dev)) {
Line 3355... Line 3536...
3355
    mutex_lock(&dev->struct_mutex);
3536
    mutex_lock(&dev->struct_mutex);
3356
    intel_update_fbc(dev);
3537
    intel_update_fbc(dev);
3357
    mutex_unlock(&dev->struct_mutex);
3538
    mutex_unlock(&dev->struct_mutex);
3358
}
3539
}
Line -... Line 3540...
-
 
3540
 
-
 
3541
static void haswell_crtc_disable(struct drm_crtc *crtc)
-
 
3542
{
-
 
3543
	struct drm_device *dev = crtc->dev;
-
 
3544
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
3545
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
3546
	struct intel_encoder *encoder;
-
 
3547
	int pipe = intel_crtc->pipe;
-
 
3548
	int plane = intel_crtc->plane;
-
 
3549
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
-
 
3550
	bool is_pch_port;
-
 
3551
 
-
 
3552
	if (!intel_crtc->active)
-
 
3553
		return;
-
 
3554
 
-
 
3555
	is_pch_port = haswell_crtc_driving_pch(crtc);
-
 
3556
 
-
 
3557
	for_each_encoder_on_crtc(dev, crtc, encoder)
-
 
3558
		encoder->disable(encoder);
-
 
3559
 
-
 
3560
 
-
 
3561
	intel_disable_plane(dev_priv, plane, pipe);
-
 
3562
 
-
 
3563
	if (dev_priv->cfb_plane == plane)
-
 
3564
		intel_disable_fbc(dev);
-
 
3565
 
-
 
3566
	intel_disable_pipe(dev_priv, pipe);
-
 
3567
 
-
 
3568
	intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
-
 
3569
 
-
 
3570
	/* Disable PF */
-
 
3571
	I915_WRITE(PF_CTL(pipe), 0);
-
 
3572
	I915_WRITE(PF_WIN_SZ(pipe), 0);
-
 
3573
 
-
 
3574
	intel_ddi_disable_pipe_clock(intel_crtc);
-
 
3575
 
-
 
3576
	for_each_encoder_on_crtc(dev, crtc, encoder)
-
 
3577
		if (encoder->post_disable)
-
 
3578
			encoder->post_disable(encoder);
-
 
3579
 
-
 
3580
	if (is_pch_port) {
-
 
3581
		lpt_disable_pch_transcoder(dev_priv);
-
 
3582
		intel_ddi_fdi_disable(crtc);
-
 
3583
	}
-
 
3584
 
-
 
3585
	intel_crtc->active = false;
-
 
3586
	intel_update_watermarks(dev);
-
 
3587
 
-
 
3588
	mutex_lock(&dev->struct_mutex);
-
 
3589
	intel_update_fbc(dev);
-
 
3590
	mutex_unlock(&dev->struct_mutex);
-
 
3591
}
3359
 
3592
 
3360
static void ironlake_crtc_off(struct drm_crtc *crtc)
3593
static void ironlake_crtc_off(struct drm_crtc *crtc)
3361
{
3594
{
3362
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3595
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
3363
	intel_put_pch_pll(intel_crtc);
3596
	intel_put_pch_pll(intel_crtc);
Line -... Line 3597...
-
 
3597
}
-
 
3598
 
-
 
3599
static void haswell_crtc_off(struct drm_crtc *crtc)
-
 
3600
{
-
 
3601
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
3602
 
-
 
3603
	/* Stop saying we're using TRANSCODER_EDP because some other CRTC might
-
 
3604
	 * start using it. */
-
 
3605
	intel_crtc->cpu_transcoder = intel_crtc->pipe;
-
 
3606
 
-
 
3607
	intel_ddi_put_crtc_pll(crtc);
3364
}
3608
}
3365
 
3609
 
3366
static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
3610
static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
3367
{
3611
{
3368
	if (!enable && intel_crtc->overlay) {
3612
	if (!enable && intel_crtc->overlay) {
Line 3859... Line 4103...
3859
 
4103
 
3860
		if (intel_encoder->type == INTEL_OUTPUT_EDP) {
4104
		if (intel_encoder->type == INTEL_OUTPUT_EDP) {
3861
			/* Use VBT settings if we have an eDP panel */
4105
			/* Use VBT settings if we have an eDP panel */
Line 3862... Line 4106...
3862
			unsigned int edp_bpc = dev_priv->edp.bpp / 3;
4106
			unsigned int edp_bpc = dev_priv->edp.bpp / 3;
3863
 
4107
 
3864
			if (edp_bpc < display_bpc) {
4108
			if (edp_bpc && edp_bpc < display_bpc) {
3865
				DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
4109
				DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
3866
				display_bpc = edp_bpc;
4110
				display_bpc = edp_bpc;
3867
			}
4111
			}
Line 4075... Line 4319...
4075
 
4319
 
4076
static void vlv_update_pll(struct drm_crtc *crtc,
4320
static void vlv_update_pll(struct drm_crtc *crtc,
4077
			   struct drm_display_mode *mode,
4321
			   struct drm_display_mode *mode,
4078
			   struct drm_display_mode *adjusted_mode,
4322
			   struct drm_display_mode *adjusted_mode,
4079
			   intel_clock_t *clock, intel_clock_t *reduced_clock,
4323
			   intel_clock_t *clock, intel_clock_t *reduced_clock,
4080
			   int refclk, int num_connectors)
4324
			   int num_connectors)
4081
{
4325
{
4082
	struct drm_device *dev = crtc->dev;
4326
	struct drm_device *dev = crtc->dev;
4083
	struct drm_i915_private *dev_priv = dev->dev_private;
4327
	struct drm_i915_private *dev_priv = dev->dev_private;
4084
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4328
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4085
	int pipe = intel_crtc->pipe;
4329
	int pipe = intel_crtc->pipe;
4086
	u32 dpll, mdiv, pdiv;
4330
	u32 dpll, mdiv, pdiv;
4087
	u32 bestn, bestm1, bestm2, bestp1, bestp2;
4331
	u32 bestn, bestm1, bestm2, bestp1, bestp2;
-
 
4332
	bool is_sdvo;
-
 
4333
	u32 temp;
-
 
4334
 
-
 
4335
	is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
-
 
4336
		intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
-
 
4337
 
-
 
4338
	dpll = DPLL_VGA_MODE_DIS;
-
 
4339
	dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
-
 
4340
	dpll |= DPLL_REFA_CLK_ENABLE_VLV;
Line 4088... Line 4341...
4088
	bool is_hdmi;
4341
	dpll |= DPLL_INTEGRATED_CLOCK_VLV;
-
 
4342
 
Line 4089... Line 4343...
4089
 
4343
	I915_WRITE(DPLL(pipe), dpll);
4090
	is_hdmi = intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4344
	POSTING_READ(DPLL(pipe));
4091
 
4345
 
4092
	bestn = clock->n;
4346
	bestn = clock->n;
4093
	bestm1 = clock->m1;
4347
	bestm1 = clock->m1;
Line 4094... Line 4348...
4094
	bestm2 = clock->m2;
4348
	bestm2 = clock->m2;
4095
	bestp1 = clock->p1;
4349
	bestp1 = clock->p1;
4096
	bestp2 = clock->p2;
-
 
4097
 
-
 
4098
	/* Enable DPIO clock input */
4350
	bestp2 = clock->p2;
4099
	dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
4351
 
4100
		DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
4352
	/*
4101
	I915_WRITE(DPLL(pipe), dpll);
4353
	 * In Valleyview PLL and program lane counter registers are exposed
4102
	POSTING_READ(DPLL(pipe));
4354
	 * through DPIO interface
4103
 
4355
	 */
4104
	mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
4356
	mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
4105
	mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
4357
	mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
4106
	mdiv |= ((bestn << DPIO_N_SHIFT));
4358
	mdiv |= ((bestn << DPIO_N_SHIFT));
Line 4107... Line 4359...
4107
	mdiv |= (1 << DPIO_POST_DIV_SHIFT);
4359
	mdiv |= (1 << DPIO_POST_DIV_SHIFT);
Line 4108... Line 4360...
4108
	mdiv |= (1 << DPIO_K_SHIFT);
4360
	mdiv |= (1 << DPIO_K_SHIFT);
4109
	mdiv |= DPIO_ENABLE_CALIBRATION;
4361
	mdiv |= DPIO_ENABLE_CALIBRATION;
4110
	intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
4362
	intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
-
 
4363
 
4111
 
4364
	intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
Line 4112... Line 4365...
4112
	intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
4365
 
Line 4113... Line 4366...
4113
 
4366
	pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) |
4114
	pdiv = DPIO_REFSEL_OVERRIDE | (5 << DPIO_PLL_MODESEL_SHIFT) |
4367
		(3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
4115
		(3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
4368
		(7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) |
4116
		(8 << DPIO_DRIVER_CTL_SHIFT) | (5 << DPIO_CLK_BIAS_CTL_SHIFT);
4369
		(5 << DPIO_CLK_BIAS_CTL_SHIFT);
4117
	intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
4370
	intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
Line 4118... Line -...
4118
 
-
 
4119
	intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x009f0051);
4371
 
Line -... Line 4372...
-
 
4372
	intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b);
-
 
4373
 
-
 
4374
	dpll |= DPLL_VCO_ENABLE;
-
 
4375
	I915_WRITE(DPLL(pipe), dpll);
-
 
4376
	POSTING_READ(DPLL(pipe));
-
 
4377
	if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
-
 
4378
		DRM_ERROR("DPLL %d failed to lock\n", pipe);
-
 
4379
 
-
 
4380
	intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
-
 
4381
 
-
 
4382
	if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
-
 
4383
		intel_dp_set_m_n(crtc, mode, adjusted_mode);
4120
 
4384
 
4121
	dpll |= DPLL_VCO_ENABLE;
4385
	I915_WRITE(DPLL(pipe), dpll);
4122
	I915_WRITE(DPLL(pipe), dpll);
4386
 
4123
	POSTING_READ(DPLL(pipe));
4387
	/* Wait for the clocks to stabilize. */
4124
	if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
4388
	POSTING_READ(DPLL(pipe));
4125
		DRM_ERROR("DPLL %d failed to lock\n", pipe);
4389
	udelay(150);
4126
 
4390
 
4127
	if (is_hdmi) {
-
 
Line -... Line 4391...
-
 
4391
	temp = 0;
-
 
4392
	if (is_sdvo) {
-
 
4393
		temp = intel_mode_get_pixel_multiplier(adjusted_mode);
-
 
4394
		if (temp > 1)
-
 
4395
			temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
-
 
4396
		else
-
 
4397
			temp = 0;
4128
		u32 temp = intel_mode_get_pixel_multiplier(adjusted_mode);
4398
	}
-
 
4399
		I915_WRITE(DPLL_MD(pipe), temp);
-
 
4400
		POSTING_READ(DPLL_MD(pipe));
-
 
4401
 
-
 
4402
	/* Now program lane control registers */
-
 
4403
	if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
-
 
4404
			|| intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
-
 
4405
	{
-
 
4406
		temp = 0x1000C4;
4129
 
4407
		if(pipe == 1)
Line 4130... Line 4408...
4130
		if (temp > 1)
4408
			temp |= (1 << 21);
4131
			temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
4409
		intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
4132
		else
4410
	}
Line 4150... Line 4428...
4150
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4428
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4151
	int pipe = intel_crtc->pipe;
4429
	int pipe = intel_crtc->pipe;
4152
	u32 dpll;
4430
	u32 dpll;
4153
	bool is_sdvo;
4431
	bool is_sdvo;
Line -... Line 4432...
-
 
4432
 
-
 
4433
	i9xx_update_pll_dividers(crtc, clock, reduced_clock);
4154
 
4434
 
4155
	is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
4435
	is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
Line 4156... Line 4436...
4156
		intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
4436
		intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
Line 4250... Line 4530...
4250
	}
4530
	}
4251
}
4531
}
Line 4252... Line 4532...
4252
 
4532
 
4253
static void i8xx_update_pll(struct drm_crtc *crtc,
4533
static void i8xx_update_pll(struct drm_crtc *crtc,
4254
			    struct drm_display_mode *adjusted_mode,
4534
			    struct drm_display_mode *adjusted_mode,
4255
			    intel_clock_t *clock,
4535
			    intel_clock_t *clock, intel_clock_t *reduced_clock,
4256
			    int num_connectors)
4536
			    int num_connectors)
4257
{
4537
{
4258
	struct drm_device *dev = crtc->dev;
4538
	struct drm_device *dev = crtc->dev;
4259
	struct drm_i915_private *dev_priv = dev->dev_private;
4539
	struct drm_i915_private *dev_priv = dev->dev_private;
4260
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4540
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4261
	int pipe = intel_crtc->pipe;
4541
	int pipe = intel_crtc->pipe;
Line -... Line 4542...
-
 
4542
	u32 dpll;
-
 
4543
 
4262
	u32 dpll;
4544
	i9xx_update_pll_dividers(crtc, clock, reduced_clock);
Line 4263... Line 4545...
4263
 
4545
 
4264
	dpll = DPLL_VGA_MODE_DIS;
4546
	dpll = DPLL_VGA_MODE_DIS;
4265
 
4547
 
Line 4308... Line 4590...
4308
	 * So write it again.
4590
	 * So write it again.
4309
	 */
4591
	 */
4310
	I915_WRITE(DPLL(pipe), dpll);
4592
	I915_WRITE(DPLL(pipe), dpll);
4311
}
4593
}
Line -... Line 4594...
-
 
4594
 
-
 
4595
static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
-
 
4596
				   struct drm_display_mode *mode,
-
 
4597
				   struct drm_display_mode *adjusted_mode)
-
 
4598
{
-
 
4599
	struct drm_device *dev = intel_crtc->base.dev;
-
 
4600
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
4601
	enum pipe pipe = intel_crtc->pipe;
-
 
4602
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
-
 
4603
	uint32_t vsyncshift;
-
 
4604
 
-
 
4605
	if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
-
 
4606
		/* the chip adds 2 halflines automatically */
-
 
4607
		adjusted_mode->crtc_vtotal -= 1;
-
 
4608
		adjusted_mode->crtc_vblank_end -= 1;
-
 
4609
		vsyncshift = adjusted_mode->crtc_hsync_start
-
 
4610
			     - adjusted_mode->crtc_htotal / 2;
-
 
4611
	} else {
-
 
4612
		vsyncshift = 0;
-
 
4613
	}
-
 
4614
 
-
 
4615
	if (INTEL_INFO(dev)->gen > 3)
-
 
4616
		I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
-
 
4617
 
-
 
4618
	I915_WRITE(HTOTAL(cpu_transcoder),
-
 
4619
		   (adjusted_mode->crtc_hdisplay - 1) |
-
 
4620
		   ((adjusted_mode->crtc_htotal - 1) << 16));
-
 
4621
	I915_WRITE(HBLANK(cpu_transcoder),
-
 
4622
		   (adjusted_mode->crtc_hblank_start - 1) |
-
 
4623
		   ((adjusted_mode->crtc_hblank_end - 1) << 16));
-
 
4624
	I915_WRITE(HSYNC(cpu_transcoder),
-
 
4625
		   (adjusted_mode->crtc_hsync_start - 1) |
-
 
4626
		   ((adjusted_mode->crtc_hsync_end - 1) << 16));
-
 
4627
 
-
 
4628
	I915_WRITE(VTOTAL(cpu_transcoder),
-
 
4629
		   (adjusted_mode->crtc_vdisplay - 1) |
-
 
4630
		   ((adjusted_mode->crtc_vtotal - 1) << 16));
-
 
4631
	I915_WRITE(VBLANK(cpu_transcoder),
-
 
4632
		   (adjusted_mode->crtc_vblank_start - 1) |
-
 
4633
		   ((adjusted_mode->crtc_vblank_end - 1) << 16));
-
 
4634
	I915_WRITE(VSYNC(cpu_transcoder),
-
 
4635
		   (adjusted_mode->crtc_vsync_start - 1) |
-
 
4636
		   ((adjusted_mode->crtc_vsync_end - 1) << 16));
-
 
4637
 
-
 
4638
	/* Workaround: when the EDP input selection is B, the VTOTAL_B must be
-
 
4639
	 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
-
 
4640
	 * documented on the DDI_FUNC_CTL register description, EDP Input Select
-
 
4641
	 * bits. */
-
 
4642
	if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
-
 
4643
	    (pipe == PIPE_B || pipe == PIPE_C))
-
 
4644
		I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
-
 
4645
 
-
 
4646
	/* pipesrc controls the size that is scaled from, which should
-
 
4647
	 * always be the user's requested size.
-
 
4648
	 */
-
 
4649
	I915_WRITE(PIPESRC(pipe),
-
 
4650
		   ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
-
 
4651
}
4312
 
4652
 
4313
static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
4653
static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
4314
			      struct drm_display_mode *mode,
4654
			      struct drm_display_mode *mode,
4315
			      struct drm_display_mode *adjusted_mode,
4655
			      struct drm_display_mode *adjusted_mode,
4316
			      int x, int y,
4656
			      int x, int y,
Line 4321... Line 4661...
4321
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4661
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4322
	int pipe = intel_crtc->pipe;
4662
	int pipe = intel_crtc->pipe;
4323
	int plane = intel_crtc->plane;
4663
	int plane = intel_crtc->plane;
4324
	int refclk, num_connectors = 0;
4664
	int refclk, num_connectors = 0;
4325
	intel_clock_t clock, reduced_clock;
4665
	intel_clock_t clock, reduced_clock;
4326
	u32 dspcntr, pipeconf, vsyncshift;
4666
	u32 dspcntr, pipeconf;
4327
	bool ok, has_reduced_clock = false, is_sdvo = false;
4667
	bool ok, has_reduced_clock = false, is_sdvo = false;
4328
	bool is_lvds = false, is_tv = false, is_dp = false;
4668
	bool is_lvds = false, is_tv = false, is_dp = false;
4329
	struct intel_encoder *encoder;
4669
	struct intel_encoder *encoder;
4330
	const intel_limit_t *limit;
4670
	const intel_limit_t *limit;
4331
	int ret;
4671
	int ret;
Line 4385... Line 4725...
4385
	}
4725
	}
Line 4386... Line 4726...
4386
 
4726
 
4387
	if (is_sdvo && is_tv)
4727
	if (is_sdvo && is_tv)
Line 4388... Line -...
4388
		i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
-
 
4389
 
-
 
4390
	i9xx_update_pll_dividers(crtc, &clock, has_reduced_clock ?
-
 
4391
				 &reduced_clock : NULL);
4728
		i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
4392
 
4729
 
-
 
4730
	if (IS_GEN2(dev))
-
 
4731
		i8xx_update_pll(crtc, adjusted_mode, &clock,
4393
	if (IS_GEN2(dev))
4732
				has_reduced_clock ? &reduced_clock : NULL,
4394
		i8xx_update_pll(crtc, adjusted_mode, &clock, num_connectors);
4733
				num_connectors);
-
 
4734
	else if (IS_VALLEYVIEW(dev))
4395
	else if (IS_VALLEYVIEW(dev))
4735
		vlv_update_pll(crtc, mode, adjusted_mode, &clock,
4396
		vlv_update_pll(crtc, mode,adjusted_mode, &clock, NULL,
4736
				has_reduced_clock ? &reduced_clock : NULL,
4397
			       refclk, num_connectors);
4737
				num_connectors);
4398
	else
4738
	else
4399
		i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
4739
		i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
Line 4433... Line 4773...
4433
				    PIPECONF_DITHER_EN |
4773
				    PIPECONF_DITHER_EN |
4434
				    PIPECONF_DITHER_TYPE_SP;
4774
				    PIPECONF_DITHER_TYPE_SP;
4435
			}
4775
			}
4436
		}
4776
		}
Line -... Line 4777...
-
 
4777
 
-
 
4778
	if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
-
 
4779
		if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
-
 
4780
			pipeconf |= PIPECONF_BPP_6 |
-
 
4781
					PIPECONF_ENABLE |
-
 
4782
					I965_PIPECONF_ACTIVE;
-
 
4783
		}
-
 
4784
	}
4437
 
4785
 
4438
	DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
4786
	DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
Line 4439... Line 4787...
4439
	drm_mode_debug_printmodeline(mode);
4787
	drm_mode_debug_printmodeline(mode);
4440
 
4788
 
Line 4448... Line 4796...
4448
			}
4796
			}
4449
		}
4797
		}
Line 4450... Line 4798...
4450
 
4798
 
4451
	pipeconf &= ~PIPECONF_INTERLACE_MASK;
4799
	pipeconf &= ~PIPECONF_INTERLACE_MASK;
4452
	if (!IS_GEN2(dev) &&
4800
	if (!IS_GEN2(dev) &&
4453
	    adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4801
	    adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
4454
		pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
-
 
4455
		/* the chip adds 2 halflines automatically */
-
 
4456
		adjusted_mode->crtc_vtotal -= 1;
-
 
4457
		adjusted_mode->crtc_vblank_end -= 1;
-
 
4458
		vsyncshift = adjusted_mode->crtc_hsync_start
-
 
4459
			     - adjusted_mode->crtc_htotal/2;
4802
		pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
4460
			} else {
4803
	else
4461
		pipeconf |= PIPECONF_PROGRESSIVE;
-
 
4462
		vsyncshift = 0;
-
 
4463
	}
-
 
4464
 
-
 
4465
	if (!IS_GEN3(dev))
-
 
4466
		I915_WRITE(VSYNCSHIFT(pipe), vsyncshift);
-
 
4467
 
-
 
4468
	I915_WRITE(HTOTAL(pipe),
-
 
4469
		   (adjusted_mode->crtc_hdisplay - 1) |
-
 
4470
		   ((adjusted_mode->crtc_htotal - 1) << 16));
-
 
4471
	I915_WRITE(HBLANK(pipe),
-
 
4472
		   (adjusted_mode->crtc_hblank_start - 1) |
-
 
4473
		   ((adjusted_mode->crtc_hblank_end - 1) << 16));
-
 
4474
	I915_WRITE(HSYNC(pipe),
-
 
4475
		   (adjusted_mode->crtc_hsync_start - 1) |
-
 
Line 4476... Line -...
4476
		   ((adjusted_mode->crtc_hsync_end - 1) << 16));
-
 
4477
 
-
 
4478
	I915_WRITE(VTOTAL(pipe),
4804
		pipeconf |= PIPECONF_PROGRESSIVE;
4479
		   (adjusted_mode->crtc_vdisplay - 1) |
-
 
4480
		   ((adjusted_mode->crtc_vtotal - 1) << 16));
-
 
4481
	I915_WRITE(VBLANK(pipe),
-
 
4482
		   (adjusted_mode->crtc_vblank_start - 1) |
-
 
4483
		   ((adjusted_mode->crtc_vblank_end - 1) << 16));
-
 
4484
	I915_WRITE(VSYNC(pipe),
-
 
Line 4485... Line 4805...
4485
		   (adjusted_mode->crtc_vsync_start - 1) |
4805
 
4486
		   ((adjusted_mode->crtc_vsync_end - 1) << 16));
4806
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
4487
 
4807
 
4488
	/* pipesrc and dspsize control the size that is scaled from,
4808
	/* pipesrc and dspsize control the size that is scaled from,
4489
	 * which should always be the user's requested size.
4809
	 * which should always be the user's requested size.
4490
	 */
4810
	 */
4491
	I915_WRITE(DSPSIZE(plane),
4811
	I915_WRITE(DSPSIZE(plane),
4492
		   ((mode->vdisplay - 1) << 16) |
-
 
4493
		   (mode->hdisplay - 1));
-
 
Line 4494... Line 4812...
4494
	I915_WRITE(DSPPOS(plane), 0);
4812
		   ((mode->vdisplay - 1) << 16) |
4495
	I915_WRITE(PIPESRC(pipe),
4813
		   (mode->hdisplay - 1));
4496
		   ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
4814
	I915_WRITE(DSPPOS(plane), 0);
Line 4509... Line 4827...
4509
	intel_update_watermarks(dev);
4827
	intel_update_watermarks(dev);
Line 4510... Line 4828...
4510
 
4828
 
4511
    return ret;
4829
    return ret;
Line 4512... Line -...
4512
}
-
 
4513
 
-
 
4514
/*
-
 
4515
 * Initialize reference clocks when the driver loads
4830
}
4516
 */
4831
 
4517
void ironlake_init_pch_refclk(struct drm_device *dev)
4832
static void ironlake_init_pch_refclk(struct drm_device *dev)
4518
{
4833
{
4519
	struct drm_i915_private *dev_priv = dev->dev_private;
4834
	struct drm_i915_private *dev_priv = dev->dev_private;
4520
	struct drm_mode_config *mode_config = &dev->mode_config;
4835
	struct drm_mode_config *mode_config = &dev->mode_config;
Line 4626... Line 4941...
4626
		POSTING_READ(PCH_DREF_CONTROL);
4941
		POSTING_READ(PCH_DREF_CONTROL);
4627
		udelay(200);
4942
		udelay(200);
4628
	}
4943
	}
4629
}
4944
}
Line -... Line 4945...
-
 
4945
 
-
 
4946
/* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
-
 
4947
static void lpt_init_pch_refclk(struct drm_device *dev)
-
 
4948
{
-
 
4949
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
4950
	struct drm_mode_config *mode_config = &dev->mode_config;
-
 
4951
	struct intel_encoder *encoder;
-
 
4952
	bool has_vga = false;
-
 
4953
	bool is_sdv = false;
-
 
4954
	u32 tmp;
-
 
4955
 
-
 
4956
	list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
-
 
4957
		switch (encoder->type) {
-
 
4958
		case INTEL_OUTPUT_ANALOG:
-
 
4959
			has_vga = true;
-
 
4960
			break;
-
 
4961
		}
-
 
4962
	}
-
 
4963
 
-
 
4964
	if (!has_vga)
-
 
4965
		return;
-
 
4966
 
-
 
4967
	/* XXX: Rip out SDV support once Haswell ships for real. */
-
 
4968
	if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00)
-
 
4969
		is_sdv = true;
-
 
4970
 
-
 
4971
	tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
-
 
4972
	tmp &= ~SBI_SSCCTL_DISABLE;
-
 
4973
	tmp |= SBI_SSCCTL_PATHALT;
-
 
4974
	intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
-
 
4975
 
-
 
4976
	udelay(24);
-
 
4977
 
-
 
4978
	tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
-
 
4979
	tmp &= ~SBI_SSCCTL_PATHALT;
-
 
4980
	intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
-
 
4981
 
-
 
4982
	if (!is_sdv) {
-
 
4983
		tmp = I915_READ(SOUTH_CHICKEN2);
-
 
4984
		tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
-
 
4985
		I915_WRITE(SOUTH_CHICKEN2, tmp);
-
 
4986
 
-
 
4987
		if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
-
 
4988
				       FDI_MPHY_IOSFSB_RESET_STATUS, 100))
-
 
4989
			DRM_ERROR("FDI mPHY reset assert timeout\n");
-
 
4990
 
-
 
4991
		tmp = I915_READ(SOUTH_CHICKEN2);
-
 
4992
		tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
-
 
4993
		I915_WRITE(SOUTH_CHICKEN2, tmp);
-
 
4994
 
-
 
4995
		if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
-
 
4996
				        FDI_MPHY_IOSFSB_RESET_STATUS) == 0,
-
 
4997
				       100))
-
 
4998
			DRM_ERROR("FDI mPHY reset de-assert timeout\n");
-
 
4999
	}
-
 
5000
 
-
 
5001
	tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
-
 
5002
	tmp &= ~(0xFF << 24);
-
 
5003
	tmp |= (0x12 << 24);
-
 
5004
	intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
-
 
5005
 
-
 
5006
	if (!is_sdv) {
-
 
5007
		tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
-
 
5008
		tmp &= ~(0x3 << 6);
-
 
5009
		tmp |= (1 << 6) | (1 << 0);
-
 
5010
		intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
-
 
5011
	}
-
 
5012
 
-
 
5013
	if (is_sdv) {
-
 
5014
		tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
-
 
5015
		tmp |= 0x7FFF;
-
 
5016
		intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
-
 
5017
	}
-
 
5018
 
-
 
5019
	tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
-
 
5020
	tmp |= (1 << 11);
-
 
5021
	intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
-
 
5022
 
-
 
5023
	tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
-
 
5024
	tmp |= (1 << 11);
-
 
5025
	intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
-
 
5026
 
-
 
5027
	if (is_sdv) {
-
 
5028
		tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY);
-
 
5029
		tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
-
 
5030
		intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY);
-
 
5031
 
-
 
5032
		tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY);
-
 
5033
		tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
-
 
5034
		intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY);
-
 
5035
 
-
 
5036
		tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY);
-
 
5037
		tmp |= (0x3F << 8);
-
 
5038
		intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY);
-
 
5039
 
-
 
5040
		tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY);
-
 
5041
		tmp |= (0x3F << 8);
-
 
5042
		intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY);
-
 
5043
	}
-
 
5044
 
-
 
5045
	tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
-
 
5046
	tmp |= (1 << 24) | (1 << 21) | (1 << 18);
-
 
5047
	intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
-
 
5048
 
-
 
5049
	tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
-
 
5050
	tmp |= (1 << 24) | (1 << 21) | (1 << 18);
-
 
5051
	intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
-
 
5052
 
-
 
5053
	if (!is_sdv) {
-
 
5054
		tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
-
 
5055
		tmp &= ~(7 << 13);
-
 
5056
		tmp |= (5 << 13);
-
 
5057
		intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
-
 
5058
 
-
 
5059
		tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
-
 
5060
		tmp &= ~(7 << 13);
-
 
5061
		tmp |= (5 << 13);
-
 
5062
		intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
-
 
5063
	}
-
 
5064
 
-
 
5065
	tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
-
 
5066
	tmp &= ~0xFF;
-
 
5067
	tmp |= 0x1C;
-
 
5068
	intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
-
 
5069
 
-
 
5070
	tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
-
 
5071
	tmp &= ~0xFF;
-
 
5072
	tmp |= 0x1C;
-
 
5073
	intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
-
 
5074
 
-
 
5075
	tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
-
 
5076
	tmp &= ~(0xFF << 16);
-
 
5077
	tmp |= (0x1C << 16);
-
 
5078
	intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
-
 
5079
 
-
 
5080
	tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
-
 
5081
	tmp &= ~(0xFF << 16);
-
 
5082
	tmp |= (0x1C << 16);
-
 
5083
	intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
-
 
5084
 
-
 
5085
	if (!is_sdv) {
-
 
5086
		tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
-
 
5087
		tmp |= (1 << 27);
-
 
5088
		intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
-
 
5089
 
-
 
5090
		tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
-
 
5091
		tmp |= (1 << 27);
-
 
5092
		intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
-
 
5093
 
-
 
5094
		tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
-
 
5095
		tmp &= ~(0xF << 28);
-
 
5096
		tmp |= (4 << 28);
-
 
5097
		intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
-
 
5098
 
-
 
5099
		tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
-
 
5100
		tmp &= ~(0xF << 28);
-
 
5101
		tmp |= (4 << 28);
-
 
5102
		intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
-
 
5103
	}
-
 
5104
 
-
 
5105
	/* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
-
 
5106
	tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK);
-
 
5107
	tmp |= SBI_DBUFF0_ENABLE;
-
 
5108
	intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK);
-
 
5109
}
-
 
5110
 
-
 
5111
/*
-
 
5112
 * Initialize reference clocks when the driver loads
-
 
5113
 */
-
 
5114
void intel_init_pch_refclk(struct drm_device *dev)
-
 
5115
{
-
 
5116
	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
-
 
5117
		ironlake_init_pch_refclk(dev);
-
 
5118
	else if (HAS_PCH_LPT(dev))
-
 
5119
		lpt_init_pch_refclk(dev);
-
 
5120
}
4630
 
5121
 
4631
static int ironlake_get_refclk(struct drm_crtc *crtc)
5122
static int ironlake_get_refclk(struct drm_crtc *crtc)
4632
{
5123
{
4633
	struct drm_device *dev = crtc->dev;
5124
	struct drm_device *dev = crtc->dev;
4634
	struct drm_i915_private *dev_priv = dev->dev_private;
5125
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 4682... Line 5173...
4682
		break;
5173
		break;
4683
	case 36:
5174
	case 36:
4684
		val |= PIPE_12BPC;
5175
		val |= PIPE_12BPC;
4685
		break;
5176
		break;
4686
	default:
5177
	default:
4687
		val |= PIPE_8BPC;
5178
		/* Case prevented by intel_choose_pipe_bpp_dither. */
4688
		break;
5179
		BUG();
4689
	}
5180
	}
Line 4690... Line 5181...
4690
 
5181
 
4691
	val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
5182
	val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
4692
	if (dither)
5183
	if (dither)
Line 4700... Line 5191...
4700
 
5191
 
4701
	I915_WRITE(PIPECONF(pipe), val);
5192
	I915_WRITE(PIPECONF(pipe), val);
4702
	POSTING_READ(PIPECONF(pipe));
5193
	POSTING_READ(PIPECONF(pipe));
Line -... Line 5194...
-
 
5194
}
-
 
5195
 
-
 
5196
static void haswell_set_pipeconf(struct drm_crtc *crtc,
-
 
5197
				 struct drm_display_mode *adjusted_mode,
-
 
5198
				 bool dither)
-
 
5199
{
-
 
5200
	struct drm_i915_private *dev_priv = crtc->dev->dev_private;
-
 
5201
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5202
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
-
 
5203
	uint32_t val;
-
 
5204
 
-
 
5205
	val = I915_READ(PIPECONF(cpu_transcoder));
-
 
5206
 
-
 
5207
	val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
-
 
5208
	if (dither)
-
 
5209
		val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
-
 
5210
 
-
 
5211
	val &= ~PIPECONF_INTERLACE_MASK_HSW;
-
 
5212
	if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
-
 
5213
		val |= PIPECONF_INTERLACED_ILK;
-
 
5214
	else
-
 
5215
		val |= PIPECONF_PROGRESSIVE;
-
 
5216
 
-
 
5217
	I915_WRITE(PIPECONF(cpu_transcoder), val);
-
 
5218
	POSTING_READ(PIPECONF(cpu_transcoder));
4703
}
5219
}
4704
 
5220
 
4705
static bool ironlake_compute_clocks(struct drm_crtc *crtc,
5221
static bool ironlake_compute_clocks(struct drm_crtc *crtc,
4706
				    struct drm_display_mode *adjusted_mode,
5222
				    struct drm_display_mode *adjusted_mode,
4707
				    intel_clock_t *clock,
5223
				    intel_clock_t *clock,
Line 4763... Line 5279...
4763
		i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
5279
		i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
Line 4764... Line 5280...
4764
 
5280
 
4765
	return true;
5281
	return true;
Line -... Line 5282...
-
 
5282
}
-
 
5283
 
-
 
5284
static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
-
 
5285
{
-
 
5286
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5287
	uint32_t temp;
-
 
5288
 
-
 
5289
	temp = I915_READ(SOUTH_CHICKEN1);
-
 
5290
	if (temp & FDI_BC_BIFURCATION_SELECT)
-
 
5291
		return;
-
 
5292
 
-
 
5293
	WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
-
 
5294
	WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
-
 
5295
 
-
 
5296
	temp |= FDI_BC_BIFURCATION_SELECT;
-
 
5297
	DRM_DEBUG_KMS("enabling fdi C rx\n");
-
 
5298
	I915_WRITE(SOUTH_CHICKEN1, temp);
-
 
5299
	POSTING_READ(SOUTH_CHICKEN1);
-
 
5300
}
-
 
5301
 
-
 
5302
static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
-
 
5303
{
-
 
5304
	struct drm_device *dev = intel_crtc->base.dev;
-
 
5305
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5306
	struct intel_crtc *pipe_B_crtc =
-
 
5307
		to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
-
 
5308
 
-
 
5309
	DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
-
 
5310
		      intel_crtc->pipe, intel_crtc->fdi_lanes);
-
 
5311
	if (intel_crtc->fdi_lanes > 4) {
-
 
5312
		DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
-
 
5313
			      intel_crtc->pipe, intel_crtc->fdi_lanes);
-
 
5314
		/* Clamp lanes to avoid programming the hw with bogus values. */
-
 
5315
		intel_crtc->fdi_lanes = 4;
-
 
5316
 
-
 
5317
		return false;
-
 
5318
	}
-
 
5319
 
-
 
5320
	if (dev_priv->num_pipe == 2)
-
 
5321
		return true;
-
 
5322
 
-
 
5323
	switch (intel_crtc->pipe) {
-
 
5324
	case PIPE_A:
-
 
5325
		return true;
-
 
5326
	case PIPE_B:
-
 
5327
		if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
-
 
5328
		    intel_crtc->fdi_lanes > 2) {
-
 
5329
			DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
-
 
5330
				      intel_crtc->pipe, intel_crtc->fdi_lanes);
-
 
5331
			/* Clamp lanes to avoid programming the hw with bogus values. */
-
 
5332
			intel_crtc->fdi_lanes = 2;
-
 
5333
 
-
 
5334
			return false;
-
 
5335
		}
-
 
5336
 
-
 
5337
		if (intel_crtc->fdi_lanes > 2)
-
 
5338
			WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
-
 
5339
		else
-
 
5340
			cpt_enable_fdi_bc_bifurcation(dev);
-
 
5341
 
-
 
5342
		return true;
-
 
5343
	case PIPE_C:
-
 
5344
		if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
-
 
5345
			if (intel_crtc->fdi_lanes > 2) {
-
 
5346
				DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
-
 
5347
					      intel_crtc->pipe, intel_crtc->fdi_lanes);
-
 
5348
				/* Clamp lanes to avoid programming the hw with bogus values. */
-
 
5349
				intel_crtc->fdi_lanes = 2;
-
 
5350
 
-
 
5351
				return false;
-
 
5352
			}
-
 
5353
		} else {
-
 
5354
			DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
-
 
5355
			return false;
-
 
5356
		}
-
 
5357
 
-
 
5358
		cpt_enable_fdi_bc_bifurcation(dev);
-
 
5359
 
-
 
5360
		return true;
-
 
5361
	default:
-
 
5362
		BUG();
-
 
5363
	}
-
 
5364
}
-
 
5365
 
-
 
5366
int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
-
 
5367
{
-
 
5368
	/*
-
 
5369
	 * Account for spread spectrum to avoid
-
 
5370
	 * oversubscribing the link. Max center spread
-
 
5371
	 * is 2.5%; use 5% for safety's sake.
-
 
5372
	 */
-
 
5373
	u32 bps = target_clock * bpp * 21 / 20;
-
 
5374
	return bps / (link_bw * 8) + 1;
4766
}
5375
}
4767
 
5376
 
4768
static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
5377
static void ironlake_set_m_n(struct drm_crtc *crtc,
4769
                  struct drm_display_mode *mode,
-
 
4770
                  struct drm_display_mode *adjusted_mode,
-
 
4771
                  int x, int y,
5378
                  struct drm_display_mode *mode,
4772
				  struct drm_framebuffer *fb)
5379
			     struct drm_display_mode *adjusted_mode)
4773
{
5380
{
4774
    struct drm_device *dev = crtc->dev;
5381
    struct drm_device *dev = crtc->dev;
4775
    struct drm_i915_private *dev_priv = dev->dev_private;
-
 
4776
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5382
    struct drm_i915_private *dev_priv = dev->dev_private;
4777
    int pipe = intel_crtc->pipe;
-
 
4778
    int plane = intel_crtc->plane;
-
 
4779
	int num_connectors = 0;
-
 
4780
    intel_clock_t clock, reduced_clock;
-
 
4781
	u32 dpll, fp = 0, fp2 = 0;
-
 
4782
    bool ok, has_reduced_clock = false, is_sdvo = false;
5383
    struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4783
    bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
-
 
4784
	struct intel_encoder *encoder, *edp_encoder = NULL;
5384
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
4785
    int ret;
-
 
4786
    struct fdi_m_n m_n = {0};
5385
	struct intel_encoder *intel_encoder, *edp_encoder = NULL;
4787
    u32 temp;
-
 
4788
    int target_clock, pixel_multiplier, lane, link_bw, factor;
-
 
4789
    unsigned int pipe_bpp;
5386
    struct fdi_m_n m_n = {0};
Line 4790... Line 5387...
4790
    bool dither;
5387
	int target_clock, pixel_multiplier, lane, link_bw;
4791
	bool is_cpu_edp = false, is_pch_edp = false;
5388
	bool is_dp = false, is_cpu_edp = false;
4792
 
-
 
4793
	for_each_encoder_on_crtc(dev, crtc, encoder) {
-
 
4794
        switch (encoder->type) {
-
 
4795
        case INTEL_OUTPUT_LVDS:
-
 
4796
            is_lvds = true;
-
 
4797
            break;
-
 
4798
        case INTEL_OUTPUT_SDVO:
-
 
4799
        case INTEL_OUTPUT_HDMI:
-
 
4800
            is_sdvo = true;
-
 
4801
            if (encoder->needs_tv_clock)
-
 
4802
                is_tv = true;
-
 
4803
            break;
-
 
4804
        case INTEL_OUTPUT_TVOUT:
-
 
4805
            is_tv = true;
-
 
4806
            break;
-
 
4807
        case INTEL_OUTPUT_ANALOG:
5389
 
4808
            is_crt = true;
5390
	for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
4809
            break;
5391
		switch (intel_encoder->type) {
4810
        case INTEL_OUTPUT_DISPLAYPORT:
5392
        case INTEL_OUTPUT_DISPLAYPORT:
4811
            is_dp = true;
5393
            is_dp = true;
4812
            break;
5394
            break;
4813
        case INTEL_OUTPUT_EDP:
-
 
4814
			is_dp = true;
-
 
4815
			if (intel_encoder_is_pch_edp(&encoder->base))
5395
        case INTEL_OUTPUT_EDP:
4816
				is_pch_edp = true;
5396
			is_dp = true;
4817
			else
5397
			if (!intel_encoder_is_pch_edp(&intel_encoder->base))
4818
				is_cpu_edp = true;
5398
				is_cpu_edp = true;
4819
			edp_encoder = encoder;
-
 
4820
            break;
-
 
4821
        }
-
 
4822
 
-
 
4823
        num_connectors++;
-
 
4824
    }
-
 
4825
 
-
 
4826
	ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
-
 
4827
				     &has_reduced_clock, &reduced_clock);
-
 
4828
    if (!ok) {
5399
			edp_encoder = intel_encoder;
Line 4829... Line -...
4829
        DRM_ERROR("Couldn't find PLL settings for mode!\n");
-
 
4830
        return -EINVAL;
-
 
4831
    }
-
 
4832
 
5400
            break;
4833
    /* Ensure that the cursor is valid for the new mode before changing... */
5401
        }
4834
//    intel_crtc_update_cursor(crtc, true);
5402
    }
4835
 
5403
 
4836
    /* FDI link */
5404
    /* FDI link */
Line 4857... Line 5425...
4857
	else if (is_dp)
5425
	else if (is_dp)
4858
		target_clock = mode->clock;
5426
		target_clock = mode->clock;
4859
	else
5427
	else
4860
		target_clock = adjusted_mode->clock;
5428
		target_clock = adjusted_mode->clock;
Line 4861... Line -...
4861
 
-
 
4862
    /* determine panel color depth */
-
 
4863
	dither = intel_choose_pipe_bpp_dither(crtc, fb, &pipe_bpp,
-
 
4864
					      adjusted_mode);
-
 
4865
	if (is_lvds && dev_priv->lvds_dither)
-
 
4866
		dither = true;
-
 
4867
 
-
 
4868
	if (pipe_bpp != 18 && pipe_bpp != 24 && pipe_bpp != 30 &&
-
 
4869
	    pipe_bpp != 36) {
-
 
4870
        WARN(1, "intel_choose_pipe_bpp returned invalid value %d\n",
-
 
4871
            pipe_bpp);
-
 
4872
        pipe_bpp = 24;
-
 
4873
    }
-
 
4874
    intel_crtc->bpp = pipe_bpp;
-
 
4875
 
5429
 
4876
    if (!lane) {
-
 
4877
        /*
-
 
4878
         * Account for spread spectrum to avoid
5430
	if (!lane)
4879
         * oversubscribing the link. Max center spread
-
 
4880
         * is 2.5%; use 5% for safety's sake.
-
 
4881
         */
5431
		lane = ironlake_get_lanes_required(target_clock, link_bw,
4882
        u32 bps = target_clock * intel_crtc->bpp * 21 / 20;
-
 
4883
        lane = bps / (link_bw * 8) + 1;
-
 
Line 4884... Line 5432...
4884
    }
5432
						   intel_crtc->bpp);
Line 4885... Line 5433...
4885
 
5433
 
4886
    intel_crtc->fdi_lanes = lane;
5434
    intel_crtc->fdi_lanes = lane;
4887
 
5435
 
4888
    if (pixel_multiplier > 1)
5436
    if (pixel_multiplier > 1)
Line -... Line 5437...
-
 
5437
        link_bw *= pixel_multiplier;
-
 
5438
    ironlake_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw,
-
 
5439
                 &m_n);
-
 
5440
 
-
 
5441
	I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
-
 
5442
	I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
-
 
5443
	I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
-
 
5444
	I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
4889
        link_bw *= pixel_multiplier;
5445
}
-
 
5446
 
-
 
5447
static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
-
 
5448
				      struct drm_display_mode *adjusted_mode,
-
 
5449
				      intel_clock_t *clock, u32 fp)
-
 
5450
{
-
 
5451
	struct drm_crtc *crtc = &intel_crtc->base;
-
 
5452
	struct drm_device *dev = crtc->dev;
-
 
5453
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5454
	struct intel_encoder *intel_encoder;
-
 
5455
	uint32_t dpll;
-
 
5456
	int factor, pixel_multiplier, num_connectors = 0;
-
 
5457
	bool is_lvds = false, is_sdvo = false, is_tv = false;
-
 
5458
	bool is_dp = false, is_cpu_edp = false;
-
 
5459
 
-
 
5460
	for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-
 
5461
		switch (intel_encoder->type) {
-
 
5462
		case INTEL_OUTPUT_LVDS:
-
 
5463
			is_lvds = true;
4890
    ironlake_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw,
5464
			break;
-
 
5465
		case INTEL_OUTPUT_SDVO:
-
 
5466
		case INTEL_OUTPUT_HDMI:
-
 
5467
			is_sdvo = true;
-
 
5468
			if (intel_encoder->needs_tv_clock)
-
 
5469
				is_tv = true;
-
 
5470
			break;
-
 
5471
		case INTEL_OUTPUT_TVOUT:
-
 
5472
			is_tv = true;
-
 
5473
			break;
-
 
5474
		case INTEL_OUTPUT_DISPLAYPORT:
4891
                 &m_n);
5475
			is_dp = true;
4892
 
5476
			break;
-
 
5477
		case INTEL_OUTPUT_EDP:
-
 
5478
			is_dp = true;
-
 
5479
			if (!intel_encoder_is_pch_edp(&intel_encoder->base))
-
 
5480
				is_cpu_edp = true;
-
 
5481
			break;
Line 4893... Line 5482...
4893
    fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
5482
		}
4894
    if (has_reduced_clock)
5483
 
4895
        fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
5484
		num_connectors++;
4896
            reduced_clock.m2;
5485
	}
Line 4903... Line 5492...
4903
            (I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP)
5492
            (I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP)
4904
            factor = 25;
5493
            factor = 25;
4905
    } else if (is_sdvo && is_tv)
5494
    } else if (is_sdvo && is_tv)
4906
        factor = 20;
5495
        factor = 20;
Line 4907... Line 5496...
4907
 
5496
 
4908
    if (clock.m < factor * clock.n)
5497
	if (clock->m < factor * clock->n)
Line 4909... Line 5498...
4909
        fp |= FP_CB_TUNE;
5498
        fp |= FP_CB_TUNE;
Line 4910... Line 5499...
4910
 
5499
 
4911
    dpll = 0;
5500
    dpll = 0;
4912
 
5501
 
4913
    if (is_lvds)
5502
    if (is_lvds)
4914
        dpll |= DPLLB_MODE_LVDS;
5503
        dpll |= DPLLB_MODE_LVDS;
4915
    else
5504
    else
4916
        dpll |= DPLLB_MODE_DAC_SERIAL;
5505
        dpll |= DPLLB_MODE_DAC_SERIAL;
4917
    if (is_sdvo) {
5506
    if (is_sdvo) {
4918
        int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
5507
		pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
4919
        if (pixel_multiplier > 1) {
5508
        if (pixel_multiplier > 1) {
4920
            dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
5509
            dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
4921
        }
5510
        }
4922
        dpll |= DPLL_DVO_HIGH_SPEED;
5511
        dpll |= DPLL_DVO_HIGH_SPEED;
Line 4923... Line 5512...
4923
    }
5512
    }
4924
	if (is_dp && !is_cpu_edp)
5513
	if (is_dp && !is_cpu_edp)
4925
        dpll |= DPLL_DVO_HIGH_SPEED;
5514
        dpll |= DPLL_DVO_HIGH_SPEED;
4926
 
5515
 
Line 4927... Line 5516...
4927
    /* compute bitmask from p1 value */
5516
    /* compute bitmask from p1 value */
4928
    dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
5517
	dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
4929
    /* also FPA1 */
5518
    /* also FPA1 */
4930
    dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
5519
	dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
4931
 
5520
 
4932
    switch (clock.p2) {
5521
	switch (clock->p2) {
Line 4953... Line 5542...
4953
    else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
5542
    else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
4954
        dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
5543
        dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
4955
    else
5544
    else
4956
        dpll |= PLL_REF_INPUT_DREFCLK;
5545
        dpll |= PLL_REF_INPUT_DREFCLK;
Line -... Line 5546...
-
 
5546
 
-
 
5547
	return dpll;
-
 
5548
}
-
 
5549
 
-
 
5550
static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
-
 
5551
				  struct drm_display_mode *mode,
-
 
5552
				  struct drm_display_mode *adjusted_mode,
-
 
5553
				  int x, int y,
-
 
5554
				  struct drm_framebuffer *fb)
-
 
5555
{
-
 
5556
	struct drm_device *dev = crtc->dev;
-
 
5557
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5558
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5559
	int pipe = intel_crtc->pipe;
-
 
5560
	int plane = intel_crtc->plane;
-
 
5561
	int num_connectors = 0;
-
 
5562
	intel_clock_t clock, reduced_clock;
-
 
5563
	u32 dpll, fp = 0, fp2 = 0;
-
 
5564
	bool ok, has_reduced_clock = false;
-
 
5565
	bool is_lvds = false, is_dp = false, is_cpu_edp = false;
-
 
5566
	struct intel_encoder *encoder;
-
 
5567
	u32 temp;
-
 
5568
	int ret;
-
 
5569
	bool dither, fdi_config_ok;
-
 
5570
 
-
 
5571
	for_each_encoder_on_crtc(dev, crtc, encoder) {
-
 
5572
		switch (encoder->type) {
-
 
5573
		case INTEL_OUTPUT_LVDS:
-
 
5574
			is_lvds = true;
-
 
5575
			break;
-
 
5576
		case INTEL_OUTPUT_DISPLAYPORT:
-
 
5577
			is_dp = true;
-
 
5578
			break;
-
 
5579
		case INTEL_OUTPUT_EDP:
-
 
5580
			is_dp = true;
-
 
5581
			if (!intel_encoder_is_pch_edp(&encoder->base))
-
 
5582
				is_cpu_edp = true;
-
 
5583
			break;
-
 
5584
		}
-
 
5585
 
-
 
5586
		num_connectors++;
-
 
5587
	}
-
 
5588
 
-
 
5589
	WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
-
 
5590
	     "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
-
 
5591
 
-
 
5592
	ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
-
 
5593
				     &has_reduced_clock, &reduced_clock);
-
 
5594
	if (!ok) {
-
 
5595
		DRM_ERROR("Couldn't find PLL settings for mode!\n");
-
 
5596
		return -EINVAL;
-
 
5597
	}
-
 
5598
 
-
 
5599
	/* Ensure that the cursor is valid for the new mode before changing... */
-
 
5600
//	intel_crtc_update_cursor(crtc, true);
-
 
5601
 
-
 
5602
	/* determine panel color depth */
-
 
5603
	dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
-
 
5604
					      adjusted_mode);
-
 
5605
	if (is_lvds && dev_priv->lvds_dither)
-
 
5606
		dither = true;
-
 
5607
 
-
 
5608
	fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
-
 
5609
	if (has_reduced_clock)
-
 
5610
		fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
-
 
5611
			reduced_clock.m2;
-
 
5612
 
-
 
5613
	dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
4957
 
5614
 
4958
	DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
5615
	DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
Line 4959... Line 5616...
4959
    drm_mode_debug_printmodeline(mode);
5616
    drm_mode_debug_printmodeline(mode);
4960
 
-
 
4961
	/* CPU eDP is the only output that doesn't need a PCH PLL of its own on
-
 
4962
	 * pre-Haswell/LPT generation */
-
 
4963
	if (HAS_PCH_LPT(dev)) {
-
 
4964
		DRM_DEBUG_KMS("LPT detected: no PLL for pipe %d necessary\n",
5617
 
4965
				pipe);
5618
	/* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
Line 4966... Line 5619...
4966
	} else if (!is_cpu_edp) {
5619
	if (!is_cpu_edp) {
4967
		struct intel_pch_pll *pll;
5620
		struct intel_pch_pll *pll;
4968
 
5621
 
Line 5047... Line 5700...
5047
    } else {
5700
    } else {
5048
			I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
5701
			I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
5049
    }
5702
    }
5050
	}
5703
	}
Line -... Line 5704...
-
 
5704
 
-
 
5705
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
-
 
5706
 
-
 
5707
	/* Note, this also computes intel_crtc->fdi_lanes which is used below in
-
 
5708
	 * ironlake_check_fdi_lanes. */
-
 
5709
	ironlake_set_m_n(crtc, mode, adjusted_mode);
-
 
5710
 
-
 
5711
	fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
-
 
5712
 
-
 
5713
	if (is_cpu_edp)
-
 
5714
		ironlake_set_pll_edp(crtc, adjusted_mode->clock);
5051
 
5715
 
-
 
5716
	ironlake_set_pipeconf(crtc, adjusted_mode, dither);
-
 
5717
 
-
 
5718
	intel_wait_for_vblank(dev, pipe);
5052
    if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
5719
 
-
 
5720
	/* Set up the display plane register */
-
 
5721
	I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
-
 
5722
	POSTING_READ(DSPCNTR(plane));
5053
        /* the chip adds 2 halflines automatically */
5723
 
-
 
5724
	ret = intel_pipe_set_base(crtc, x, y, fb);
-
 
5725
 
-
 
5726
	intel_update_watermarks(dev);
-
 
5727
 
-
 
5728
	intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
-
 
5729
 
-
 
5730
	return fdi_config_ok ? ret : -EINVAL;
-
 
5731
}
-
 
5732
 
5054
        adjusted_mode->crtc_vtotal -= 1;
5733
static int haswell_crtc_mode_set(struct drm_crtc *crtc,
-
 
5734
				 struct drm_display_mode *mode,
-
 
5735
				 struct drm_display_mode *adjusted_mode,
-
 
5736
				 int x, int y,
-
 
5737
				 struct drm_framebuffer *fb)
-
 
5738
{
-
 
5739
	struct drm_device *dev = crtc->dev;
-
 
5740
	struct drm_i915_private *dev_priv = dev->dev_private;
5055
        adjusted_mode->crtc_vblank_end -= 1;
5741
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5742
	int pipe = intel_crtc->pipe;
-
 
5743
	int plane = intel_crtc->plane;
-
 
5744
	int num_connectors = 0;
-
 
5745
	intel_clock_t clock, reduced_clock;
-
 
5746
	u32 dpll = 0, fp = 0, fp2 = 0;
-
 
5747
	bool ok, has_reduced_clock = false;
-
 
5748
	bool is_lvds = false, is_dp = false, is_cpu_edp = false;
-
 
5749
	struct intel_encoder *encoder;
-
 
5750
	u32 temp;
-
 
5751
	int ret;
-
 
5752
	bool dither;
-
 
5753
 
-
 
5754
	for_each_encoder_on_crtc(dev, crtc, encoder) {
-
 
5755
		switch (encoder->type) {
-
 
5756
		case INTEL_OUTPUT_LVDS:
-
 
5757
			is_lvds = true;
-
 
5758
			break;
-
 
5759
		case INTEL_OUTPUT_DISPLAYPORT:
-
 
5760
			is_dp = true;
-
 
5761
			break;
-
 
5762
		case INTEL_OUTPUT_EDP:
5056
		I915_WRITE(VSYNCSHIFT(pipe),
5763
			is_dp = true;
-
 
5764
			if (!intel_encoder_is_pch_edp(&encoder->base))
-
 
5765
				is_cpu_edp = true;
-
 
5766
			break;
-
 
5767
		}
-
 
5768
 
-
 
5769
		num_connectors++;
-
 
5770
	}
-
 
5771
 
-
 
5772
	if (is_cpu_edp)
-
 
5773
		intel_crtc->cpu_transcoder = TRANSCODER_EDP;
-
 
5774
	else
-
 
5775
		intel_crtc->cpu_transcoder = pipe;
-
 
5776
 
-
 
5777
	/* We are not sure yet this won't happen. */
-
 
5778
	WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
-
 
5779
	     INTEL_PCH_TYPE(dev));
-
 
5780
 
-
 
5781
	WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
-
 
5782
	     num_connectors, pipe_name(pipe));
-
 
5783
 
-
 
5784
	WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
-
 
5785
		(PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
-
 
5786
 
-
 
5787
	WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
-
 
5788
 
-
 
5789
	if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock))
-
 
5790
		return -EINVAL;
-
 
5791
 
-
 
5792
	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
-
 
5793
		ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
-
 
5794
					     &has_reduced_clock,
-
 
5795
					     &reduced_clock);
-
 
5796
		if (!ok) {
-
 
5797
			DRM_ERROR("Couldn't find PLL settings for mode!\n");
-
 
5798
			return -EINVAL;
-
 
5799
		}
-
 
5800
	}
-
 
5801
 
-
 
5802
	/* Ensure that the cursor is valid for the new mode before changing... */
-
 
5803
//   intel_crtc_update_cursor(crtc, true);
-
 
5804
 
-
 
5805
	/* determine panel color depth */
5057
			   adjusted_mode->crtc_hsync_start
5806
	dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
-
 
5807
					      adjusted_mode);
-
 
5808
	if (is_lvds && dev_priv->lvds_dither)
-
 
5809
		dither = true;
-
 
5810
 
-
 
5811
	DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
-
 
5812
	drm_mode_debug_printmodeline(mode);
-
 
5813
 
-
 
5814
	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
-
 
5815
		fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
-
 
5816
		if (has_reduced_clock)
-
 
5817
			fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
-
 
5818
			      reduced_clock.m2;
-
 
5819
 
-
 
5820
		dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock,
-
 
5821
					     fp);
-
 
5822
 
-
 
5823
		/* CPU eDP is the only output that doesn't need a PCH PLL of its
-
 
5824
		 * own on pre-Haswell/LPT generation */
-
 
5825
		if (!is_cpu_edp) {
-
 
5826
			struct intel_pch_pll *pll;
-
 
5827
 
-
 
5828
			pll = intel_get_pch_pll(intel_crtc, dpll, fp);
-
 
5829
			if (pll == NULL) {
-
 
5830
				DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
-
 
5831
						 pipe);
-
 
5832
				return -EINVAL;
-
 
5833
			}
-
 
5834
		} else
-
 
5835
			intel_put_pch_pll(intel_crtc);
-
 
5836
 
-
 
5837
		/* The LVDS pin pair needs to be on before the DPLLs are
-
 
5838
		 * enabled.  This is an exception to the general rule that
-
 
5839
		 * mode_set doesn't turn things on.
-
 
5840
		 */
-
 
5841
		if (is_lvds) {
-
 
5842
			temp = I915_READ(PCH_LVDS);
-
 
5843
			temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
-
 
5844
			if (HAS_PCH_CPT(dev)) {
-
 
5845
				temp &= ~PORT_TRANS_SEL_MASK;
5058
			   - adjusted_mode->crtc_htotal/2);
5846
				temp |= PORT_TRANS_SEL_CPT(pipe);
-
 
5847
	} else {
-
 
5848
				if (pipe == 1)
-
 
5849
					temp |= LVDS_PIPEB_SELECT;
5059
	} else {
5850
				else
5060
		I915_WRITE(VSYNCSHIFT(pipe), 0);
5851
					temp &= ~LVDS_PIPEB_SELECT;
Line 5061... Line 5852...
5061
	}
5852
			}
5062
 
5853
 
5063
    I915_WRITE(HTOTAL(pipe),
5854
			/* set the corresponsding LVDS_BORDER bit */
5064
           (adjusted_mode->crtc_hdisplay - 1) |
5855
			temp |= dev_priv->lvds_border_bits;
-
 
5856
			/* Set the B0-B3 data pairs corresponding to whether
-
 
5857
			 * we're going to set the DPLLs for dual-channel mode or
5065
           ((adjusted_mode->crtc_htotal - 1) << 16));
5858
			 * not.
5066
    I915_WRITE(HBLANK(pipe),
5859
			 */
5067
           (adjusted_mode->crtc_hblank_start - 1) |
5860
			if (clock.p2 == 7)
5068
           ((adjusted_mode->crtc_hblank_end - 1) << 16));
5861
				temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
5069
    I915_WRITE(HSYNC(pipe),
5862
			else
Line 5070... Line 5863...
5070
           (adjusted_mode->crtc_hsync_start - 1) |
5863
				temp &= ~(LVDS_B0B3_POWER_UP |
5071
           ((adjusted_mode->crtc_hsync_end - 1) << 16));
5864
					  LVDS_CLKB_POWER_UP);
5072
 
5865
 
5073
    I915_WRITE(VTOTAL(pipe),
5866
			/* It would be nice to set 24 vs 18-bit mode
-
 
5867
			 * (LVDS_A3_POWER_UP) appropriately here, but we need to
5074
           (adjusted_mode->crtc_vdisplay - 1) |
5868
			 * look more thoroughly into how panels behave in the
5075
           ((adjusted_mode->crtc_vtotal - 1) << 16));
5869
			 * two modes.
5076
    I915_WRITE(VBLANK(pipe),
5870
			 */
5077
           (adjusted_mode->crtc_vblank_start - 1) |
5871
			temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
5078
           ((adjusted_mode->crtc_vblank_end - 1) << 16));
5872
			if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
-
 
5873
				temp |= LVDS_HSYNC_POLARITY;
-
 
5874
			if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
-
 
5875
				temp |= LVDS_VSYNC_POLARITY;
Line -... Line 5876...
-
 
5876
			I915_WRITE(PCH_LVDS, temp);
-
 
5877
		}
-
 
5878
	}
-
 
5879
 
5079
    I915_WRITE(VSYNC(pipe),
5880
	if (is_dp && !is_cpu_edp) {
-
 
5881
		intel_dp_set_m_n(crtc, mode, adjusted_mode);
-
 
5882
	} else {
-
 
5883
		if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
-
 
5884
			/* For non-DP output, clear any trans DP clock recovery
-
 
5885
			 * setting.*/
-
 
5886
			I915_WRITE(TRANSDATA_M1(pipe), 0);
-
 
5887
			I915_WRITE(TRANSDATA_N1(pipe), 0);
-
 
5888
			I915_WRITE(TRANSDPLINK_M1(pipe), 0);
-
 
5889
			I915_WRITE(TRANSDPLINK_N1(pipe), 0);
-
 
5890
		}
-
 
5891
	}
-
 
5892
 
-
 
5893
	intel_crtc->lowfreq_avail = false;
5080
           (adjusted_mode->crtc_vsync_start - 1) |
5894
	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
-
 
5895
		if (intel_crtc->pch_pll) {
-
 
5896
			I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
-
 
5897
 
-
 
5898
			/* Wait for the clocks to stabilize. */
-
 
5899
			POSTING_READ(intel_crtc->pch_pll->pll_reg);
-
 
5900
			udelay(150);
-
 
5901
 
5081
           ((adjusted_mode->crtc_vsync_end - 1) << 16));
5902
			/* The pixel multiplier can only be updated once the
5082
 
5903
			 * DPLL is enabled and the clocks are stable.
5083
    /* pipesrc controls the size that is scaled from, which should
-
 
-
 
5904
			 *
Line -... Line 5905...
-
 
5905
			 * So write it again.
5084
     * always be the user's requested size.
5906
     */
5085
     */
5907
			I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
5086
    I915_WRITE(PIPESRC(pipe),
5908
		}
-
 
5909
 
5087
           ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
5910
		if (intel_crtc->pch_pll) {
-
 
5911
			if (is_lvds && has_reduced_clock && i915_powersave) {
-
 
5912
				I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
-
 
5913
				intel_crtc->lowfreq_avail = true;
Line -... Line 5914...
-
 
5914
			} else {
-
 
5915
				I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
-
 
5916
			}
-
 
5917
		}
-
 
5918
	}
-
 
5919
 
5088
 
5920
	intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
5089
    I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
5921
 
Line 5090... Line 5922...
5090
    I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
5922
	if (!is_dp || is_cpu_edp)
5091
    I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
-
 
5092
    I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
-
 
Line 5093... Line 5923...
5093
 
5923
		ironlake_set_m_n(crtc, mode, adjusted_mode);
5094
	if (is_cpu_edp)
5924
 
5095
        ironlake_set_pll_edp(crtc, adjusted_mode->clock);
5925
	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
Line 5117... Line 5947...
5117
			       int x, int y,
5947
			       int x, int y,
5118
			       struct drm_framebuffer *fb)
5948
			       struct drm_framebuffer *fb)
5119
{
5949
{
5120
	struct drm_device *dev = crtc->dev;
5950
	struct drm_device *dev = crtc->dev;
5121
	struct drm_i915_private *dev_priv = dev->dev_private;
5951
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5952
	struct drm_encoder_helper_funcs *encoder_funcs;
-
 
5953
	struct intel_encoder *encoder;
5122
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5954
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5123
	int pipe = intel_crtc->pipe;
5955
	int pipe = intel_crtc->pipe;
5124
	int ret;
5956
	int ret;
Line 5125... Line 5957...
5125
 
5957
 
Line 5126... Line 5958...
5126
	drm_vblank_pre_modeset(dev, pipe);
5958
	drm_vblank_pre_modeset(dev, pipe);
5127
 
5959
 
5128
	ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
5960
	ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
Line -... Line 5961...
-
 
5961
					      x, y, fb);
5129
					      x, y, fb);
5962
	drm_vblank_post_modeset(dev, pipe);
-
 
5963
 
-
 
5964
	if (ret != 0)
-
 
5965
	return ret;
-
 
5966
 
-
 
5967
	for_each_encoder_on_crtc(dev, crtc, encoder) {
-
 
5968
		DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
-
 
5969
			encoder->base.base.id,
-
 
5970
			drm_get_encoder_name(&encoder->base),
-
 
5971
			mode->base.id, mode->name);
-
 
5972
		encoder_funcs = encoder->base.helper_private;
-
 
5973
		encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
5130
	drm_vblank_post_modeset(dev, pipe);
5974
	}
Line 5131... Line 5975...
5131
 
5975
 
5132
	return ret;
5976
	return 0;
5133
}
5977
}
Line 5765... Line 6609...
5765
intel_framebuffer_create_for_mode(struct drm_device *dev,
6609
intel_framebuffer_create_for_mode(struct drm_device *dev,
5766
				  struct drm_display_mode *mode,
6610
				  struct drm_display_mode *mode,
5767
				  int depth, int bpp)
6611
				  int depth, int bpp)
5768
{
6612
{
5769
	struct drm_i915_gem_object *obj;
6613
	struct drm_i915_gem_object *obj;
5770
	struct drm_mode_fb_cmd2 mode_cmd;
6614
	struct drm_mode_fb_cmd2 mode_cmd = { 0 };
Line 5771... Line 6615...
5771
 
6615
 
5772
//	obj = i915_gem_alloc_object(dev,
6616
//	obj = i915_gem_alloc_object(dev,
5773
//				    intel_framebuffer_size_for_mode(mode, bpp));
6617
//				    intel_framebuffer_size_for_mode(mode, bpp));
5774
//	if (obj == NULL)
6618
//	if (obj == NULL)
Line 5895... Line 6739...
5895
		old->release_fb = fb;
6739
		old->release_fb = fb;
5896
	} else
6740
	} else
5897
		DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
6741
		DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
5898
	if (IS_ERR(fb)) {
6742
	if (IS_ERR(fb)) {
5899
		DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
6743
		DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
5900
		goto fail;
6744
		return false;
5901
	}
6745
	}
Line 5902... Line 6746...
5902
 
6746
 
5903
	if (!intel_set_mode(crtc, mode, 0, 0, fb)) {
6747
	if (!intel_set_mode(crtc, mode, 0, 0, fb)) {
5904
		DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
6748
		DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
5905
		if (old->release_fb)
6749
		if (old->release_fb)
5906
			old->release_fb->funcs->destroy(old->release_fb);
6750
			old->release_fb->funcs->destroy(old->release_fb);
5907
		goto fail;
6751
		return false;
Line 5908... Line 6752...
5908
	}
6752
	}
5909
 
6753
 
5910
	/* let the connector get through one full cycle before testing */
-
 
5911
	intel_wait_for_vblank(dev, intel_crtc->pipe);
6754
	/* let the connector get through one full cycle before testing */
5912
 
-
 
5913
	return true;
-
 
5914
fail:
-
 
5915
	connector->encoder = NULL;
-
 
5916
	encoder->crtc = NULL;
6755
	intel_wait_for_vblank(dev, intel_crtc->pipe);
Line 5917... Line 6756...
5917
	return false;
6756
	return true;
5918
}
6757
}
5919
 
6758
 
Line 6037... Line 6876...
6037
struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
6876
struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
6038
					     struct drm_crtc *crtc)
6877
					     struct drm_crtc *crtc)
6039
{
6878
{
6040
	struct drm_i915_private *dev_priv = dev->dev_private;
6879
	struct drm_i915_private *dev_priv = dev->dev_private;
6041
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6880
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6042
	int pipe = intel_crtc->pipe;
6881
	enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
6043
	struct drm_display_mode *mode;
6882
	struct drm_display_mode *mode;
6044
	int htot = I915_READ(HTOTAL(pipe));
6883
	int htot = I915_READ(HTOTAL(cpu_transcoder));
6045
	int hsync = I915_READ(HSYNC(pipe));
6884
	int hsync = I915_READ(HSYNC(cpu_transcoder));
6046
	int vtot = I915_READ(VTOTAL(pipe));
6885
	int vtot = I915_READ(VTOTAL(cpu_transcoder));
6047
	int vsync = I915_READ(VSYNC(pipe));
6886
	int vsync = I915_READ(VSYNC(cpu_transcoder));
Line 6048... Line 6887...
6048
 
6887
 
6049
	mode = kzalloc(sizeof(*mode), GFP_KERNEL);
6888
	mode = kzalloc(sizeof(*mode), GFP_KERNEL);
6050
	if (!mode)
6889
	if (!mode)
Line 6200... Line 7039...
6200
#if 0
7039
#if 0
6201
static void intel_unpin_work_fn(struct work_struct *__work)
7040
static void intel_unpin_work_fn(struct work_struct *__work)
6202
{
7041
{
6203
	struct intel_unpin_work *work =
7042
	struct intel_unpin_work *work =
6204
		container_of(__work, struct intel_unpin_work, work);
7043
		container_of(__work, struct intel_unpin_work, work);
-
 
7044
	struct drm_device *dev = work->crtc->dev;
Line 6205... Line 7045...
6205
 
7045
 
6206
	mutex_lock(&work->dev->struct_mutex);
7046
	mutex_lock(&dev->struct_mutex);
6207
	intel_unpin_fb_obj(work->old_fb_obj);
7047
	intel_unpin_fb_obj(work->old_fb_obj);
6208
	drm_gem_object_unreference(&work->pending_flip_obj->base);
7048
	drm_gem_object_unreference(&work->pending_flip_obj->base);
Line 6209... Line 7049...
6209
	drm_gem_object_unreference(&work->old_fb_obj->base);
7049
	drm_gem_object_unreference(&work->old_fb_obj->base);
6210
 
7050
 
-
 
7051
	intel_update_fbc(dev);
-
 
7052
	mutex_unlock(&dev->struct_mutex);
-
 
7053
 
-
 
7054
	BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
6211
	intel_update_fbc(work->dev);
7055
	atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
6212
	mutex_unlock(&work->dev->struct_mutex);
7056
 
Line 6213... Line 7057...
6213
	kfree(work);
7057
	kfree(work);
6214
}
7058
}
6215
 
7059
 
6216
static void do_intel_finish_page_flip(struct drm_device *dev,
7060
static void do_intel_finish_page_flip(struct drm_device *dev,
6217
				      struct drm_crtc *crtc)
7061
				      struct drm_crtc *crtc)
6218
{
7062
{
6219
	drm_i915_private_t *dev_priv = dev->dev_private;
7063
	drm_i915_private_t *dev_priv = dev->dev_private;
6220
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
6221
	struct intel_unpin_work *work;
-
 
6222
	struct drm_i915_gem_object *obj;
7064
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Line 6223... Line 7065...
6223
	struct drm_pending_vblank_event *e;
7065
	struct intel_unpin_work *work;
6224
	struct timeval tvbl;
7066
	struct drm_i915_gem_object *obj;
6225
	unsigned long flags;
7067
	unsigned long flags;
Line 6226... Line 7068...
6226
 
7068
 
6227
	/* Ignore early vblank irqs */
7069
	/* Ignore early vblank irqs */
-
 
7070
	if (intel_crtc == NULL)
-
 
7071
		return;
-
 
7072
 
-
 
7073
	spin_lock_irqsave(&dev->event_lock, flags);
6228
	if (intel_crtc == NULL)
7074
	work = intel_crtc->unpin_work;
6229
		return;
7075
 
6230
 
7076
	/* Ensure we don't miss a work->pending update ... */
6231
	spin_lock_irqsave(&dev->event_lock, flags);
7077
	smp_rmb();
Line -... Line 7078...
-
 
7078
 
-
 
7079
	if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
-
 
7080
		spin_unlock_irqrestore(&dev->event_lock, flags);
6232
	work = intel_crtc->unpin_work;
7081
		return;
Line 6233... Line 7082...
6233
	if (work == NULL || !work->pending) {
7082
	}
6234
		spin_unlock_irqrestore(&dev->event_lock, flags);
-
 
6235
		return;
7083
 
6236
	}
-
 
6237
 
-
 
6238
	intel_crtc->unpin_work = NULL;
-
 
6239
 
-
 
6240
	if (work->event) {
-
 
6241
		e = work->event;
-
 
6242
		e->event.sequence = drm_vblank_count_and_time(dev, intel_crtc->pipe, &tvbl);
-
 
6243
 
-
 
Line 6244... Line 7084...
6244
		e->event.tv_sec = tvbl.tv_sec;
7084
	/* and that the unpin work is consistent wrt ->pending. */
Line 6245... Line 7085...
6245
		e->event.tv_usec = tvbl.tv_usec;
7085
	smp_rmb();
Line 6246... Line 7086...
6246
 
7086
 
Line 6247... Line 7087...
6247
		list_add_tail(&e->base.link,
7087
	intel_crtc->unpin_work = NULL;
6248
			      &e->base.file_priv->event_list);
7088
 
6249
		wake_up_interruptible(&e->base.file_priv->event_wait);
-
 
6250
	}
7089
	if (work->event)
-
 
7090
		drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
6251
 
7091
 
Line 6252... Line 7092...
6252
	drm_vblank_put(dev, intel_crtc->pipe);
7092
	drm_vblank_put(dev, intel_crtc->pipe);
6253
 
7093
 
Line 6254... Line 7094...
6254
	spin_unlock_irqrestore(&dev->event_lock, flags);
7094
	spin_unlock_irqrestore(&dev->event_lock, flags);
Line 6285... Line 7125...
6285
	drm_i915_private_t *dev_priv = dev->dev_private;
7125
	drm_i915_private_t *dev_priv = dev->dev_private;
6286
	struct intel_crtc *intel_crtc =
7126
	struct intel_crtc *intel_crtc =
6287
		to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
7127
		to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
6288
	unsigned long flags;
7128
	unsigned long flags;
Line -... Line 7129...
-
 
7129
 
-
 
7130
	/* NB: An MMIO update of the plane base pointer will also
-
 
7131
	 * generate a page-flip completion irq, i.e. every modeset
-
 
7132
	 * is also accompanied by a spurious intel_prepare_page_flip().
6289
 
7133
	 */
6290
	spin_lock_irqsave(&dev->event_lock, flags);
7134
	spin_lock_irqsave(&dev->event_lock, flags);
6291
	if (intel_crtc->unpin_work) {
7135
	if (intel_crtc->unpin_work)
6292
		if ((++intel_crtc->unpin_work->pending) > 1)
-
 
6293
			DRM_ERROR("Prepared flip multiple times\n");
-
 
6294
	} else {
-
 
6295
		DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n");
-
 
6296
	}
7136
		atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
6297
	spin_unlock_irqrestore(&dev->event_lock, flags);
7137
	spin_unlock_irqrestore(&dev->event_lock, flags);
Line -... Line 7138...
-
 
7138
}
-
 
7139
 
-
 
7140
inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
-
 
7141
{
-
 
7142
	/* Ensure that the work item is consistent when activating it ... */
-
 
7143
	smp_wmb();
-
 
7144
	atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
-
 
7145
	/* and that it is marked active as soon as the irq could fire. */
-
 
7146
	smp_wmb();
6298
}
7147
}
6299
 
7148
 
6300
static int intel_gen2_queue_flip(struct drm_device *dev,
7149
static int intel_gen2_queue_flip(struct drm_device *dev,
6301
				 struct drm_crtc *crtc,
7150
				 struct drm_crtc *crtc,
6302
				 struct drm_framebuffer *fb,
7151
				 struct drm_framebuffer *fb,
Line 6328... Line 7177...
6328
	intel_ring_emit(ring, MI_DISPLAY_FLIP |
7177
	intel_ring_emit(ring, MI_DISPLAY_FLIP |
6329
			MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7178
			MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
6330
	intel_ring_emit(ring, fb->pitches[0]);
7179
	intel_ring_emit(ring, fb->pitches[0]);
6331
	intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7180
	intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
6332
	intel_ring_emit(ring, 0); /* aux display base address, unused */
7181
	intel_ring_emit(ring, 0); /* aux display base address, unused */
-
 
7182
 
-
 
7183
	intel_mark_page_flip_active(intel_crtc);
6333
	intel_ring_advance(ring);
7184
	intel_ring_advance(ring);
6334
	return 0;
7185
	return 0;
Line 6335... Line 7186...
6335
 
7186
 
6336
err_unpin:
7187
err_unpin:
Line 6368... Line 7219...
6368
			MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
7219
			MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
6369
	intel_ring_emit(ring, fb->pitches[0]);
7220
	intel_ring_emit(ring, fb->pitches[0]);
6370
	intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7221
	intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
6371
	intel_ring_emit(ring, MI_NOOP);
7222
	intel_ring_emit(ring, MI_NOOP);
Line -... Line 7223...
-
 
7223
 
6372
 
7224
	intel_mark_page_flip_active(intel_crtc);
6373
	intel_ring_advance(ring);
7225
	intel_ring_advance(ring);
Line 6374... Line 7226...
6374
	return 0;
7226
	return 0;
6375
 
7227
 
Line 6414... Line 7266...
6414
	 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
7266
	 * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
6415
	 */
7267
	 */
6416
	pf = 0;
7268
	pf = 0;
6417
	pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7269
	pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
6418
	intel_ring_emit(ring, pf | pipesrc);
7270
	intel_ring_emit(ring, pf | pipesrc);
-
 
7271
 
-
 
7272
	intel_mark_page_flip_active(intel_crtc);
6419
	intel_ring_advance(ring);
7273
	intel_ring_advance(ring);
6420
	return 0;
7274
	return 0;
Line 6421... Line 7275...
6421
 
7275
 
6422
err_unpin:
7276
err_unpin:
Line 6456... Line 7310...
6456
	 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
7310
	 * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
6457
	 */
7311
	 */
6458
	pf = 0;
7312
	pf = 0;
6459
	pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
7313
	pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
6460
	intel_ring_emit(ring, pf | pipesrc);
7314
	intel_ring_emit(ring, pf | pipesrc);
-
 
7315
 
-
 
7316
	intel_mark_page_flip_active(intel_crtc);
6461
	intel_ring_advance(ring);
7317
	intel_ring_advance(ring);
6462
	return 0;
7318
	return 0;
Line 6463... Line 7319...
6463
 
7319
 
6464
err_unpin:
7320
err_unpin:
Line 6510... Line 7366...
6510
 
7366
 
6511
	intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
7367
	intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
6512
	intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
7368
	intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
6513
	intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
7369
	intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
-
 
7370
	intel_ring_emit(ring, (MI_NOOP));
-
 
7371
 
6514
	intel_ring_emit(ring, (MI_NOOP));
7372
	intel_mark_page_flip_active(intel_crtc);
6515
	intel_ring_advance(ring);
7373
	intel_ring_advance(ring);
Line 6516... Line 7374...
6516
	return 0;
7374
	return 0;
6517
 
7375
 
Line 6558... Line 7416...
6558
	work = kzalloc(sizeof *work, GFP_KERNEL);
7416
	work = kzalloc(sizeof *work, GFP_KERNEL);
6559
	if (work == NULL)
7417
	if (work == NULL)
6560
		return -ENOMEM;
7418
		return -ENOMEM;
Line 6561... Line 7419...
6561
 
7419
 
6562
	work->event = event;
7420
	work->event = event;
6563
	work->dev = crtc->dev;
7421
	work->crtc = crtc;
6564
	intel_fb = to_intel_framebuffer(crtc->fb);
7422
	intel_fb = to_intel_framebuffer(crtc->fb);
6565
	work->old_fb_obj = intel_fb->obj;
7423
	work->old_fb_obj = intel_fb->obj;
Line 6566... Line 7424...
6566
	INIT_WORK(&work->work, intel_unpin_work_fn);
7424
	INIT_WORK(&work->work, intel_unpin_work_fn);
Line 6583... Line 7441...
6583
	spin_unlock_irqrestore(&dev->event_lock, flags);
7441
	spin_unlock_irqrestore(&dev->event_lock, flags);
Line 6584... Line 7442...
6584
 
7442
 
6585
	intel_fb = to_intel_framebuffer(fb);
7443
	intel_fb = to_intel_framebuffer(fb);
Line -... Line 7444...
-
 
7444
	obj = intel_fb->obj;
-
 
7445
 
-
 
7446
	if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
6586
	obj = intel_fb->obj;
7447
		flush_workqueue(dev_priv->wq);
6587
 
7448
 
6588
	ret = i915_mutex_lock_interruptible(dev);
7449
	ret = i915_mutex_lock_interruptible(dev);
Line 6589... Line 7450...
6589
	if (ret)
7450
	if (ret)
Line 6601... Line 7462...
6601
 
7462
 
6602
	/* Block clients from rendering to the new back buffer until
7463
	/* Block clients from rendering to the new back buffer until
6603
	 * the flip occurs and the object is no longer visible.
7464
	 * the flip occurs and the object is no longer visible.
6604
	 */
7465
	 */
-
 
7466
	atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
Line 6605... Line 7467...
6605
	atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
7467
	atomic_inc(&intel_crtc->unpin_work_count);
6606
 
7468
 
6607
	ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
7469
	ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
Line 6615... Line 7477...
6615
	trace_i915_flip_request(intel_crtc->plane, obj);
7477
	trace_i915_flip_request(intel_crtc->plane, obj);
Line 6616... Line 7478...
6616
 
7478
 
Line 6617... Line 7479...
6617
	return 0;
7479
	return 0;
-
 
7480
 
6618
 
7481
cleanup_pending:
6619
cleanup_pending:
7482
	atomic_dec(&intel_crtc->unpin_work_count);
6620
	atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
7483
	atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
6621
	drm_gem_object_unreference(&work->old_fb_obj->base);
7484
	drm_gem_object_unreference(&work->old_fb_obj->base);
Line 6912... Line 7775...
6912
		if (prepare_pipes & (1 << intel_crtc->pipe)) {
7775
		if (prepare_pipes & (1 << intel_crtc->pipe)) {
6913
			struct drm_property *dpms_property =
7776
			struct drm_property *dpms_property =
6914
				dev->mode_config.dpms_property;
7777
				dev->mode_config.dpms_property;
Line 6915... Line 7778...
6915
 
7778
 
6916
			connector->dpms = DRM_MODE_DPMS_ON;
7779
			connector->dpms = DRM_MODE_DPMS_ON;
6917
			drm_connector_property_set_value(connector,
7780
			drm_object_property_set_value(&connector->base,
6918
							 dpms_property,
7781
							 dpms_property,
Line 6919... Line 7782...
6919
							 DRM_MODE_DPMS_ON);
7782
							 DRM_MODE_DPMS_ON);
6920
 
7783
 
Line 7034... Line 7897...
7034
		    int x, int y, struct drm_framebuffer *fb)
7897
		    int x, int y, struct drm_framebuffer *fb)
7035
{
7898
{
7036
	struct drm_device *dev = crtc->dev;
7899
	struct drm_device *dev = crtc->dev;
7037
	drm_i915_private_t *dev_priv = dev->dev_private;
7900
	drm_i915_private_t *dev_priv = dev->dev_private;
7038
	struct drm_display_mode *adjusted_mode, saved_mode, saved_hwmode;
7901
	struct drm_display_mode *adjusted_mode, saved_mode, saved_hwmode;
7039
	struct drm_encoder_helper_funcs *encoder_funcs;
-
 
7040
	struct drm_encoder *encoder;
-
 
7041
	struct intel_crtc *intel_crtc;
7902
	struct intel_crtc *intel_crtc;
7042
	unsigned disable_pipes, prepare_pipes, modeset_pipes;
7903
	unsigned disable_pipes, prepare_pipes, modeset_pipes;
7043
	bool ret = true;
7904
	bool ret = true;
Line 7044... Line 7905...
7044
 
7905
 
Line 7080... Line 7941...
7080
 
7941
 
7081
	/* Only after disabling all output pipelines that will be changed can we
7942
	/* Only after disabling all output pipelines that will be changed can we
7082
	 * update the the output configuration. */
7943
	 * update the the output configuration. */
Line -... Line 7944...
-
 
7944
	intel_modeset_update_state(dev, prepare_pipes);
-
 
7945
 
-
 
7946
	if (dev_priv->display.modeset_global_resources)
7083
	intel_modeset_update_state(dev, prepare_pipes);
7947
		dev_priv->display.modeset_global_resources(dev);
7084
 
7948
 
7085
	/* Set up the DPLL and any encoders state that needs to adjust or depend
7949
	/* Set up the DPLL and any encoders state that needs to adjust or depend
7086
	 * on the DPLL.
7950
	 * on the DPLL.
7087
	 */
7951
	 */
7088
	for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
7952
	for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
7089
		ret = !intel_crtc_mode_set(&intel_crtc->base,
7953
		ret = !intel_crtc_mode_set(&intel_crtc->base,
7090
					   mode, adjusted_mode,
7954
					   mode, adjusted_mode,
7091
					   x, y, fb);
7955
					   x, y, fb);
7092
		if (!ret)
-
 
7093
		    goto done;
-
 
7094
 
-
 
7095
		list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
-
 
7096
 
-
 
7097
			if (encoder->crtc != &intel_crtc->base)
-
 
7098
				continue;
-
 
7099
 
-
 
7100
			DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
-
 
7101
				encoder->base.id, drm_get_encoder_name(encoder),
-
 
7102
				mode->base.id, mode->name);
-
 
7103
			encoder_funcs = encoder->helper_private;
-
 
7104
			encoder_funcs->mode_set(encoder, mode, adjusted_mode);
7956
		if (!ret)
Line 7105... Line 7957...
7105
		}
7957
		    goto done;
7106
	}
7958
	}
7107
 
7959
 
Line 7278... Line 8130...
7278
 
8130
 
7279
		if (&connector->new_encoder->base != connector->base.encoder) {
8131
		if (&connector->new_encoder->base != connector->base.encoder) {
7280
			DRM_DEBUG_KMS("encoder changed, full mode switch\n");
8132
			DRM_DEBUG_KMS("encoder changed, full mode switch\n");
7281
			config->mode_changed = true;
8133
			config->mode_changed = true;
7282
		}
-
 
7283
 
-
 
7284
		/* Disable all disconnected encoders. */
-
 
7285
		if (connector->base.status == connector_status_disconnected)
-
 
7286
			connector->new_encoder = NULL;
8134
		}
7287
	}
8135
	}
Line 7288... Line 8136...
7288
	/* connector->new_encoder is now updated for all connectors. */
8136
	/* connector->new_encoder is now updated for all connectors. */
7289
 
8137
 
Line 7439... Line 8287...
7439
	.set_config = intel_crtc_set_config,
8287
	.set_config = intel_crtc_set_config,
7440
	.destroy = intel_crtc_destroy,
8288
	.destroy = intel_crtc_destroy,
7441
//	.page_flip = intel_crtc_page_flip,
8289
//	.page_flip = intel_crtc_page_flip,
7442
};
8290
};
Line -... Line 8291...
-
 
8291
 
-
 
8292
static void intel_cpu_pll_init(struct drm_device *dev)
-
 
8293
{
-
 
8294
	if (IS_HASWELL(dev))
-
 
8295
		intel_ddi_pll_init(dev);
-
 
8296
}
7443
 
8297
 
7444
static void intel_pch_pll_init(struct drm_device *dev)
8298
static void intel_pch_pll_init(struct drm_device *dev)
7445
{
8299
{
7446
	drm_i915_private_t *dev_priv = dev->dev_private;
8300
	drm_i915_private_t *dev_priv = dev->dev_private;
Line 7478... Line 8332...
7478
	}
8332
	}
Line 7479... Line 8333...
7479
 
8333
 
7480
	/* Swap pipes & planes for FBC on pre-965 */
8334
	/* Swap pipes & planes for FBC on pre-965 */
7481
	intel_crtc->pipe = pipe;
8335
	intel_crtc->pipe = pipe;
-
 
8336
	intel_crtc->plane = pipe;
7482
	intel_crtc->plane = pipe;
8337
	intel_crtc->cpu_transcoder = pipe;
7483
	if (IS_MOBILE(dev) && IS_GEN3(dev)) {
8338
	if (IS_MOBILE(dev) && IS_GEN3(dev)) {
7484
		DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
8339
		DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
7485
		intel_crtc->plane = !pipe;
8340
		intel_crtc->plane = !pipe;
Line 7491... Line 8346...
7491
	dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
8346
	dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
Line 7492... Line 8347...
7492
 
8347
 
Line 7493... Line 8348...
7493
	intel_crtc->bpp = 24; /* default for pre-Ironlake */
8348
	intel_crtc->bpp = 24; /* default for pre-Ironlake */
7494
 
-
 
7495
	drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
-
 
7496
 
-
 
7497
    DRM_DEBUG_KMS("CRTC %d mode %x FB %x enable %d\n",
-
 
7498
            intel_crtc->base.base.id, intel_crtc->base.mode,
-
 
7499
            intel_crtc->base.fb, intel_crtc->base.enabled);
8349
 
Line 7500... Line 8350...
7500
 
8350
	drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
7501
}
8351
}
7502
 
8352
 
Line 7572... Line 8422...
7572
	if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
8422
	if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
7573
		/* disable the panel fitter on everything but LVDS */
8423
		/* disable the panel fitter on everything but LVDS */
7574
		I915_WRITE(PFIT_CONTROL, 0);
8424
		I915_WRITE(PFIT_CONTROL, 0);
7575
	}
8425
	}
Line 7576... Line 8426...
7576
 
8426
 
7577
	if (HAS_PCH_SPLIT(dev)) {
-
 
7578
		dpd_is_edp = intel_dpd_is_edp(dev);
-
 
7579
 
-
 
7580
		if (has_edp_a(dev))
-
 
7581
			intel_dp_init(dev, DP_A, PORT_A);
-
 
7582
 
8427
	if (!(IS_HASWELL(dev) &&
7583
		if (dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
-
 
7584
			intel_dp_init(dev, PCH_DP_D, PORT_D);
-
 
7585
	}
-
 
7586
 
8428
	      (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)))
Line 7587... Line 8429...
7587
	intel_crt_init(dev);
8429
	intel_crt_init(dev);
7588
 
8430
 
Line 7605... Line 8447...
7605
			intel_ddi_init(dev, PORT_C);
8447
			intel_ddi_init(dev, PORT_C);
7606
		if (found & SFUSE_STRAP_DDID_DETECTED)
8448
		if (found & SFUSE_STRAP_DDID_DETECTED)
7607
			intel_ddi_init(dev, PORT_D);
8449
			intel_ddi_init(dev, PORT_D);
7608
	} else if (HAS_PCH_SPLIT(dev)) {
8450
	} else if (HAS_PCH_SPLIT(dev)) {
7609
		int found;
8451
		int found;
-
 
8452
		dpd_is_edp = intel_dpd_is_edp(dev);
-
 
8453
 
-
 
8454
		if (has_edp_a(dev))
-
 
8455
			intel_dp_init(dev, DP_A, PORT_A);
Line 7610... Line 8456...
7610
 
8456
 
7611
		if (I915_READ(HDMIB) & PORT_DETECTED) {
8457
		if (I915_READ(HDMIB) & PORT_DETECTED) {
7612
			/* PCH SDVOB multiplex with HDMIB */
8458
			/* PCH SDVOB multiplex with HDMIB */
7613
			found = intel_sdvo_init(dev, PCH_SDVOB, true);
8459
			found = intel_sdvo_init(dev, PCH_SDVOB, true);
Line 7624... Line 8470...
7624
			intel_hdmi_init(dev, HDMID, PORT_D);
8470
			intel_hdmi_init(dev, HDMID, PORT_D);
Line 7625... Line 8471...
7625
 
8471
 
7626
		if (I915_READ(PCH_DP_C) & DP_DETECTED)
8472
		if (I915_READ(PCH_DP_C) & DP_DETECTED)
Line 7627... Line 8473...
7627
			intel_dp_init(dev, PCH_DP_C, PORT_C);
8473
			intel_dp_init(dev, PCH_DP_C, PORT_C);
7628
 
8474
 
7629
		if (!dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
8475
		if (I915_READ(PCH_DP_D) & DP_DETECTED)
7630
			intel_dp_init(dev, PCH_DP_D, PORT_D);
8476
			intel_dp_init(dev, PCH_DP_D, PORT_D);
Line -... Line 8477...
-
 
8477
	} else if (IS_VALLEYVIEW(dev)) {
-
 
8478
		int found;
-
 
8479
 
-
 
8480
		/* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
7631
	} else if (IS_VALLEYVIEW(dev)) {
8481
		if (I915_READ(DP_C) & DP_DETECTED)
7632
		int found;
8482
			intel_dp_init(dev, DP_C, PORT_C);
7633
 
8483
 
7634
		if (I915_READ(SDVOB) & PORT_DETECTED) {
8484
		if (I915_READ(SDVOB) & PORT_DETECTED) {
7635
			/* SDVOB multiplex with HDMIB */
8485
			/* SDVOB multiplex with HDMIB */
Line 7641... Line 8491...
7641
		}
8491
		}
Line 7642... Line 8492...
7642
 
8492
 
7643
		if (I915_READ(SDVOC) & PORT_DETECTED)
8493
		if (I915_READ(SDVOC) & PORT_DETECTED)
Line 7644... Line -...
7644
			intel_hdmi_init(dev, SDVOC, PORT_C);
-
 
7645
 
-
 
7646
		/* Shares lanes with HDMI on SDVOC */
-
 
7647
		if (I915_READ(DP_C) & DP_DETECTED)
8494
			intel_hdmi_init(dev, SDVOC, PORT_C);
7648
			intel_dp_init(dev, DP_C, PORT_C);
8495
 
Line 7649... Line 8496...
7649
	} else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
8496
	} else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
7650
		bool found = false;
8497
		bool found = false;
Line 7697... Line 8544...
7697
		encoder->base.possible_crtcs = encoder->crtc_mask;
8544
		encoder->base.possible_crtcs = encoder->crtc_mask;
7698
		encoder->base.possible_clones =
8545
		encoder->base.possible_clones =
7699
			intel_encoder_clones(encoder);
8546
			intel_encoder_clones(encoder);
7700
	}
8547
	}
Line 7701... Line 8548...
7701
 
8548
 
-
 
8549
	intel_init_pch_refclk(dev);
7702
	if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
8550
 
7703
		ironlake_init_pch_refclk(dev);
8551
	drm_helper_move_panel_connectors_to_head(dev);
Line 7704... Line 8552...
7704
}
8552
}
Line 7715... Line 8563...
7715
			   struct drm_mode_fb_cmd2 *mode_cmd,
8563
			   struct drm_mode_fb_cmd2 *mode_cmd,
7716
			   struct drm_i915_gem_object *obj)
8564
			   struct drm_i915_gem_object *obj)
7717
{
8565
{
7718
	int ret;
8566
	int ret;
Line 7719... Line 8567...
7719
 
8567
 
-
 
8568
	if (obj->tiling_mode == I915_TILING_Y) {
-
 
8569
		DRM_DEBUG("hardware does not support tiling Y\n");
-
 
8570
		return -EINVAL;
-
 
8571
	}
-
 
8572
 
-
 
8573
	if (mode_cmd->pitches[0] & 63) {
-
 
8574
		DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
7720
	if (obj->tiling_mode == I915_TILING_Y)
8575
			  mode_cmd->pitches[0]);
-
 
8576
		return -EINVAL;
-
 
8577
	}
-
 
8578
 
-
 
8579
	/* FIXME <= Gen4 stride limits are bit unclear */
-
 
8580
	if (mode_cmd->pitches[0] > 32768) {
-
 
8581
		DRM_DEBUG("pitch (%d) must be at less than 32768\n",
-
 
8582
			  mode_cmd->pitches[0]);
-
 
8583
		return -EINVAL;
Line -... Line 8584...
-
 
8584
	}
-
 
8585
 
-
 
8586
	if (obj->tiling_mode != I915_TILING_NONE &&
7721
		return -EINVAL;
8587
	    mode_cmd->pitches[0] != obj->stride) {
7722
 
8588
		DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
-
 
8589
			  mode_cmd->pitches[0], obj->stride);
Line -... Line 8590...
-
 
8590
			return -EINVAL;
7723
	if (mode_cmd->pitches[0] & 63)
8591
	}
7724
			return -EINVAL;
8592
 
7725
 
8593
	/* Reject formats not supported by any plane early. */
7726
	switch (mode_cmd->pixel_format) {
8594
	switch (mode_cmd->pixel_format) {
7727
	case DRM_FORMAT_RGB332:
-
 
7728
	case DRM_FORMAT_RGB565:
8595
	case DRM_FORMAT_C8:
-
 
8596
	case DRM_FORMAT_RGB565:
-
 
8597
	case DRM_FORMAT_XRGB8888:
-
 
8598
	case DRM_FORMAT_ARGB8888:
-
 
8599
		break;
-
 
8600
	case DRM_FORMAT_XRGB1555:
-
 
8601
	case DRM_FORMAT_ARGB1555:
-
 
8602
		if (INTEL_INFO(dev)->gen > 3) {
-
 
8603
			DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
-
 
8604
			return -EINVAL;
-
 
8605
		}
7729
	case DRM_FORMAT_XRGB8888:
8606
		break;
7730
	case DRM_FORMAT_XBGR8888:
8607
	case DRM_FORMAT_XBGR8888:
-
 
8608
	case DRM_FORMAT_ABGR8888:
-
 
8609
	case DRM_FORMAT_XRGB2101010:
-
 
8610
	case DRM_FORMAT_ARGB2101010:
7731
	case DRM_FORMAT_ARGB8888:
8611
	case DRM_FORMAT_XBGR2101010:
-
 
8612
	case DRM_FORMAT_ABGR2101010:
-
 
8613
		if (INTEL_INFO(dev)->gen < 4) {
7732
	case DRM_FORMAT_XRGB2101010:
8614
			DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
7733
	case DRM_FORMAT_ARGB2101010:
8615
			return -EINVAL;
7734
		/* RGB formats are common across chipsets */
8616
		}
7735
		break;
8617
		break;
7736
	case DRM_FORMAT_YUYV:
8618
	case DRM_FORMAT_YUYV:
-
 
8619
	case DRM_FORMAT_UYVY:
-
 
8620
	case DRM_FORMAT_YVYU:
-
 
8621
	case DRM_FORMAT_VYUY:
-
 
8622
		if (INTEL_INFO(dev)->gen < 5) {
7737
	case DRM_FORMAT_UYVY:
8623
			DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
7738
	case DRM_FORMAT_YVYU:
8624
			return -EINVAL;
7739
	case DRM_FORMAT_VYUY:
8625
		}
7740
		break;
-
 
7741
	default:
8626
		break;
7742
		DRM_DEBUG_KMS("unsupported pixel format %u\n",
8627
	default:
Line -... Line 8628...
-
 
8628
		DRM_DEBUG("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format);
-
 
8629
		return -EINVAL;
-
 
8630
	}
-
 
8631
 
7743
				mode_cmd->pixel_format);
8632
	/* FIXME need to adjust LINOFF/TILEOFF accordingly. */
7744
		return -EINVAL;
8633
	if (mode_cmd->offsets[0] != 0)
7745
	}
8634
		return -EINVAL;
7746
 
8635
 
7747
	ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
8636
	ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
Line 7765... Line 8654...
7765
static void intel_init_display(struct drm_device *dev)
8654
static void intel_init_display(struct drm_device *dev)
7766
{
8655
{
7767
	struct drm_i915_private *dev_priv = dev->dev_private;
8656
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 7768... Line 8657...
7768
 
8657
 
-
 
8658
	/* We always want a DPMS function */
-
 
8659
	if (IS_HASWELL(dev)) {
-
 
8660
		dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
-
 
8661
		dev_priv->display.crtc_enable = haswell_crtc_enable;
-
 
8662
		dev_priv->display.crtc_disable = haswell_crtc_disable;
-
 
8663
		dev_priv->display.off = haswell_crtc_off;
7769
	/* We always want a DPMS function */
8664
		dev_priv->display.update_plane = ironlake_update_plane;
7770
	if (HAS_PCH_SPLIT(dev)) {
8665
	} else if (HAS_PCH_SPLIT(dev)) {
7771
		dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
8666
		dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
7772
		dev_priv->display.crtc_enable = ironlake_crtc_enable;
8667
		dev_priv->display.crtc_enable = ironlake_crtc_enable;
7773
		dev_priv->display.crtc_disable = ironlake_crtc_disable;
8668
		dev_priv->display.crtc_disable = ironlake_crtc_disable;
7774
		dev_priv->display.off = ironlake_crtc_off;
8669
		dev_priv->display.off = ironlake_crtc_off;
Line 7816... Line 8711...
7816
			dev_priv->display.write_eld = ironlake_write_eld;
8711
			dev_priv->display.write_eld = ironlake_write_eld;
7817
		} else if (IS_IVYBRIDGE(dev)) {
8712
		} else if (IS_IVYBRIDGE(dev)) {
7818
			/* FIXME: detect B0+ stepping and use auto training */
8713
			/* FIXME: detect B0+ stepping and use auto training */
7819
			dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
8714
			dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
7820
			dev_priv->display.write_eld = ironlake_write_eld;
8715
			dev_priv->display.write_eld = ironlake_write_eld;
-
 
8716
			dev_priv->display.modeset_global_resources =
-
 
8717
				ivb_modeset_global_resources;
7821
		} else if (IS_HASWELL(dev)) {
8718
		} else if (IS_HASWELL(dev)) {
7822
			dev_priv->display.fdi_link_train = hsw_fdi_link_train;
8719
			dev_priv->display.fdi_link_train = hsw_fdi_link_train;
7823
			dev_priv->display.write_eld = haswell_write_eld;
8720
			dev_priv->display.write_eld = haswell_write_eld;
7824
		} else
8721
		} else
7825
			dev_priv->display.update_wm = NULL;
8722
			dev_priv->display.update_wm = NULL;
Line 8029... Line 8926...
8029
		ret = intel_plane_init(dev, i);
8926
		ret = intel_plane_init(dev, i);
8030
		if (ret)
8927
		if (ret)
8031
			DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
8928
			DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
8032
	}
8929
	}
Line -... Line 8930...
-
 
8930
 
8033
 
8931
	intel_cpu_pll_init(dev);
Line 8034... Line 8932...
8034
	intel_pch_pll_init(dev);
8932
	intel_pch_pll_init(dev);
8035
 
8933
 
8036
	/* Just disable it once at startup */
8934
	/* Just disable it once at startup */
Line 8098... Line 8996...
8098
	struct drm_device *dev = crtc->base.dev;
8996
	struct drm_device *dev = crtc->base.dev;
8099
	struct drm_i915_private *dev_priv = dev->dev_private;
8997
	struct drm_i915_private *dev_priv = dev->dev_private;
8100
	u32 reg;
8998
	u32 reg;
Line 8101... Line 8999...
8101
 
8999
 
8102
	/* Clear any frame start delays used for debugging left by the BIOS */
9000
	/* Clear any frame start delays used for debugging left by the BIOS */
8103
	reg = PIPECONF(crtc->pipe);
9001
	reg = PIPECONF(crtc->cpu_transcoder);
Line 8104... Line 9002...
8104
	I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
9002
	I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
8105
 
9003
 
8106
	/* We need to sanitize the plane -> pipe mapping first because this will
9004
	/* We need to sanitize the plane -> pipe mapping first because this will
Line 8217... Line 9115...
8217
	 * the crtc fixup. */
9115
	 * the crtc fixup. */
8218
}
9116
}
Line 8219... Line 9117...
8219
 
9117
 
8220
/* Scan out the current hw modeset state, sanitizes it and maps it into the drm
9118
/* Scan out the current hw modeset state, sanitizes it and maps it into the drm
8221
 * and i915 state tracking structures. */
9119
 * and i915 state tracking structures. */
-
 
9120
void intel_modeset_setup_hw_state(struct drm_device *dev,
8222
void intel_modeset_setup_hw_state(struct drm_device *dev)
9121
				  bool force_restore)
8223
{
9122
{
8224
	struct drm_i915_private *dev_priv = dev->dev_private;
9123
	struct drm_i915_private *dev_priv = dev->dev_private;
8225
	enum pipe pipe;
9124
	enum pipe pipe;
8226
	u32 tmp;
9125
	u32 tmp;
8227
	struct intel_crtc *crtc;
9126
	struct intel_crtc *crtc;
8228
	struct intel_encoder *encoder;
9127
	struct intel_encoder *encoder;
Line -... Line 9128...
-
 
9128
	struct intel_connector *connector;
-
 
9129
 
-
 
9130
	if (IS_HASWELL(dev)) {
-
 
9131
		tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
-
 
9132
 
-
 
9133
		if (tmp & TRANS_DDI_FUNC_ENABLE) {
-
 
9134
			switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
-
 
9135
			case TRANS_DDI_EDP_INPUT_A_ON:
-
 
9136
			case TRANS_DDI_EDP_INPUT_A_ONOFF:
-
 
9137
				pipe = PIPE_A;
-
 
9138
				break;
-
 
9139
			case TRANS_DDI_EDP_INPUT_B_ONOFF:
-
 
9140
				pipe = PIPE_B;
-
 
9141
				break;
-
 
9142
			case TRANS_DDI_EDP_INPUT_C_ONOFF:
-
 
9143
				pipe = PIPE_C;
-
 
9144
				break;
-
 
9145
			}
-
 
9146
 
-
 
9147
			crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
-
 
9148
			crtc->cpu_transcoder = TRANSCODER_EDP;
-
 
9149
 
-
 
9150
			DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
-
 
9151
				      pipe_name(pipe));
-
 
9152
		}
8229
	struct intel_connector *connector;
9153
	}
8230
 
9154
 
Line 8231... Line 9155...
8231
	for_each_pipe(pipe) {
9155
	for_each_pipe(pipe) {
8232
		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9156
		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
8233
 
9157
 
8234
		tmp = I915_READ(PIPECONF(pipe));
9158
		tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
8235
		if (tmp & PIPECONF_ENABLE)
9159
		if (tmp & PIPECONF_ENABLE)
Line 8242... Line 9166...
8242
		DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
9166
		DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
8243
			      crtc->base.base.id,
9167
			      crtc->base.base.id,
8244
			      crtc->active ? "enabled" : "disabled");
9168
			      crtc->active ? "enabled" : "disabled");
8245
	}
9169
	}
Line -... Line 9170...
-
 
9170
 
-
 
9171
	if (IS_HASWELL(dev))
-
 
9172
		intel_ddi_setup_hw_pll_state(dev);
8246
 
9173
 
8247
	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
9174
	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
8248
			    base.head) {
9175
			    base.head) {
Line 8249... Line 9176...
8249
		pipe = 0;
9176
		pipe = 0;
Line 8288... Line 9215...
8288
	for_each_pipe(pipe) {
9215
	for_each_pipe(pipe) {
8289
		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
9216
		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
8290
		intel_sanitize_crtc(crtc);
9217
		intel_sanitize_crtc(crtc);
8291
	}
9218
	}
Line -... Line 9219...
-
 
9219
 
-
 
9220
	if (force_restore) {
-
 
9221
		for_each_pipe(pipe) {
-
 
9222
			crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
-
 
9223
			intel_set_mode(&crtc->base, &crtc->base.mode,
-
 
9224
				       crtc->base.x, crtc->base.y, crtc->base.fb);
-
 
9225
		}
-
 
9226
 
-
 
9227
//       i915_redisable_vga(dev);
8292
 
9228
	} else {
-
 
9229
	intel_modeset_update_staged_output_state(dev);
Line 8293... Line 9230...
8293
	intel_modeset_update_staged_output_state(dev);
9230
	}
-
 
9231
 
-
 
9232
	intel_modeset_check_state(dev);
8294
 
9233
 
Line 8295... Line 9234...
8295
	intel_modeset_check_state(dev);
9234
	drm_mode_config_reset(dev);
8296
}
9235
}
8297
 
9236
 
Line 8298... Line 9237...
8298
void intel_modeset_gem_init(struct drm_device *dev)
9237
void intel_modeset_gem_init(struct drm_device *dev)
Line 8299... Line 9238...
8299
{
9238
{
8300
	intel_modeset_init_hw(dev);
9239
	intel_modeset_init_hw(dev);
Line 8301... Line 9240...
8301
 
9240
 
8302
//   intel_setup_overlay(dev);
9241
//   intel_setup_overlay(dev);
8303
 
9242
 
Line 8420... Line 9359...
8420
struct intel_display_error_state *
9359
struct intel_display_error_state *
8421
intel_display_capture_error_state(struct drm_device *dev)
9360
intel_display_capture_error_state(struct drm_device *dev)
8422
{
9361
{
8423
	drm_i915_private_t *dev_priv = dev->dev_private;
9362
	drm_i915_private_t *dev_priv = dev->dev_private;
8424
	struct intel_display_error_state *error;
9363
	struct intel_display_error_state *error;
-
 
9364
	enum transcoder cpu_transcoder;
8425
	int i;
9365
	int i;
Line 8426... Line 9366...
8426
 
9366
 
8427
	error = kmalloc(sizeof(*error), GFP_ATOMIC);
9367
	error = kmalloc(sizeof(*error), GFP_ATOMIC);
8428
	if (error == NULL)
9368
	if (error == NULL)
Line 8429... Line 9369...
8429
		return NULL;
9369
		return NULL;
-
 
9370
 
-
 
9371
	for_each_pipe(i) {
8430
 
9372
		cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
8431
	for_each_pipe(i) {
9373
 
8432
		error->cursor[i].control = I915_READ(CURCNTR(i));
9374
		error->cursor[i].control = I915_READ(CURCNTR(i));
Line 8433... Line 9375...
8433
		error->cursor[i].position = I915_READ(CURPOS(i));
9375
		error->cursor[i].position = I915_READ(CURPOS(i));
Line 8441... Line 9383...
8441
		if (INTEL_INFO(dev)->gen >= 4) {
9383
		if (INTEL_INFO(dev)->gen >= 4) {
8442
			error->plane[i].surface = I915_READ(DSPSURF(i));
9384
			error->plane[i].surface = I915_READ(DSPSURF(i));
8443
			error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
9385
			error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
8444
		}
9386
		}
Line 8445... Line 9387...
8445
 
9387
 
8446
		error->pipe[i].conf = I915_READ(PIPECONF(i));
9388
		error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder));
8447
		error->pipe[i].source = I915_READ(PIPESRC(i));
9389
		error->pipe[i].source = I915_READ(PIPESRC(i));
8448
		error->pipe[i].htotal = I915_READ(HTOTAL(i));
9390
		error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
8449
		error->pipe[i].hblank = I915_READ(HBLANK(i));
9391
		error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder));
8450
		error->pipe[i].hsync = I915_READ(HSYNC(i));
9392
		error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder));
8451
		error->pipe[i].vtotal = I915_READ(VTOTAL(i));
9393
		error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
8452
		error->pipe[i].vblank = I915_READ(VBLANK(i));
9394
		error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder));
8453
		error->pipe[i].vsync = I915_READ(VSYNC(i));
9395
		error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder));
Line 8454... Line 9396...
8454
	}
9396
	}
8455
 
9397