Subversion Repositories Kolibri OS

Rev

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

Rev 5367 Rev 6084
Line 27... Line 27...
27
 
27
 
28
#include 
28
#include 
29
#include 
29
#include 
30
#include 
30
#include 
-
 
31
#include 
31
#include 
32
#include 
32
#include 
33
#include 
33
#include 
34
#include 
34
#include 
35
#include 
35
#include "intel_drv.h"
36
#include "intel_drv.h"
36
#include 
37
#include 
Line 37... Line 38...
37
#include "i915_drv.h"
38
#include "i915_drv.h"
Line -... Line 39...
-
 
39
 
-
 
40
#define DP_LINK_CHECK_TIMEOUT	(10 * 1000)
-
 
41
 
-
 
42
/* Compliance test status bits  */
-
 
43
#define INTEL_DP_RESOLUTION_SHIFT_MASK	0
-
 
44
#define INTEL_DP_RESOLUTION_PREFERRED	(1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
38
 
45
#define INTEL_DP_RESOLUTION_STANDARD	(2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
39
#define DP_LINK_CHECK_TIMEOUT	(10 * 1000)
46
#define INTEL_DP_RESOLUTION_FAILSAFE	(3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
40
 
47
 
41
struct dp_link_dpll {
48
struct dp_link_dpll {
Line 42... Line 49...
42
	int link_bw;
49
	int clock;
43
	struct dpll dpll;
50
	struct dpll dpll;
44
};
51
};
45
 
52
 
46
static const struct dp_link_dpll gen4_dpll[] = {
53
static const struct dp_link_dpll gen4_dpll[] = {
47
	{ DP_LINK_BW_1_62,
54
	{ 162000,
Line 48... Line 55...
48
		{ .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
55
		{ .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
49
	{ DP_LINK_BW_2_7,
56
	{ 270000,
50
		{ .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
57
		{ .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
51
};
58
};
52
 
59
 
53
static const struct dp_link_dpll pch_dpll[] = {
60
static const struct dp_link_dpll pch_dpll[] = {
Line 54... Line 61...
54
	{ DP_LINK_BW_1_62,
61
	{ 162000,
55
		{ .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
62
		{ .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
56
	{ DP_LINK_BW_2_7,
63
	{ 270000,
57
		{ .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
64
		{ .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
58
};
65
};
59
 
66
 
Line 60... Line 67...
60
static const struct dp_link_dpll vlv_dpll[] = {
67
static const struct dp_link_dpll vlv_dpll[] = {
61
	{ DP_LINK_BW_1_62,
68
	{ 162000,
Line 72... Line 79...
72
	/*
79
	/*
73
	 * CHV requires to program fractional division for m2.
80
	 * CHV requires to program fractional division for m2.
74
	 * m2 is stored in fixed point format using formula below
81
	 * m2 is stored in fixed point format using formula below
75
	 * (m2_int << 22) | m2_fraction
82
	 * (m2_int << 22) | m2_fraction
76
	 */
83
	 */
77
	{ DP_LINK_BW_1_62,	/* m2_int = 32, m2_fraction = 1677722 */
84
	{ 162000,	/* m2_int = 32, m2_fraction = 1677722 */
78
		{ .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
85
		{ .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
79
	{ DP_LINK_BW_2_7,	/* m2_int = 27, m2_fraction = 0 */
86
	{ 270000,	/* m2_int = 27, m2_fraction = 0 */
80
		{ .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
87
		{ .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
81
	{ DP_LINK_BW_5_4,	/* m2_int = 27, m2_fraction = 0 */
88
	{ 540000,	/* m2_int = 27, m2_fraction = 0 */
82
		{ .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
89
		{ .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
83
};
90
};
Line -... Line 91...
-
 
91
 
-
 
92
static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
-
 
93
				  324000, 432000, 540000 };
-
 
94
static const int skl_rates[] = { 162000, 216000, 270000,
-
 
95
				  324000, 432000, 540000 };
-
 
96
static const int default_rates[] = { 162000, 270000, 540000 };
84
 
97
 
85
/**
98
/**
86
 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
99
 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
87
 * @intel_dp: DP struct
100
 * @intel_dp: DP struct
88
 *
101
 *
Line 113... Line 126...
113
static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
126
static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
114
static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
127
static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
115
static void vlv_steal_power_sequencer(struct drm_device *dev,
128
static void vlv_steal_power_sequencer(struct drm_device *dev,
116
				      enum pipe pipe);
129
				      enum pipe pipe);
Line -... Line 130...
-
 
130
 
-
 
131
static unsigned int intel_dp_unused_lane_mask(int lane_count)
-
 
132
{
117
 
133
	return ~((1 << lane_count) - 1) & 0xf;
-
 
134
}
-
 
135
 
118
int
136
static int
119
intel_dp_max_link_bw(struct intel_dp *intel_dp)
137
intel_dp_max_link_bw(struct intel_dp  *intel_dp)
120
{
138
{
121
	int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
-
 
Line 122... Line 139...
122
	struct drm_device *dev = intel_dp->attached_connector->base.dev;
139
	int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
123
 
140
 
124
	switch (max_link_bw) {
141
	switch (max_link_bw) {
125
	case DP_LINK_BW_1_62:
-
 
126
	case DP_LINK_BW_2_7:
-
 
127
		break;
-
 
128
	case DP_LINK_BW_5_4: /* 1.2 capable displays may advertise higher bw */
-
 
129
		if (((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) ||
-
 
130
		     INTEL_INFO(dev)->gen >= 8) &&
142
	case DP_LINK_BW_1_62:
131
		    intel_dp->dpcd[DP_DPCD_REV] >= 0x12)
-
 
132
			max_link_bw = DP_LINK_BW_5_4;
-
 
133
		else
143
	case DP_LINK_BW_2_7:
134
			max_link_bw = DP_LINK_BW_2_7;
144
	case DP_LINK_BW_5_4:
135
		break;
145
		break;
136
	default:
146
	default:
137
		WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
147
		WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
Line 205... Line 215...
205
			return MODE_PANEL;
215
			return MODE_PANEL;
Line 206... Line 216...
206
 
216
 
207
		target_clock = fixed_mode->clock;
217
		target_clock = fixed_mode->clock;
Line 208... Line 218...
208
	}
218
	}
209
 
219
 
Line 210... Line 220...
210
	max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));
220
	max_link_clock = intel_dp_max_link_rate(intel_dp);
211
	max_lanes = intel_dp_max_lane_count(intel_dp);
221
	max_lanes = intel_dp_max_lane_count(intel_dp);
Line 235... Line 245...
235
	for (i = 0; i < src_bytes; i++)
245
	for (i = 0; i < src_bytes; i++)
236
		v |= ((uint32_t) src[i]) << ((3-i) * 8);
246
		v |= ((uint32_t) src[i]) << ((3-i) * 8);
237
	return v;
247
	return v;
238
}
248
}
Line 239... Line 249...
239
 
249
 
240
void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
250
static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
241
{
251
{
242
	int i;
252
	int i;
243
	if (dst_bytes > 4)
253
	if (dst_bytes > 4)
244
		dst_bytes = 4;
254
		dst_bytes = 4;
245
	for (i = 0; i < dst_bytes; i++)
255
	for (i = 0; i < dst_bytes; i++)
246
		dst[i] = src >> ((3-i) * 8);
256
		dst[i] = src >> ((3-i) * 8);
Line 247... Line -...
247
}
-
 
248
 
-
 
249
/* hrawclock is 1/4 the FSB frequency */
-
 
250
static int
-
 
251
intel_hrawclk(struct drm_device *dev)
-
 
252
{
-
 
253
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
254
	uint32_t clkcfg;
-
 
255
 
-
 
256
	/* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
-
 
257
	if (IS_VALLEYVIEW(dev))
-
 
258
		return 200;
-
 
259
 
-
 
260
	clkcfg = I915_READ(CLKCFG);
-
 
261
	switch (clkcfg & CLKCFG_FSB_MASK) {
-
 
262
	case CLKCFG_FSB_400:
-
 
263
		return 100;
-
 
264
	case CLKCFG_FSB_533:
-
 
265
		return 133;
-
 
266
	case CLKCFG_FSB_667:
-
 
267
		return 166;
-
 
268
	case CLKCFG_FSB_800:
-
 
269
		return 200;
-
 
270
	case CLKCFG_FSB_1067:
-
 
271
		return 266;
-
 
272
	case CLKCFG_FSB_1333:
-
 
273
		return 333;
-
 
274
	/* these two are just a guess; one of them might be right */
-
 
275
	case CLKCFG_FSB_1600:
-
 
276
	case CLKCFG_FSB_1600_ALT:
-
 
277
		return 400;
-
 
278
	default:
-
 
279
		return 133;
-
 
280
	}
-
 
281
}
257
}
282
 
258
 
283
static void
259
static void
284
intel_dp_init_panel_power_sequencer(struct drm_device *dev,
260
intel_dp_init_panel_power_sequencer(struct drm_device *dev,
285
				    struct intel_dp *intel_dp);
261
				    struct intel_dp *intel_dp);
Line 297... Line 273...
297
 
273
 
298
	/*
274
	/*
299
	 * See vlv_power_sequencer_reset() why we need
275
	 * See vlv_power_sequencer_reset() why we need
300
	 * a power domain reference here.
276
	 * a power domain reference here.
301
	 */
277
	 */
302
	power_domain = intel_display_port_power_domain(encoder);
278
	power_domain = intel_display_port_aux_power_domain(encoder);
Line 303... Line 279...
303
	intel_display_power_get(dev_priv, power_domain);
279
	intel_display_power_get(dev_priv, power_domain);
304
 
280
 
Line 313... Line 289...
313
	struct drm_i915_private *dev_priv = dev->dev_private;
289
	struct drm_i915_private *dev_priv = dev->dev_private;
314
	enum intel_display_power_domain power_domain;
290
	enum intel_display_power_domain power_domain;
Line 315... Line 291...
315
 
291
 
Line 316... Line 292...
316
	mutex_unlock(&dev_priv->pps_mutex);
292
	mutex_unlock(&dev_priv->pps_mutex);
317
 
293
 
318
	power_domain = intel_display_port_power_domain(encoder);
294
	power_domain = intel_display_port_aux_power_domain(encoder);
Line 319... Line 295...
319
	intel_display_power_put(dev_priv, power_domain);
295
	intel_display_power_put(dev_priv, power_domain);
320
}
296
}
321
 
297
 
322
static void
298
static void
323
vlv_power_sequencer_kick(struct intel_dp *intel_dp)
299
vlv_power_sequencer_kick(struct intel_dp *intel_dp)
324
{
300
{
325
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
301
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
326
	struct drm_device *dev = intel_dig_port->base.base.dev;
302
	struct drm_device *dev = intel_dig_port->base.base.dev;
-
 
303
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
304
	enum pipe pipe = intel_dp->pps_pipe;
327
	struct drm_i915_private *dev_priv = dev->dev_private;
305
	bool pll_enabled, release_cl_override = false;
Line 328... Line 306...
328
	enum pipe pipe = intel_dp->pps_pipe;
306
	enum dpio_phy phy = DPIO_PHY(pipe);
329
	bool pll_enabled;
307
	enum dpio_channel ch = vlv_pipe_to_channel(pipe);
330
	uint32_t DP;
308
	uint32_t DP;
Line 354... Line 332...
354
 
332
 
355
	/*
333
	/*
356
	 * The DPLL for the pipe must be enabled for this to work.
334
	 * The DPLL for the pipe must be enabled for this to work.
357
	 * So enable temporarily it if it's not already enabled.
335
	 * So enable temporarily it if it's not already enabled.
358
	 */
336
	 */
-
 
337
	if (!pll_enabled) {
-
 
338
		release_cl_override = IS_CHERRYVIEW(dev) &&
-
 
339
			!chv_phy_powergate_ch(dev_priv, phy, ch, true);
359
	if (!pll_enabled)
340
 
360
		vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ?
341
		vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ?
-
 
342
				 &chv_dpll[0].dpll : &vlv_dpll[0].dpll);
Line 361... Line 343...
361
				 &chv_dpll[0].dpll : &vlv_dpll[0].dpll);
343
	}
362
 
344
 
363
	/*
345
	/*
364
	 * Similar magic as in intel_dp_enable_port().
346
	 * Similar magic as in intel_dp_enable_port().
Line 373... Line 355...
373
	POSTING_READ(intel_dp->output_reg);
355
	POSTING_READ(intel_dp->output_reg);
Line 374... Line 356...
374
 
356
 
375
	I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
357
	I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
Line 376... Line 358...
376
	POSTING_READ(intel_dp->output_reg);
358
	POSTING_READ(intel_dp->output_reg);
377
 
359
 
-
 
360
	if (!pll_enabled) {
-
 
361
		vlv_force_pll_off(dev, pipe);
-
 
362
 
-
 
363
		if (release_cl_override)
378
	if (!pll_enabled)
364
			chv_phy_powergate_ch(dev_priv, phy, ch, false);
Line 379... Line 365...
379
		vlv_force_pll_off(dev, pipe);
365
	}
380
}
366
}
381
 
367
 
Line 555... Line 541...
555
 
541
 
556
static u32 _pp_ctrl_reg(struct intel_dp *intel_dp)
542
static u32 _pp_ctrl_reg(struct intel_dp *intel_dp)
557
{
543
{
Line -... Line 544...
-
 
544
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
-
 
545
 
558
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
546
	if (IS_BROXTON(dev))
559
 
547
		return BXT_PP_CONTROL(0);
560
	if (HAS_PCH_SPLIT(dev))
548
	else if (HAS_PCH_SPLIT(dev))
561
		return PCH_PP_CONTROL;
549
		return PCH_PP_CONTROL;
562
	else
550
	else
Line 563... Line 551...
563
		return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
551
		return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
564
}
552
}
565
 
553
 
Line -... Line 554...
-
 
554
static u32 _pp_stat_reg(struct intel_dp *intel_dp)
-
 
555
{
566
static u32 _pp_stat_reg(struct intel_dp *intel_dp)
556
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
567
{
557
 
568
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
558
	if (IS_BROXTON(dev))
569
 
559
		return BXT_PP_STATUS(0);
570
	if (HAS_PCH_SPLIT(dev))
560
	else if (HAS_PCH_SPLIT(dev))
Line 581... Line 571...
581
{
571
{
582
	struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
572
	struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
583
						 edp_notifier);
573
						 edp_notifier);
584
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
574
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
585
	struct drm_i915_private *dev_priv = dev->dev_private;
575
	struct drm_i915_private *dev_priv = dev->dev_private;
586
	u32 pp_div;
-
 
587
	u32 pp_ctrl_reg, pp_div_reg;
-
 
Line 588... Line 576...
588
 
576
 
589
	if (!is_edp(intel_dp) || code != SYS_RESTART)
577
	if (!is_edp(intel_dp) || code != SYS_RESTART)
Line 590... Line 578...
590
		return 0;
578
		return 0;
Line 591... Line 579...
591
 
579
 
592
	pps_lock(intel_dp);
580
	pps_lock(intel_dp);
-
 
581
 
-
 
582
	if (IS_VALLEYVIEW(dev)) {
Line 593... Line 583...
593
 
583
		enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
594
	if (IS_VALLEYVIEW(dev)) {
584
		u32 pp_ctrl_reg, pp_div_reg;
595
		enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
585
		u32 pp_div;
596
 
586
 
Line 694... Line 684...
694
 
684
 
695
static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
685
static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
696
{
686
{
697
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
687
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
-
 
688
	struct drm_device *dev = intel_dig_port->base.base.dev;
Line 698... Line 689...
698
	struct drm_device *dev = intel_dig_port->base.base.dev;
689
	struct drm_i915_private *dev_priv = dev->dev_private;
699
 
690
 
Line 700... Line 691...
700
	if (index)
691
	if (index)
701
		return 0;
-
 
702
 
692
		return 0;
703
	if (intel_dig_port->port == PORT_A) {
693
 
704
		if (IS_GEN6(dev) || IS_GEN7(dev))
-
 
705
			return 200; /* SNB & IVB eDP input clock at 400Mhz */
694
	if (intel_dig_port->port == PORT_A) {
706
		else
695
		return DIV_ROUND_UP(dev_priv->cdclk_freq, 2000);
707
			return 225; /* eDP input clock at 450Mhz */
696
 
708
	} else {
697
	} else {
Line 717... Line 706...
717
	struct drm_i915_private *dev_priv = dev->dev_private;
706
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 718... Line 707...
718
 
707
 
719
	if (intel_dig_port->port == PORT_A) {
708
	if (intel_dig_port->port == PORT_A) {
720
		if (index)
709
		if (index)
721
			return 0;
710
			return 0;
722
		return DIV_ROUND_CLOSEST(intel_ddi_get_cdclk_freq(dev_priv), 2000);
711
		return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
723
	} else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
712
	} else if (dev_priv->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
724
		/* Workaround for non-ULT HSW */
713
		/* Workaround for non-ULT HSW */
725
		switch (index) {
714
		switch (index) {
726
		case 0: return 63;
715
		case 0: return 63;
Line 824... Line 813...
824
	 * deep sleep states.
813
	 * deep sleep states.
825
	 */
814
	 */
Line 826... Line 815...
826
 
815
 
Line 827... Line -...
827
	intel_dp_check_edp(intel_dp);
-
 
828
 
-
 
829
	intel_aux_display_runtime_get(dev_priv);
816
	intel_dp_check_edp(intel_dp);
830
 
817
 
831
	/* Try to wait for any previous AUX channel activity */
818
	/* Try to wait for any previous AUX channel activity */
832
	for (try = 0; try < 3; try++) {
819
	for (try = 0; try < 3; try++) {
833
		status = I915_READ_NOTRACE(ch_ctl);
820
		status = I915_READ_NOTRACE(ch_ctl);
834
		if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
821
		if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
835
			break;
822
			break;
Line 836... Line 823...
836
		msleep(1);
823
		msleep(1);
-
 
824
	}
-
 
825
 
-
 
826
	if (try == 3) {
-
 
827
		static u32 last_status = -1;
837
	}
828
		const u32 status = I915_READ(ch_ctl);
838
 
829
 
-
 
830
		if (status != last_status) {
-
 
831
			WARN(1, "dp_aux_ch not started status 0x%08x\n",
-
 
832
			     status);
839
	if (try == 3) {
833
			last_status = status;
840
		WARN(1, "dp_aux_ch not started status 0x%08x\n",
834
		}
841
		     I915_READ(ch_ctl));
835
 
Line 842... Line 836...
842
		ret = -EBUSY;
836
		ret = -EBUSY;
Line 873... Line 867...
873
			   status |
867
				   status |
874
			   DP_AUX_CH_CTL_DONE |
868
				   DP_AUX_CH_CTL_DONE |
875
			   DP_AUX_CH_CTL_TIME_OUT_ERROR |
869
				   DP_AUX_CH_CTL_TIME_OUT_ERROR |
876
			   DP_AUX_CH_CTL_RECEIVE_ERROR);
870
				   DP_AUX_CH_CTL_RECEIVE_ERROR);
Line 877... Line 871...
877
 
871
 
-
 
872
			if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
-
 
873
				continue;
-
 
874
 
-
 
875
			/* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
-
 
876
			 *   400us delay required for errors and timeouts
-
 
877
			 *   Timeout errors from the HW already meet this
-
 
878
			 *   requirement so skip to next iteration
878
		if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
879
			 */
-
 
880
			if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
879
			      DP_AUX_CH_CTL_RECEIVE_ERROR))
881
				usleep_range(400, 500);
880
			continue;
-
 
881
		if (status & DP_AUX_CH_CTL_DONE)
-
 
882
			break;
882
				continue;
883
	}
883
			}
884
		if (status & DP_AUX_CH_CTL_DONE)
884
			if (status & DP_AUX_CH_CTL_DONE)
-
 
885
				goto done;
885
			break;
886
		}
Line 886... Line 887...
886
	}
887
	}
887
 
888
 
888
	if ((status & DP_AUX_CH_CTL_DONE) == 0) {
889
	if ((status & DP_AUX_CH_CTL_DONE) == 0) {
889
		DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
890
		DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
890
		ret = -EBUSY;
891
		ret = -EBUSY;
Line -... Line 892...
-
 
892
		goto out;
891
		goto out;
893
	}
892
	}
894
 
893
 
895
done:
894
	/* Check for timeout or receive error.
896
	/* Check for timeout or receive error.
895
	 * Timeouts occur when the sink is not connected
897
	 * Timeouts occur when the sink is not connected
Line 918... Line 920...
918
		intel_dp_unpack_aux(I915_READ(ch_data + i),
920
		intel_dp_unpack_aux(I915_READ(ch_data + i),
919
			   recv + i, recv_bytes - i);
921
				    recv + i, recv_bytes - i);
Line 920... Line 922...
920
 
922
 
921
	ret = recv_bytes;
923
	ret = recv_bytes;
922
out:
-
 
923
//	pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
-
 
Line 924... Line 924...
924
	intel_aux_display_runtime_put(dev_priv);
924
out:
925
 
925
 
Line 926... Line 926...
926
	if (vdd)
926
	if (vdd)
Line 939... Line 939...
939
	struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
939
	struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
940
	uint8_t txbuf[20], rxbuf[20];
940
	uint8_t txbuf[20], rxbuf[20];
941
	size_t txsize, rxsize;
941
	size_t txsize, rxsize;
942
	int ret;
942
	int ret;
Line 943... Line 943...
943
 
943
 
-
 
944
	txbuf[0] = (msg->request << 4) |
944
	txbuf[0] = msg->request << 4;
945
		((msg->address >> 16) & 0xf);
945
	txbuf[1] = msg->address >> 8;
946
	txbuf[1] = (msg->address >> 8) & 0xff;
946
	txbuf[2] = msg->address & 0xff;
947
	txbuf[2] = msg->address & 0xff;
Line 947... Line 948...
947
	txbuf[3] = msg->size - 1;
948
	txbuf[3] = msg->size - 1;
948
 
949
 
949
	switch (msg->request & ~DP_AUX_I2C_MOT) {
950
	switch (msg->request & ~DP_AUX_I2C_MOT) {
-
 
951
	case DP_AUX_NATIVE_WRITE:
950
	case DP_AUX_NATIVE_WRITE:
952
	case DP_AUX_I2C_WRITE:
951
	case DP_AUX_I2C_WRITE:
953
	case DP_AUX_I2C_WRITE_STATUS_UPDATE:
Line 952... Line 954...
952
		txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
954
		txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
953
		rxsize = 1;
955
		rxsize = 2; /* 0 or 1 data bytes */
Line 954... Line 956...
954
 
956
 
Line 955... Line 957...
955
		if (WARN_ON(txsize > 20))
957
		if (WARN_ON(txsize > 20))
956
		return -E2BIG;
958
			return -E2BIG;
957
 
959
 
Line -... Line 960...
-
 
960
		memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
-
 
961
 
-
 
962
		ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
-
 
963
		if (ret > 0) {
958
		memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
964
			msg->reply = rxbuf[0] >> 4;
959
 
965
 
960
		ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
966
			if (ret > 1) {
-
 
967
				/* Number of bytes written in a short write. */
961
		if (ret > 0) {
968
				ret = clamp_t(int, rxbuf[1], 0, msg->size);
Line 962... Line 969...
962
			msg->reply = rxbuf[0] >> 4;
969
			} else {
963
 
970
				/* Return payload size. */
964
			/* Return payload size. */
971
				ret = msg->size;
Line 998... Line 1005...
998
 
1005
 
999
static void
1006
static void
1000
intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
1007
intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
1001
{
1008
{
-
 
1009
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
1002
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
1010
	struct drm_i915_private *dev_priv = dev->dev_private;
1003
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1011
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
-
 
1012
	enum port port = intel_dig_port->port;
1004
	enum port port = intel_dig_port->port;
1013
	struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
-
 
1014
	const char *name = NULL;
1005
	const char *name = NULL;
1015
	uint32_t porte_aux_ctl_reg = DPA_AUX_CH_CTL;
Line -... Line 1016...
-
 
1016
	int ret;
-
 
1017
 
-
 
1018
	/* On SKL we don't have Aux for port E so we rely on VBT to set
-
 
1019
	 * a proper alternate aux channel.
-
 
1020
	 */
-
 
1021
	if (IS_SKYLAKE(dev) && port == PORT_E) {
-
 
1022
		switch (info->alternate_aux_channel) {
-
 
1023
		case DP_AUX_B:
-
 
1024
			porte_aux_ctl_reg = DPB_AUX_CH_CTL;
-
 
1025
			break;
-
 
1026
		case DP_AUX_C:
-
 
1027
			porte_aux_ctl_reg = DPC_AUX_CH_CTL;
-
 
1028
			break;
-
 
1029
		case DP_AUX_D:
-
 
1030
			porte_aux_ctl_reg = DPD_AUX_CH_CTL;
-
 
1031
			break;
-
 
1032
		case DP_AUX_A:
-
 
1033
		default:
-
 
1034
			porte_aux_ctl_reg = DPA_AUX_CH_CTL;
-
 
1035
		}
1006
	int ret;
1036
	}
1007
 
1037
 
1008
	switch (port) {
1038
	switch (port) {
1009
	case PORT_A:
1039
	case PORT_A:
1010
		intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
1040
		intel_dp->aux_ch_ctl_reg = DPA_AUX_CH_CTL;
Line 1020... Line 1050...
1020
		break;
1050
		break;
1021
	case PORT_D:
1051
	case PORT_D:
1022
		intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
1052
		intel_dp->aux_ch_ctl_reg = PCH_DPD_AUX_CH_CTL;
1023
		name = "DPDDC-D";
1053
		name = "DPDDC-D";
1024
		break;
1054
		break;
-
 
1055
	case PORT_E:
-
 
1056
		intel_dp->aux_ch_ctl_reg = porte_aux_ctl_reg;
-
 
1057
		name = "DPDDC-E";
-
 
1058
		break;
1025
	default:
1059
	default:
1026
		BUG();
1060
		BUG();
1027
	}
1061
	}
Line 1028... Line 1062...
1028
 
1062
 
Line 1033... Line 1067...
1033
	 *   - Both port A DDI_BUF_CTL and DDI_AUX_CTL are on the CPU
1067
	 *   - Both port A DDI_BUF_CTL and DDI_AUX_CTL are on the CPU
1034
	 *   - Port B/C/D AUX channels are on the PCH, DDI_BUF_CTL on the CPU
1068
	 *   - Port B/C/D AUX channels are on the PCH, DDI_BUF_CTL on the CPU
1035
	 *
1069
	 *
1036
	 * Skylake moves AUX_CTL back next to DDI_BUF_CTL, on the CPU.
1070
	 * Skylake moves AUX_CTL back next to DDI_BUF_CTL, on the CPU.
1037
	 */
1071
	 */
1038
	if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
1072
	if (!IS_HASWELL(dev) && !IS_BROADWELL(dev) && port != PORT_E)
1039
		intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
1073
		intel_dp->aux_ch_ctl_reg = intel_dp->output_reg + 0x10;
Line 1040... Line 1074...
1040
 
1074
 
1041
	intel_dp->aux.name = name;
1075
	intel_dp->aux.name = name;
1042
	intel_dp->aux.dev = dev->dev;
1076
	intel_dp->aux.dev = dev->dev;
Line 1043... Line 1077...
1043
	intel_dp->aux.transfer = intel_dp_aux_transfer;
1077
	intel_dp->aux.transfer = intel_dp_aux_transfer;
-
 
1078
 
Line 1044... Line 1079...
1044
 
1079
	DRM_DEBUG_KMS("registering %s bus for %s\n", name,
1045
	DRM_DEBUG_KMS("registering %s bus\n", name);
1080
					"");
1046
 
1081
 
1047
	ret = drm_dp_aux_register(&intel_dp->aux);
1082
	ret = drm_dp_aux_register(&intel_dp->aux);
Line 1059... Line 1094...
1059
 
1094
 
1060
	intel_connector_unregister(intel_connector);
1095
	intel_connector_unregister(intel_connector);
Line 1061... Line 1096...
1061
}
1096
}
1062
 
1097
 
1063
static void
1098
static void
1064
skl_edp_set_pll_config(struct intel_crtc_config *pipe_config, int link_bw)
1099
skl_edp_set_pll_config(struct intel_crtc_state *pipe_config)
Line -... Line 1100...
-
 
1100
{
-
 
1101
	u32 ctrl1;
-
 
1102
 
1065
{
1103
	memset(&pipe_config->dpll_hw_state, 0,
1066
	u32 ctrl1;
1104
	       sizeof(pipe_config->dpll_hw_state));
1067
 
1105
 
Line 1068... Line 1106...
1068
	pipe_config->ddi_pll_sel = SKL_DPLL0;
1106
	pipe_config->ddi_pll_sel = SKL_DPLL0;
1069
	pipe_config->dpll_hw_state.cfgcr1 = 0;
1107
	pipe_config->dpll_hw_state.cfgcr1 = 0;
1070
	pipe_config->dpll_hw_state.cfgcr2 = 0;
1108
	pipe_config->dpll_hw_state.cfgcr2 = 0;
1071
 
1109
 
1072
	ctrl1 = DPLL_CTRL1_OVERRIDE(SKL_DPLL0);
1110
	ctrl1 = DPLL_CTRL1_OVERRIDE(SKL_DPLL0);
1073
	switch (link_bw) {
1111
	switch (pipe_config->port_clock / 2) {
1074
	case DP_LINK_BW_1_62:
1112
	case 81000:
1075
		ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_810,
1113
		ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810,
1076
					      SKL_DPLL0);
1114
					      SKL_DPLL0);
1077
		break;
1115
		break;
1078
	case DP_LINK_BW_2_7:
1116
	case 135000:
1079
		ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_1350,
1117
		ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350,
-
 
1118
					      SKL_DPLL0);
-
 
1119
		break;
-
 
1120
	case 270000:
-
 
1121
		ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700,
1080
					      SKL_DPLL0);
1122
					      SKL_DPLL0);
1081
		break;
1123
		break;
-
 
1124
	case 162000:
-
 
1125
		ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620,
-
 
1126
					      SKL_DPLL0);
-
 
1127
		break;
-
 
1128
	/* TBD: For DP link rates 2.16 GHz and 4.32 GHz, VCO is 8640 which
-
 
1129
	results in CDCLK change. Need to handle the change of CDCLK by
-
 
1130
	disabling pipes and re-enabling them */
-
 
1131
	case 108000:
-
 
1132
		ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080,
-
 
1133
					      SKL_DPLL0);
-
 
1134
		break;
-
 
1135
	case 216000:
1082
	case DP_LINK_BW_5_4:
1136
		ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160,
1083
		ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_2700,
1137
					      SKL_DPLL0);
1084
					      SKL_DPLL0);
1138
		break;
Line 1085... Line 1139...
1085
		break;
1139
 
1086
	}
1140
	}
1087
	pipe_config->dpll_hw_state.ctrl1 = ctrl1;
1141
	pipe_config->dpll_hw_state.ctrl1 = ctrl1;
-
 
1142
}
-
 
1143
 
-
 
1144
void
1088
}
1145
hsw_dp_set_ddi_pll_sel(struct intel_crtc_state *pipe_config)
1089
 
1146
{
1090
static void
1147
	memset(&pipe_config->dpll_hw_state, 0,
1091
hsw_dp_set_ddi_pll_sel(struct intel_crtc_config *pipe_config, int link_bw)
1148
	       sizeof(pipe_config->dpll_hw_state));
1092
{
1149
 
1093
	switch (link_bw) {
1150
	switch (pipe_config->port_clock / 2) {
1094
	case DP_LINK_BW_1_62:
1151
	case 81000:
1095
		pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
1152
		pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
1096
		break;
1153
		break;
1097
	case DP_LINK_BW_2_7:
1154
	case 135000:
1098
		pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
1155
		pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
1099
		break;
1156
		break;
Line -... Line 1157...
-
 
1157
	case 270000:
-
 
1158
		pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
-
 
1159
		break;
-
 
1160
	}
-
 
1161
}
-
 
1162
 
-
 
1163
static int
-
 
1164
intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
-
 
1165
{
-
 
1166
	if (intel_dp->num_sink_rates) {
-
 
1167
		*sink_rates = intel_dp->sink_rates;
-
 
1168
		return intel_dp->num_sink_rates;
-
 
1169
	}
-
 
1170
 
-
 
1171
	*sink_rates = default_rates;
-
 
1172
 
-
 
1173
	return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
-
 
1174
}
-
 
1175
 
-
 
1176
static bool intel_dp_source_supports_hbr2(struct drm_device *dev)
-
 
1177
{
-
 
1178
	/* WaDisableHBR2:skl */
-
 
1179
	if (IS_SKYLAKE(dev) && INTEL_REVID(dev) <= SKL_REVID_B0)
-
 
1180
		return false;
-
 
1181
 
-
 
1182
	if ((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) || IS_BROADWELL(dev) ||
-
 
1183
	    (INTEL_INFO(dev)->gen >= 9))
-
 
1184
		return true;
-
 
1185
	else
-
 
1186
		return false;
-
 
1187
}
-
 
1188
 
-
 
1189
static int
-
 
1190
intel_dp_source_rates(struct drm_device *dev, const int **source_rates)
-
 
1191
{
-
 
1192
	int size;
-
 
1193
 
-
 
1194
	if (IS_BROXTON(dev)) {
-
 
1195
		*source_rates = bxt_rates;
-
 
1196
		size = ARRAY_SIZE(bxt_rates);
-
 
1197
	} else if (IS_SKYLAKE(dev)) {
-
 
1198
		*source_rates = skl_rates;
-
 
1199
		size = ARRAY_SIZE(skl_rates);
-
 
1200
	} else {
-
 
1201
		*source_rates = default_rates;
-
 
1202
		size = ARRAY_SIZE(default_rates);
-
 
1203
	}
-
 
1204
 
-
 
1205
	/* This depends on the fact that 5.4 is last value in the array */
1100
	case DP_LINK_BW_5_4:
1206
	if (!intel_dp_source_supports_hbr2(dev))
1101
		pipe_config->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
1207
		size--;
1102
		break;
1208
 
1103
	}
1209
	return size;
1104
}
1210
}
1105
 
1211
 
1106
static void
1212
static void
Line 1125... Line 1231...
1125
		count = ARRAY_SIZE(vlv_dpll);
1231
		count = ARRAY_SIZE(vlv_dpll);
1126
	}
1232
	}
Line 1127... Line 1233...
1127
 
1233
 
1128
	if (divisor && count) {
1234
	if (divisor && count) {
1129
		for (i = 0; i < count; i++) {
1235
		for (i = 0; i < count; i++) {
1130
			if (link_bw == divisor[i].link_bw) {
1236
			if (pipe_config->port_clock == divisor[i].clock) {
1131
				pipe_config->dpll = divisor[i].dpll;
1237
				pipe_config->dpll = divisor[i].dpll;
1132
				pipe_config->clock_set = true;
1238
				pipe_config->clock_set = true;
1133
				break;
1239
				break;
1134
			}
1240
			}
1135
		}
1241
		}
1136
	}
1242
	}
Line -... Line 1243...
-
 
1243
}
-
 
1244
 
-
 
1245
static int intersect_rates(const int *source_rates, int source_len,
-
 
1246
			   const int *sink_rates, int sink_len,
-
 
1247
			   int *common_rates)
-
 
1248
{
-
 
1249
	int i = 0, j = 0, k = 0;
-
 
1250
 
-
 
1251
	while (i < source_len && j < sink_len) {
-
 
1252
		if (source_rates[i] == sink_rates[j]) {
-
 
1253
			if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
-
 
1254
				return k;
-
 
1255
			common_rates[k] = source_rates[i];
-
 
1256
			++k;
-
 
1257
			++i;
-
 
1258
			++j;
-
 
1259
		} else if (source_rates[i] < sink_rates[j]) {
-
 
1260
			++i;
-
 
1261
		} else {
-
 
1262
			++j;
-
 
1263
		}
-
 
1264
	}
-
 
1265
	return k;
-
 
1266
}
-
 
1267
 
-
 
1268
static int intel_dp_common_rates(struct intel_dp *intel_dp,
-
 
1269
				 int *common_rates)
-
 
1270
{
-
 
1271
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
-
 
1272
	const int *source_rates, *sink_rates;
-
 
1273
	int source_len, sink_len;
-
 
1274
 
-
 
1275
	sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
-
 
1276
	source_len = intel_dp_source_rates(dev, &source_rates);
-
 
1277
 
-
 
1278
	return intersect_rates(source_rates, source_len,
-
 
1279
			       sink_rates, sink_len,
-
 
1280
			       common_rates);
-
 
1281
}
-
 
1282
 
-
 
1283
static void snprintf_int_array(char *str, size_t len,
-
 
1284
			       const int *array, int nelem)
-
 
1285
{
-
 
1286
	int i;
-
 
1287
 
-
 
1288
	str[0] = '\0';
-
 
1289
 
-
 
1290
	for (i = 0; i < nelem; i++) {
-
 
1291
		int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
-
 
1292
		if (r >= len)
-
 
1293
			return;
-
 
1294
		str += r;
-
 
1295
		len -= r;
-
 
1296
	}
-
 
1297
}
-
 
1298
 
-
 
1299
static void intel_dp_print_rates(struct intel_dp *intel_dp)
-
 
1300
{
-
 
1301
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
-
 
1302
	const int *source_rates, *sink_rates;
-
 
1303
	int source_len, sink_len, common_len;
-
 
1304
	int common_rates[DP_MAX_SUPPORTED_RATES];
-
 
1305
	char str[128]; /* FIXME: too big for stack? */
-
 
1306
 
-
 
1307
	if ((drm_debug & DRM_UT_KMS) == 0)
-
 
1308
		return;
-
 
1309
 
-
 
1310
	source_len = intel_dp_source_rates(dev, &source_rates);
-
 
1311
	snprintf_int_array(str, sizeof(str), source_rates, source_len);
-
 
1312
	DRM_DEBUG_KMS("source rates: %s\n", str);
-
 
1313
 
-
 
1314
	sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
-
 
1315
	snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
-
 
1316
	DRM_DEBUG_KMS("sink rates: %s\n", str);
-
 
1317
 
-
 
1318
	common_len = intel_dp_common_rates(intel_dp, common_rates);
-
 
1319
	snprintf_int_array(str, sizeof(str), common_rates, common_len);
-
 
1320
	DRM_DEBUG_KMS("common rates: %s\n", str);
-
 
1321
}
-
 
1322
 
-
 
1323
static int rate_to_index(int find, const int *rates)
-
 
1324
{
-
 
1325
	int i = 0;
-
 
1326
 
-
 
1327
	for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
-
 
1328
		if (find == rates[i])
-
 
1329
			break;
-
 
1330
 
-
 
1331
	return i;
-
 
1332
}
-
 
1333
 
-
 
1334
int
-
 
1335
intel_dp_max_link_rate(struct intel_dp *intel_dp)
-
 
1336
{
-
 
1337
	int rates[DP_MAX_SUPPORTED_RATES] = {};
-
 
1338
	int len;
-
 
1339
 
-
 
1340
	len = intel_dp_common_rates(intel_dp, rates);
-
 
1341
	if (WARN_ON(len <= 0))
-
 
1342
		return 162000;
-
 
1343
 
-
 
1344
	return rates[rate_to_index(0, rates) - 1];
-
 
1345
}
-
 
1346
 
-
 
1347
int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
-
 
1348
{
-
 
1349
	return rate_to_index(rate, intel_dp->sink_rates);
-
 
1350
}
-
 
1351
 
-
 
1352
static void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
-
 
1353
				  uint8_t *link_bw, uint8_t *rate_select)
-
 
1354
{
-
 
1355
	if (intel_dp->num_sink_rates) {
-
 
1356
		*link_bw = 0;
-
 
1357
		*rate_select =
-
 
1358
			intel_dp_rate_select(intel_dp, port_clock);
-
 
1359
	} else {
-
 
1360
		*link_bw = drm_dp_link_rate_to_bw_code(port_clock);
-
 
1361
		*rate_select = 0;
-
 
1362
	}
1137
}
1363
}
1138
 
1364
 
1139
bool
1365
bool
1140
intel_dp_compute_config(struct intel_encoder *encoder,
1366
intel_dp_compute_config(struct intel_encoder *encoder,
1141
			struct intel_crtc_config *pipe_config)
1367
			struct intel_crtc_state *pipe_config)
1142
{
1368
{
1143
	struct drm_device *dev = encoder->base.dev;
1369
	struct drm_device *dev = encoder->base.dev;
1144
	struct drm_i915_private *dev_priv = dev->dev_private;
1370
	struct drm_i915_private *dev_priv = dev->dev_private;
1145
	struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
1371
	struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1146
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1372
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1147
	enum port port = dp_to_dig_port(intel_dp)->port;
1373
	enum port port = dp_to_dig_port(intel_dp)->port;
1148
	struct intel_crtc *intel_crtc = encoder->new_crtc;
1374
	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
1149
	struct intel_connector *intel_connector = intel_dp->attached_connector;
1375
	struct intel_connector *intel_connector = intel_dp->attached_connector;
1150
	int lane_count, clock;
1376
	int lane_count, clock;
1151
	int min_lane_count = 1;
1377
	int min_lane_count = 1;
1152
	int max_lane_count = intel_dp_max_lane_count(intel_dp);
1378
	int max_lane_count = intel_dp_max_lane_count(intel_dp);
1153
	/* Conveniently, the link BW constants become indices with a shift...*/
1379
	/* Conveniently, the link BW constants become indices with a shift...*/
1154
	int min_clock = 0;
1380
	int min_clock = 0;
1155
	int max_clock = intel_dp_max_link_bw(intel_dp) >> 3;
-
 
1156
	int bpp, mode_rate;
1381
	int max_clock;
-
 
1382
	int bpp, mode_rate;
-
 
1383
	int link_avail, link_clock;
-
 
1384
	int common_rates[DP_MAX_SUPPORTED_RATES] = {};
-
 
1385
	int common_len;
-
 
1386
	uint8_t link_bw, rate_select;
-
 
1387
 
-
 
1388
	common_len = intel_dp_common_rates(intel_dp, common_rates);
-
 
1389
 
-
 
1390
	/* No common link rates between source and sink */
-
 
1391
	WARN_ON(common_len <= 0);
Line 1157... Line 1392...
1157
	static int bws[] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };
1392
 
1158
	int link_avail, link_clock;
1393
	max_clock = common_len - 1;
Line 1159... Line 1394...
1159
 
1394
 
1160
	if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
1395
	if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
1161
		pipe_config->has_pch_encoder = true;
1396
		pipe_config->has_pch_encoder = true;
Line 1162... Line 1397...
1162
 
1397
 
1163
	pipe_config->has_dp_encoder = true;
1398
	pipe_config->has_dp_encoder = true;
1164
	pipe_config->has_drrs = false;
1399
	pipe_config->has_drrs = false;
-
 
1400
	pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
-
 
1401
 
-
 
1402
	if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
-
 
1403
		intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
-
 
1404
				       adjusted_mode);
-
 
1405
 
-
 
1406
		if (INTEL_INFO(dev)->gen >= 9) {
-
 
1407
			int ret;
1165
	pipe_config->has_audio = intel_dp->has_audio;
1408
			ret = skl_update_scaler_crtc(pipe_config);
1166
 
1409
			if (ret)
1167
	if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1410
				return ret;
1168
		intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
1411
		}
1169
				       adjusted_mode);
1412
 
Line 1177... Line 1420...
1177
 
1420
 
1178
	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
1421
	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
Line 1179... Line 1422...
1179
		return false;
1422
		return false;
1180
 
1423
 
1181
	DRM_DEBUG_KMS("DP link computation with max lane count %i "
1424
	DRM_DEBUG_KMS("DP link computation with max lane count %i "
1182
		      "max bw %02x pixel clock %iKHz\n",
1425
		      "max bw %d pixel clock %iKHz\n",
Line 1183... Line 1426...
1183
		      max_lane_count, bws[max_clock],
1426
		      max_lane_count, common_rates[max_clock],
1184
		      adjusted_mode->crtc_clock);
1427
		      adjusted_mode->crtc_clock);
1185
 
1428
 
1186
	/* Walk through all bpp values. Luckily they're all nicely spaced with 2
1429
	/* Walk through all bpp values. Luckily they're all nicely spaced with 2
-
 
1430
	 * bpc in between. */
-
 
1431
	bpp = pipe_config->pipe_bpp;
-
 
1432
	if (is_edp(intel_dp)) {
1187
	 * bpc in between. */
1433
 
1188
	bpp = pipe_config->pipe_bpp;
1434
		/* Get bpp from vbt only for panels that dont have bpp in edid */
1189
	if (is_edp(intel_dp)) {
1435
		if (intel_connector->base.display_info.bpc == 0 &&
1190
		if (dev_priv->vbt.edp_bpp && dev_priv->vbt.edp_bpp < bpp) {
1436
			(dev_priv->vbt.edp_bpp && dev_priv->vbt.edp_bpp < bpp)) {
1191
		DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
1437
			DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
Line 1207... Line 1453...
1207
	for (; bpp >= 6*3; bpp -= 2*3) {
1453
	for (; bpp >= 6*3; bpp -= 2*3) {
1208
		mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1454
		mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1209
						   bpp);
1455
						   bpp);
Line 1210... Line 1456...
1210
 
1456
 
1211
		for (clock = min_clock; clock <= max_clock; clock++) {
1457
		for (clock = min_clock; clock <= max_clock; clock++) {
-
 
1458
			for (lane_count = min_lane_count;
-
 
1459
				lane_count <= max_lane_count;
-
 
1460
				lane_count <<= 1) {
1212
		for (lane_count = min_lane_count; lane_count <= max_lane_count; lane_count <<= 1) {
1461
 
1213
				link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
1462
				link_clock = common_rates[clock];
1214
				link_avail = intel_dp_max_data_rate(link_clock,
1463
				link_avail = intel_dp_max_data_rate(link_clock,
Line 1215... Line 1464...
1215
								    lane_count);
1464
								    lane_count);
1216
 
1465
 
Line 1228... Line 1477...
1228
		/*
1477
		/*
1229
		 * See:
1478
		 * See:
1230
		 * CEA-861-E - 5.1 Default Encoding Parameters
1479
		 * CEA-861-E - 5.1 Default Encoding Parameters
1231
		 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1480
		 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1232
		 */
1481
		 */
-
 
1482
		pipe_config->limited_color_range =
1233
		if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
1483
			bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
1234
			intel_dp->color_range = DP_COLOR_RANGE_16_235;
-
 
1235
		else
1484
	} else {
-
 
1485
		pipe_config->limited_color_range =
1236
			intel_dp->color_range = 0;
1486
			intel_dp->limited_color_range;
1237
	}
1487
	}
Line 1238... Line -...
1238
 
-
 
1239
	if (intel_dp->color_range)
1488
 
Line 1240... Line -...
1240
		pipe_config->limited_color_range = true;
-
 
1241
 
-
 
1242
				intel_dp->link_bw = bws[clock];
1489
	pipe_config->lane_count = lane_count;
1243
				intel_dp->lane_count = lane_count;
1490
 
-
 
1491
	pipe_config->pipe_bpp = bpp;
-
 
1492
	pipe_config->port_clock = common_rates[clock];
-
 
1493
 
Line 1244... Line 1494...
1244
	pipe_config->pipe_bpp = bpp;
1494
	intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1245
	pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
1495
			      &link_bw, &rate_select);
1246
 
1496
 
1247
	DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
1497
	DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1248
				       intel_dp->link_bw, intel_dp->lane_count,
1498
		      link_bw, rate_select, pipe_config->lane_count,
Line 1249... Line 1499...
1249
		      pipe_config->port_clock, bpp);
1499
		      pipe_config->port_clock, bpp);
1250
				DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1500
	DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1251
					      mode_rate, link_avail);
1501
		      mode_rate, link_avail);
1252
 
1502
 
Line 1253... Line 1503...
1253
	intel_link_compute_m_n(bpp, lane_count,
1503
	intel_link_compute_m_n(bpp, lane_count,
1254
			       adjusted_mode->crtc_clock,
1504
			       adjusted_mode->crtc_clock,
1255
			       pipe_config->port_clock,
1505
			       pipe_config->port_clock,
1256
			       &pipe_config->dp_m_n);
1506
			       &pipe_config->dp_m_n);
1257
 
1507
 
1258
	if (intel_connector->panel.downclock_mode != NULL &&
1508
	if (intel_connector->panel.downclock_mode != NULL &&
1259
		intel_dp->drrs_state.type == SEAMLESS_DRRS_SUPPORT) {
1509
		dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
1260
			pipe_config->has_drrs = true;
1510
			pipe_config->has_drrs = true;
Line 1261... Line 1511...
1261
			intel_link_compute_m_n(bpp, lane_count,
1511
			intel_link_compute_m_n(bpp, lane_count,
1262
				intel_connector->panel.downclock_mode->clock,
1512
				intel_connector->panel.downclock_mode->clock,
-
 
1513
				pipe_config->port_clock,
-
 
1514
				&pipe_config->dp_m2_n2);
1263
				pipe_config->port_clock,
1515
	}
1264
				&pipe_config->dp_m2_n2);
1516
 
1265
	}
1517
	if (IS_SKYLAKE(dev) && is_edp(intel_dp))
1266
 
1518
		skl_edp_set_pll_config(pipe_config);
Line 1267... Line 1519...
1267
	if (IS_SKYLAKE(dev) && is_edp(intel_dp))
1519
	else if (IS_BROXTON(dev))
1268
		skl_edp_set_pll_config(pipe_config, intel_dp->link_bw);
1520
		/* handled in ddi */;
Line 1269... Line 1521...
1269
	else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1521
	else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Line 1280... Line 1532...
1280
	struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1532
	struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
1281
	struct drm_device *dev = crtc->base.dev;
1533
	struct drm_device *dev = crtc->base.dev;
1282
	struct drm_i915_private *dev_priv = dev->dev_private;
1534
	struct drm_i915_private *dev_priv = dev->dev_private;
1283
	u32 dpa_ctl;
1535
	u32 dpa_ctl;
Line 1284... Line 1536...
1284
 
1536
 
-
 
1537
	DRM_DEBUG_KMS("eDP PLL enable for clock %d\n",
1285
	DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
1538
		      crtc->config->port_clock);
1286
	dpa_ctl = I915_READ(DP_A);
1539
	dpa_ctl = I915_READ(DP_A);
Line 1287... Line 1540...
1287
	dpa_ctl &= ~DP_PLL_FREQ_MASK;
1540
	dpa_ctl &= ~DP_PLL_FREQ_MASK;
1288
 
1541
 
1289
	if (crtc->config.port_clock == 162000) {
1542
	if (crtc->config->port_clock == 162000) {
1290
		/* For a long time we've carried around a ILK-DevA w/a for the
1543
		/* For a long time we've carried around a ILK-DevA w/a for the
1291
		 * 160MHz clock. If we're really unlucky, it's still required.
1544
		 * 160MHz clock. If we're really unlucky, it's still required.
1292
		 */
1545
		 */
Line 1302... Line 1555...
1302
 
1555
 
1303
	POSTING_READ(DP_A);
1556
	POSTING_READ(DP_A);
1304
	udelay(500);
1557
	udelay(500);
Line -... Line 1558...
-
 
1558
}
-
 
1559
 
-
 
1560
void intel_dp_set_link_params(struct intel_dp *intel_dp,
-
 
1561
			      const struct intel_crtc_state *pipe_config)
-
 
1562
{
-
 
1563
	intel_dp->link_rate = pipe_config->port_clock;
-
 
1564
	intel_dp->lane_count = pipe_config->lane_count;
1305
}
1565
}
1306
 
1566
 
1307
static void intel_dp_prepare(struct intel_encoder *encoder)
1567
static void intel_dp_prepare(struct intel_encoder *encoder)
1308
{
1568
{
1309
	struct drm_device *dev = encoder->base.dev;
1569
	struct drm_device *dev = encoder->base.dev;
1310
	struct drm_i915_private *dev_priv = dev->dev_private;
1570
	struct drm_i915_private *dev_priv = dev->dev_private;
1311
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1571
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1312
	enum port port = dp_to_dig_port(intel_dp)->port;
1572
	enum port port = dp_to_dig_port(intel_dp)->port;
-
 
1573
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
-
 
1574
	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
Line 1313... Line 1575...
1313
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
1575
 
1314
	struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
1576
	intel_dp_set_link_params(intel_dp, crtc->config);
1315
 
1577
 
1316
	/*
1578
	/*
Line 1335... Line 1597...
1335
	 */
1597
	 */
1336
	intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
1598
	intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
Line 1337... Line 1599...
1337
 
1599
 
1338
	/* Handle DP bits in common between all three register formats */
1600
	/* Handle DP bits in common between all three register formats */
1339
	intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
1601
	intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
Line 1340... Line 1602...
1340
	intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
1602
	intel_dp->DP |= DP_PORT_WIDTH(crtc->config->lane_count);
1341
 
1603
 
Line 1342... Line 1604...
1342
	if (crtc->config.has_audio)
1604
	if (crtc->config->has_audio)
Line 1343... Line 1605...
1343
		intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
1605
		intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
1344
 
1606
 
1345
	/* Split out the IBX/CPU vs CPT settings */
1607
	/* Split out the IBX/CPU vs CPT settings */
1346
 
1608
 
1347
	if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
1609
	if (IS_GEN7(dev) && port == PORT_A) {
1348
		if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1610
		if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Line 1349... Line 1611...
1349
			intel_dp->DP |= DP_SYNC_HS_HIGH;
1611
			intel_dp->DP |= DP_SYNC_HS_HIGH;
1350
		if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1612
		if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Line 1351... Line 1613...
1351
			intel_dp->DP |= DP_SYNC_VS_HIGH;
1613
			intel_dp->DP |= DP_SYNC_VS_HIGH;
1352
		intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1614
		intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
-
 
1615
 
-
 
1616
		if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
-
 
1617
			intel_dp->DP |= DP_ENHANCED_FRAMING;
-
 
1618
 
-
 
1619
		intel_dp->DP |= crtc->pipe << 29;
-
 
1620
	} else if (HAS_PCH_CPT(dev) && port != PORT_A) {
-
 
1621
		u32 trans_dp;
-
 
1622
 
-
 
1623
		intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
-
 
1624
 
-
 
1625
		trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1353
 
1626
		if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
-
 
1627
			trans_dp |= TRANS_DP_ENH_FRAMING;
1354
		if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1628
		else
Line 1355... Line 1629...
1355
			intel_dp->DP |= DP_ENHANCED_FRAMING;
1629
			trans_dp &= ~TRANS_DP_ENH_FRAMING;
1356
 
1630
		I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
1357
		intel_dp->DP |= crtc->pipe << 29;
1631
	} else {
1358
	} else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
1632
		if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
1359
		if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
1633
		    crtc->config->limited_color_range)
Line 1360... Line 1634...
1360
		intel_dp->DP |= intel_dp->color_range;
1634
			intel_dp->DP |= DP_COLOR_RANGE_16_235;
1361
 
1635
 
Line 1362... Line 1636...
1362
		if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1636
		if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1363
			intel_dp->DP |= DP_SYNC_HS_HIGH;
-
 
1364
		if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
-
 
1365
			intel_dp->DP |= DP_SYNC_VS_HIGH;
-
 
1366
		intel_dp->DP |= DP_LINK_TRAIN_OFF;
1637
			intel_dp->DP |= DP_SYNC_HS_HIGH;
1367
 
-
 
1368
		if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1638
		if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1369
		intel_dp->DP |= DP_ENHANCED_FRAMING;
1639
			intel_dp->DP |= DP_SYNC_VS_HIGH;
1370
 
1640
		intel_dp->DP |= DP_LINK_TRAIN_OFF;
1371
		if (!IS_CHERRYVIEW(dev)) {
1641
 
Line 1372... Line 1642...
1372
		if (crtc->pipe == 1)
1642
		if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1373
		intel_dp->DP |= DP_PIPEB_SELECT;
1643
			intel_dp->DP |= DP_ENHANCED_FRAMING;
Line 1462... Line 1732...
1462
	u32 control;
1732
	u32 control;
Line 1463... Line 1733...
1463
 
1733
 
Line 1464... Line 1734...
1464
	lockdep_assert_held(&dev_priv->pps_mutex);
1734
	lockdep_assert_held(&dev_priv->pps_mutex);
-
 
1735
 
1465
 
1736
	control = I915_READ(_pp_ctrl_reg(intel_dp));
1466
	control = I915_READ(_pp_ctrl_reg(intel_dp));
1737
	if (!IS_BROXTON(dev)) {
-
 
1738
		control &= ~PANEL_UNLOCK_MASK;
1467
	control &= ~PANEL_UNLOCK_MASK;
1739
		control |= PANEL_UNLOCK_REGS;
1468
	control |= PANEL_UNLOCK_REGS;
1740
	}
Line 1469... Line 1741...
1469
	return control;
1741
	return control;
1470
}
1742
}
Line 1488... Line 1760...
1488
	lockdep_assert_held(&dev_priv->pps_mutex);
1760
	lockdep_assert_held(&dev_priv->pps_mutex);
Line 1489... Line 1761...
1489
 
1761
 
1490
	if (!is_edp(intel_dp))
1762
	if (!is_edp(intel_dp))
Line -... Line 1763...
-
 
1763
		return false;
1491
		return false;
1764
 
Line 1492... Line 1765...
1492
 
1765
	cancel_delayed_work(&intel_dp->panel_vdd_work);
1493
	intel_dp->want_panel_vdd = true;
1766
	intel_dp->want_panel_vdd = true;
Line 1494... Line 1767...
1494
 
1767
 
1495
	if (edp_have_panel_vdd(intel_dp))
1768
	if (edp_have_panel_vdd(intel_dp))
Line 1496... Line 1769...
1496
		return need_to_disable;
1769
		return need_to_disable;
1497
 
1770
 
Line 1542... Line 1815...
1542
 
1815
 
1543
	pps_lock(intel_dp);
1816
	pps_lock(intel_dp);
1544
	vdd = edp_panel_vdd_on(intel_dp);
1817
	vdd = edp_panel_vdd_on(intel_dp);
Line 1545... Line 1818...
1545
	pps_unlock(intel_dp);
1818
	pps_unlock(intel_dp);
1546
 
1819
 
1547
	WARN(!vdd, "eDP port %c VDD already requested on\n",
1820
	I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
Line 1548... Line 1821...
1548
	     port_name(dp_to_dig_port(intel_dp)->port));
1821
	     port_name(dp_to_dig_port(intel_dp)->port));
1549
}
1822
}
Line 1583... Line 1856...
1583
		I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
1856
	I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
Line 1584... Line 1857...
1584
 
1857
 
1585
		if ((pp & POWER_TARGET_ON) == 0)
1858
	if ((pp & POWER_TARGET_ON) == 0)
Line 1586... Line 1859...
1586
			intel_dp->last_power_cycle = jiffies;
1859
		intel_dp->last_power_cycle = jiffies;
1587
 
1860
 
1588
		power_domain = intel_display_port_power_domain(intel_encoder);
1861
	power_domain = intel_display_port_aux_power_domain(intel_encoder);
Line 1589... Line 1862...
1589
		intel_display_power_put(dev_priv, power_domain);
1862
	intel_display_power_put(dev_priv, power_domain);
1590
}
1863
}
Line 1626... Line 1899...
1626
	lockdep_assert_held(&dev_priv->pps_mutex);
1899
	lockdep_assert_held(&dev_priv->pps_mutex);
Line 1627... Line 1900...
1627
 
1900
 
1628
	if (!is_edp(intel_dp))
1901
	if (!is_edp(intel_dp))
Line 1629... Line 1902...
1629
		return;
1902
		return;
1630
 
1903
 
Line 1631... Line 1904...
1631
	WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
1904
	I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
Line 1632... Line 1905...
1632
	     port_name(dp_to_dig_port(intel_dp)->port));
1905
	     port_name(dp_to_dig_port(intel_dp)->port));
Line 1734... Line 2007...
1734
 
2007
 
1735
	intel_dp->last_power_cycle = jiffies;
2008
	intel_dp->last_power_cycle = jiffies;
Line 1736... Line 2009...
1736
	wait_panel_off(intel_dp);
2009
	wait_panel_off(intel_dp);
1737
 
2010
 
1738
	/* We got a reference when we enabled the VDD. */
2011
	/* We got a reference when we enabled the VDD. */
1739
	power_domain = intel_display_port_power_domain(intel_encoder);
2012
	power_domain = intel_display_port_aux_power_domain(intel_encoder);
Line 1740... Line 2013...
1740
	intel_display_power_put(dev_priv, power_domain);
2013
	intel_display_power_put(dev_priv, power_domain);
1741
}
2014
}
Line 1956... Line 2229...
1956
	tmp = I915_READ(intel_dp->output_reg);
2229
	tmp = I915_READ(intel_dp->output_reg);
Line 1957... Line 2230...
1957
 
2230
 
1958
	if (!(tmp & DP_PORT_EN))
2231
	if (!(tmp & DP_PORT_EN))
Line 1959... Line 2232...
1959
		return false;
2232
		return false;
1960
 
2233
 
1961
	if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
-
 
1962
		*pipe = PORT_TO_PIPE_CPT(tmp);
-
 
1963
	} else if (IS_CHERRYVIEW(dev)) {
2234
	if (IS_GEN7(dev) && port == PORT_A) {
1964
		*pipe = DP_PORT_TO_PIPE_CHV(tmp);
-
 
1965
	} else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
-
 
1966
		*pipe = PORT_TO_PIPE(tmp);
-
 
1967
	} else {
-
 
1968
		u32 trans_sel;
-
 
1969
		u32 trans_dp;
-
 
1970
		int i;
-
 
1971
 
-
 
1972
		switch (intel_dp->output_reg) {
-
 
1973
		case PCH_DP_B:
-
 
1974
			trans_sel = TRANS_DP_PORT_SEL_B;
-
 
1975
			break;
-
 
1976
		case PCH_DP_C:
-
 
1977
			trans_sel = TRANS_DP_PORT_SEL_C;
-
 
1978
			break;
-
 
1979
		case PCH_DP_D:
-
 
1980
			trans_sel = TRANS_DP_PORT_SEL_D;
-
 
1981
			break;
2235
		*pipe = PORT_TO_PIPE_CPT(tmp);
1982
		default:
-
 
Line 1983... Line 2236...
1983
			return true;
2236
	} else if (HAS_PCH_CPT(dev) && port != PORT_A) {
1984
		}
2237
		enum pipe p;
1985
 
2238
 
1986
		for_each_pipe(dev_priv, i) {
2239
		for_each_pipe(dev_priv, p) {
1987
			trans_dp = I915_READ(TRANS_DP_CTL(i));
2240
			u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
1988
			if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
2241
			if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
1989
				*pipe = i;
2242
				*pipe = p;
Line 1990... Line 2243...
1990
				return true;
2243
				return true;
1991
			}
2244
			}
-
 
2245
		}
-
 
2246
 
-
 
2247
		DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
-
 
2248
			      intel_dp->output_reg);
1992
		}
2249
	} else if (IS_CHERRYVIEW(dev)) {
Line 1993... Line 2250...
1993
 
2250
		*pipe = DP_PORT_TO_PIPE_CHV(tmp);
1994
		DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
2251
	} else {
Line 1995... Line 2252...
1995
			      intel_dp->output_reg);
2252
		*pipe = PORT_TO_PIPE(tmp);
1996
	}
2253
	}
1997
 
2254
 
1998
	return true;
2255
	return true;
1999
}
2256
}
2000
 
2257
 
2001
static void intel_dp_get_config(struct intel_encoder *encoder,
2258
static void intel_dp_get_config(struct intel_encoder *encoder,
2002
				struct intel_crtc_config *pipe_config)
2259
				struct intel_crtc_state *pipe_config)
2003
{
2260
{
2004
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2261
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Line 2005... Line 2262...
2005
	u32 tmp, flags = 0;
2262
	u32 tmp, flags = 0;
2006
	struct drm_device *dev = encoder->base.dev;
-
 
2007
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
Line -... Line 2263...
-
 
2263
	struct drm_device *dev = encoder->base.dev;
-
 
2264
	struct drm_i915_private *dev_priv = dev->dev_private;
2008
	enum port port = dp_to_dig_port(intel_dp)->port;
2265
	enum port port = dp_to_dig_port(intel_dp)->port;
-
 
2266
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
-
 
2267
	int dotclock;
2009
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
2268
 
2010
	int dotclock;
2269
	tmp = I915_READ(intel_dp->output_reg);
2011
 
2270
 
2012
	tmp = I915_READ(intel_dp->output_reg);
2271
	pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
Line 2013... Line 2272...
2013
	if (tmp & DP_AUDIO_OUTPUT_ENABLE)
2272
 
2014
		pipe_config->has_audio = true;
2273
	if (HAS_PCH_CPT(dev) && port != PORT_A) {
2015
 
2274
		u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2016
	if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
2275
 
2017
		if (tmp & DP_SYNC_HS_HIGH)
2276
		if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
2018
			flags |= DRM_MODE_FLAG_PHSYNC;
-
 
2019
		else
2277
			flags |= DRM_MODE_FLAG_PHSYNC;
2020
			flags |= DRM_MODE_FLAG_NHSYNC;
2278
		else
2021
 
2279
			flags |= DRM_MODE_FLAG_NHSYNC;
2022
		if (tmp & DP_SYNC_VS_HIGH)
2280
 
Line 2023... Line 2281...
2023
			flags |= DRM_MODE_FLAG_PVSYNC;
2281
		if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
2024
		else
2282
			flags |= DRM_MODE_FLAG_PVSYNC;
2025
			flags |= DRM_MODE_FLAG_NVSYNC;
2283
		else
2026
	} else {
2284
			flags |= DRM_MODE_FLAG_NVSYNC;
2027
		tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2285
	} else {
Line 2028... Line 2286...
2028
		if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
2286
		if (tmp & DP_SYNC_HS_HIGH)
Line 2029... Line 2287...
2029
			flags |= DRM_MODE_FLAG_PHSYNC;
2287
			flags |= DRM_MODE_FLAG_PHSYNC;
2030
		else
2288
		else
2031
			flags |= DRM_MODE_FLAG_NHSYNC;
2289
			flags |= DRM_MODE_FLAG_NHSYNC;
Line 2032... Line 2290...
2032
 
2290
 
Line -... Line 2291...
-
 
2291
		if (tmp & DP_SYNC_VS_HIGH)
-
 
2292
			flags |= DRM_MODE_FLAG_PVSYNC;
-
 
2293
		else
2033
		if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
2294
			flags |= DRM_MODE_FLAG_NVSYNC;
Line 2034... Line 2295...
2034
			flags |= DRM_MODE_FLAG_PVSYNC;
2295
	}
2035
		else
2296
 
2036
			flags |= DRM_MODE_FLAG_NVSYNC;
2297
	pipe_config->base.adjusted_mode.flags |= flags;
Line 2057... Line 2318...
2057
					    &pipe_config->dp_m_n);
2318
					    &pipe_config->dp_m_n);
Line 2058... Line 2319...
2058
 
2319
 
2059
	if (HAS_PCH_SPLIT(dev_priv->dev) && port != PORT_A)
2320
	if (HAS_PCH_SPLIT(dev_priv->dev) && port != PORT_A)
Line 2060... Line 2321...
2060
		ironlake_check_encoder_dotclock(pipe_config, dotclock);
2321
		ironlake_check_encoder_dotclock(pipe_config, dotclock);
Line 2061... Line 2322...
2061
 
2322
 
2062
	pipe_config->adjusted_mode.crtc_clock = dotclock;
2323
	pipe_config->base.adjusted_mode.crtc_clock = dotclock;
2063
 
2324
 
2064
	if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
2325
	if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
Line 2086... Line 2347...
2086
{
2347
{
2087
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2348
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2088
	struct drm_device *dev = encoder->base.dev;
2349
	struct drm_device *dev = encoder->base.dev;
2089
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
2350
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Line 2090... Line 2351...
2090
 
2351
 
2091
	if (crtc->config.has_audio)
2352
	if (crtc->config->has_audio)
Line -... Line 2353...
-
 
2353
		intel_audio_codec_disable(encoder);
-
 
2354
 
-
 
2355
	if (HAS_PSR(dev) && !HAS_DDI(dev))
2092
		intel_audio_codec_disable(encoder);
2356
		intel_psr_disable(intel_dp);
2093
 
2357
 
2094
	/* Make sure the panel is off before trying to change the mode. But also
2358
	/* Make sure the panel is off before trying to change the mode. But also
2095
	 * ensure that we have vdd while we switch off the panel. */
2359
	 * ensure that we have vdd while we switch off the panel. */
2096
	intel_edp_panel_vdd_on(intel_dp);
2360
	intel_edp_panel_vdd_on(intel_dp);
Line 2118... Line 2382...
2118
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2382
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Line 2119... Line 2383...
2119
 
2383
 
2120
	intel_dp_link_down(intel_dp);
2384
	intel_dp_link_down(intel_dp);
Line 2121... Line 2385...
2121
}
2385
}
-
 
2386
 
2122
 
2387
static void chv_data_lane_soft_reset(struct intel_encoder *encoder,
2123
static void chv_post_disable_dp(struct intel_encoder *encoder)
2388
				     bool reset)
2124
{
2389
{
2125
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
-
 
2126
	struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
-
 
2127
	struct drm_device *dev = encoder->base.dev;
-
 
2128
	struct drm_i915_private *dev_priv = dev->dev_private;
2390
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2129
	struct intel_crtc *intel_crtc =
-
 
2130
		to_intel_crtc(encoder->base.crtc);
2391
	enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
2131
	enum dpio_channel ch = vlv_dport_to_channel(dport);
2392
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
Line 2132... Line 2393...
2132
	enum pipe pipe = intel_crtc->pipe;
2393
	enum pipe pipe = crtc->pipe;
-
 
2394
	uint32_t val;
-
 
2395
 
-
 
2396
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
-
 
2397
	if (reset)
-
 
2398
		val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
Line -... Line 2399...
-
 
2399
	else
2133
	u32 val;
2400
		val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
-
 
2401
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
-
 
2402
 
-
 
2403
	if (crtc->config->lane_count > 2) {
-
 
2404
		val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
-
 
2405
		if (reset)
-
 
2406
			val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
Line 2134... Line -...
2134
 
-
 
2135
		intel_dp_link_down(intel_dp);
2407
		else
2136
 
2408
			val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
-
 
2409
		vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
-
 
2410
	}
-
 
2411
 
-
 
2412
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
2137
	mutex_lock(&dev_priv->dpio_lock);
2413
	val |= CHV_PCS_REQ_SOFTRESET_EN;
Line -... Line 2414...
-
 
2414
	if (reset)
2138
 
2415
		val &= ~DPIO_PCS_CLK_SOFT_RESET;
2139
	/* Propagate soft reset to data lane reset */
2416
	else
-
 
2417
		val |= DPIO_PCS_CLK_SOFT_RESET;
-
 
2418
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
-
 
2419
 
-
 
2420
	if (crtc->config->lane_count > 2) {
2140
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
2421
		val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
-
 
2422
		val |= CHV_PCS_REQ_SOFTRESET_EN;
-
 
2423
		if (reset)
Line 2141... Line 2424...
2141
	val |= CHV_PCS_REQ_SOFTRESET_EN;
2424
			val &= ~DPIO_PCS_CLK_SOFT_RESET;
-
 
2425
		else
2142
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
2426
			val |= DPIO_PCS_CLK_SOFT_RESET;
-
 
2427
		vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
2143
 
2428
	}
Line 2144... Line 2429...
2144
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
2429
}
2145
	val |= CHV_PCS_REQ_SOFTRESET_EN;
-
 
2146
	vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
-
 
Line -... Line 2430...
-
 
2430
 
-
 
2431
static void chv_post_disable_dp(struct intel_encoder *encoder)
-
 
2432
{
-
 
2433
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
-
 
2434
	struct drm_device *dev = encoder->base.dev;
2147
 
2435
	struct drm_i915_private *dev_priv = dev->dev_private;
2148
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
2436
 
Line 2149... Line 2437...
2149
	val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
2437
	intel_dp_link_down(intel_dp);
2150
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
2438
 
2151
 
2439
	mutex_lock(&dev_priv->sb_lock);
Line 2190... Line 2478...
2190
			temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2478
			temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2191
			break;
2479
			break;
2192
		}
2480
		}
2193
		I915_WRITE(DP_TP_CTL(port), temp);
2481
		I915_WRITE(DP_TP_CTL(port), temp);
Line -... Line 2482...
-
 
2482
 
2194
 
2483
	} else if ((IS_GEN7(dev) && port == PORT_A) ||
2195
	} else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
2484
		   (HAS_PCH_CPT(dev) && port != PORT_A)) {
Line 2196... Line 2485...
2196
		*DP &= ~DP_LINK_TRAIN_MASK_CPT;
2485
		*DP &= ~DP_LINK_TRAIN_MASK_CPT;
2197
 
2486
 
2198
		switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2487
		switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
Line 2285... Line 2574...
2285
	edp_panel_on(intel_dp);
2574
	edp_panel_on(intel_dp);
2286
	edp_panel_vdd_off(intel_dp, true);
2575
	edp_panel_vdd_off(intel_dp, true);
Line 2287... Line 2576...
2287
 
2576
 
Line 2288... Line 2577...
2288
	pps_unlock(intel_dp);
2577
	pps_unlock(intel_dp);
-
 
2578
 
-
 
2579
	if (IS_VALLEYVIEW(dev)) {
-
 
2580
		unsigned int lane_mask = 0x0;
-
 
2581
 
-
 
2582
		if (IS_CHERRYVIEW(dev))
2289
 
2583
			lane_mask = intel_dp_unused_lane_mask(crtc->config->lane_count);
-
 
2584
 
-
 
2585
		vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
Line 2290... Line 2586...
2290
	if (IS_VALLEYVIEW(dev))
2586
				    lane_mask);
2291
		vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp));
2587
	}
2292
 
-
 
2293
	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2588
 
Line 2294... Line 2589...
2294
			intel_dp_start_link_train(intel_dp);
2589
	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2295
			intel_dp_complete_link_train(intel_dp);
2590
	intel_dp_start_link_train(intel_dp);
2296
	intel_dp_stop_link_train(intel_dp);
2591
	intel_dp_stop_link_train(intel_dp);
2297
 
2592
 
2298
	if (crtc->config.has_audio) {
2593
	if (crtc->config->has_audio) {
2299
		DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
2594
		DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
Line 2313... Line 2608...
2313
static void vlv_enable_dp(struct intel_encoder *encoder)
2608
static void vlv_enable_dp(struct intel_encoder *encoder)
2314
{
2609
{
2315
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2610
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Line 2316... Line 2611...
2316
 
2611
 
-
 
2612
	intel_edp_backlight_on(intel_dp);
2317
	intel_edp_backlight_on(intel_dp);
2613
	intel_psr_enable(intel_dp);
Line 2318... Line 2614...
2318
}
2614
}
2319
 
2615
 
2320
static void g4x_pre_enable_dp(struct intel_encoder *encoder)
2616
static void g4x_pre_enable_dp(struct intel_encoder *encoder)
Line 2383... Line 2679...
2383
			continue;
2679
			continue;
Line 2384... Line 2680...
2384
 
2680
 
2385
		DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
2681
		DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
Line 2386... Line 2682...
2386
			      pipe_name(pipe), port_name(port));
2682
			      pipe_name(pipe), port_name(port));
2387
 
2683
 
2388
		WARN(encoder->connectors_active,
2684
		WARN(encoder->base.crtc,
Line 2389... Line 2685...
2389
		     "stealing pipe %c power sequencer from active eDP port %c\n",
2685
		     "stealing pipe %c power sequencer from active eDP port %c\n",
2390
		     pipe_name(pipe), port_name(port));
2686
		     pipe_name(pipe), port_name(port));
Line 2444... Line 2740...
2444
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
2740
	struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
2445
	enum dpio_channel port = vlv_dport_to_channel(dport);
2741
	enum dpio_channel port = vlv_dport_to_channel(dport);
2446
		int pipe = intel_crtc->pipe;
2742
	int pipe = intel_crtc->pipe;
2447
		u32 val;
2743
	u32 val;
Line 2448... Line 2744...
2448
 
2744
 
Line 2449... Line 2745...
2449
	mutex_lock(&dev_priv->dpio_lock);
2745
	mutex_lock(&dev_priv->sb_lock);
2450
 
2746
 
2451
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
2747
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
2452
		val = 0;
2748
	val = 0;
Line 2457... Line 2753...
2457
		val |= 0x001000c4;
2753
	val |= 0x001000c4;
2458
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
2754
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
2459
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
2755
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
2460
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
2756
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
Line 2461... Line 2757...
2461
 
2757
 
Line 2462... Line 2758...
2462
	mutex_unlock(&dev_priv->dpio_lock);
2758
	mutex_unlock(&dev_priv->sb_lock);
2463
 
2759
 
Line 2464... Line 2760...
2464
	intel_enable_dp(encoder);
2760
	intel_enable_dp(encoder);
Line 2475... Line 2771...
2475
	int pipe = intel_crtc->pipe;
2771
	int pipe = intel_crtc->pipe;
Line 2476... Line 2772...
2476
 
2772
 
Line 2477... Line 2773...
2477
	intel_dp_prepare(encoder);
2773
	intel_dp_prepare(encoder);
2478
 
2774
 
2479
	/* Program Tx lane resets to default */
2775
	/* Program Tx lane resets to default */
2480
	mutex_lock(&dev_priv->dpio_lock);
2776
	mutex_lock(&dev_priv->sb_lock);
2481
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
2777
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
2482
			 DPIO_PCS_TX_LANE2_RESET |
2778
			 DPIO_PCS_TX_LANE2_RESET |
2483
			 DPIO_PCS_TX_LANE1_RESET);
2779
			 DPIO_PCS_TX_LANE1_RESET);
Line 2489... Line 2785...
2489
 
2785
 
2490
	/* Fix up inter-pair skew failure */
2786
	/* Fix up inter-pair skew failure */
2491
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
2787
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
2492
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
2788
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
2493
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
2789
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
2494
	mutex_unlock(&dev_priv->dpio_lock);
2790
	mutex_unlock(&dev_priv->sb_lock);
Line 2495... Line 2791...
2495
}
2791
}
2496
 
2792
 
2497
static void chv_pre_enable_dp(struct intel_encoder *encoder)
2793
static void chv_pre_enable_dp(struct intel_encoder *encoder)
Line 2502... Line 2798...
2502
	struct drm_i915_private *dev_priv = dev->dev_private;
2798
	struct drm_i915_private *dev_priv = dev->dev_private;
2503
	struct intel_crtc *intel_crtc =
2799
	struct intel_crtc *intel_crtc =
2504
		to_intel_crtc(encoder->base.crtc);
2800
		to_intel_crtc(encoder->base.crtc);
2505
	enum dpio_channel ch = vlv_dport_to_channel(dport);
2801
	enum dpio_channel ch = vlv_dport_to_channel(dport);
2506
	int pipe = intel_crtc->pipe;
2802
	int pipe = intel_crtc->pipe;
2507
	int data, i;
2803
	int data, i, stagger;
2508
	u32 val;
2804
	u32 val;
Line 2509... Line 2805...
2509
 
2805
 
Line 2510... Line 2806...
2510
	mutex_lock(&dev_priv->dpio_lock);
2806
	mutex_lock(&dev_priv->sb_lock);
2511
 
2807
 
2512
	/* allow hardware to manage TX FIFO reset source */
2808
	/* allow hardware to manage TX FIFO reset source */
2513
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
2809
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
Line -... Line 2810...
-
 
2810
	val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
2514
	val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
2811
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
2515
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
2812
 
2516
 
2813
	if (intel_crtc->config->lane_count > 2) {
2517
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
-
 
2518
	val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
-
 
2519
	vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
-
 
2520
 
-
 
2521
	/* Deassert soft data lane reset*/
-
 
2522
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
2814
		val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
2523
	val |= CHV_PCS_REQ_SOFTRESET_EN;
-
 
2524
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
-
 
2525
 
-
 
2526
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
-
 
2527
	val |= CHV_PCS_REQ_SOFTRESET_EN;
-
 
2528
	vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
-
 
2529
 
-
 
2530
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
-
 
2531
	val |= (DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
-
 
2532
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
-
 
2533
 
-
 
Line 2534... Line 2815...
2534
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
2815
		val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
2535
	val |= (DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
2816
		vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
2536
	vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
-
 
2537
 
-
 
2538
	/* Program Tx lane latency optimal setting*/
-
 
2539
	for (i = 0; i < 4; i++) {
-
 
2540
		/* Set the latency optimal bit */
-
 
2541
		data = (i == 1) ? 0x0 : 0x6;
2817
	}
-
 
2818
 
-
 
2819
	/* Program Tx lane latency optimal setting*/
-
 
2820
	for (i = 0; i < intel_crtc->config->lane_count; i++) {
2542
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW11(ch, i),
2821
		/* Set the upar bit */
2543
				data << DPIO_FRC_LATENCY_SHFIT);
2822
		if (intel_crtc->config->lane_count == 1)
2544
 
2823
			data = 0x0;
2545
		/* Set the upar bit */
2824
		else
Line 2546... Line 2825...
2546
		data = (i == 1) ? 0x0 : 0x1;
2825
			data = (i == 1) ? 0x0 : 0x1;
-
 
2826
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
-
 
2827
				data << DPIO_UPAR_SHIFT);
2547
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
2828
	}
-
 
2829
 
-
 
2830
	/* Data lane stagger programming */
-
 
2831
	if (intel_crtc->config->port_clock > 270000)
-
 
2832
		stagger = 0x18;
-
 
2833
	else if (intel_crtc->config->port_clock > 135000)
-
 
2834
		stagger = 0xd;
-
 
2835
	else if (intel_crtc->config->port_clock > 67500)
Line -... Line 2836...
-
 
2836
		stagger = 0x7;
-
 
2837
	else if (intel_crtc->config->port_clock > 33750)
-
 
2838
		stagger = 0x4;
-
 
2839
	else
-
 
2840
		stagger = 0x2;
-
 
2841
 
-
 
2842
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
-
 
2843
	val |= DPIO_TX2_STAGGER_MASK(0x1f);
-
 
2844
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
-
 
2845
 
-
 
2846
	if (intel_crtc->config->lane_count > 2) {
-
 
2847
		val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
-
 
2848
		val |= DPIO_TX2_STAGGER_MASK(0x1f);
-
 
2849
		vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
-
 
2850
	}
-
 
2851
 
-
 
2852
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
-
 
2853
		       DPIO_LANESTAGGER_STRAP(stagger) |
-
 
2854
		       DPIO_LANESTAGGER_STRAP_OVRD |
-
 
2855
		       DPIO_TX1_STAGGER_MASK(0x1f) |
-
 
2856
		       DPIO_TX1_STAGGER_MULT(6) |
-
 
2857
		       DPIO_TX2_STAGGER_MULT(0));
-
 
2858
 
-
 
2859
	if (intel_crtc->config->lane_count > 2) {
-
 
2860
		vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
-
 
2861
			       DPIO_LANESTAGGER_STRAP(stagger) |
-
 
2862
			       DPIO_LANESTAGGER_STRAP_OVRD |
-
 
2863
			       DPIO_TX1_STAGGER_MASK(0x1f) |
-
 
2864
			       DPIO_TX1_STAGGER_MULT(7) |
2548
				data << DPIO_UPAR_SHIFT);
2865
			       DPIO_TX2_STAGGER_MULT(5));
Line 2549... Line 2866...
2549
	}
2866
	}
-
 
2867
 
-
 
2868
	/* Deassert data lane reset */
-
 
2869
	chv_data_lane_soft_reset(encoder, false);
-
 
2870
 
-
 
2871
	mutex_unlock(&dev_priv->sb_lock);
-
 
2872
 
2550
 
2873
	intel_enable_dp(encoder);
Line 2551... Line 2874...
2551
	/* Data lane stagger programming */
2874
 
2552
	/* FIXME: Fix up value only after power analysis */
2875
	/* Second common lane will stay alive on its own now */
2553
 
2876
	if (dport->release_cl2_override) {
Line 2563... Line 2886...
2563
	struct drm_i915_private *dev_priv = dev->dev_private;
2886
	struct drm_i915_private *dev_priv = dev->dev_private;
2564
	struct intel_crtc *intel_crtc =
2887
	struct intel_crtc *intel_crtc =
2565
		to_intel_crtc(encoder->base.crtc);
2888
		to_intel_crtc(encoder->base.crtc);
2566
	enum dpio_channel ch = vlv_dport_to_channel(dport);
2889
	enum dpio_channel ch = vlv_dport_to_channel(dport);
2567
	enum pipe pipe = intel_crtc->pipe;
2890
	enum pipe pipe = intel_crtc->pipe;
-
 
2891
	unsigned int lane_mask =
-
 
2892
		intel_dp_unused_lane_mask(intel_crtc->config->lane_count);
2568
	u32 val;
2893
	u32 val;
Line 2569... Line 2894...
2569
 
2894
 
Line -... Line 2895...
-
 
2895
	intel_dp_prepare(encoder);
-
 
2896
 
-
 
2897
	/*
-
 
2898
	 * Must trick the second common lane into life.
-
 
2899
	 * Otherwise we can't even access the PLL.
-
 
2900
	 */
-
 
2901
	if (ch == DPIO_CH0 && pipe == PIPE_B)
-
 
2902
		dport->release_cl2_override =
-
 
2903
			!chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
-
 
2904
 
2570
	intel_dp_prepare(encoder);
2905
	chv_phy_powergate_lanes(encoder, true, lane_mask);
-
 
2906
 
-
 
2907
	mutex_lock(&dev_priv->sb_lock);
-
 
2908
 
Line 2571... Line 2909...
2571
 
2909
	/* Assert data lane reset */
2572
	mutex_lock(&dev_priv->dpio_lock);
2910
	chv_data_lane_soft_reset(encoder, true);
2573
 
2911
 
2574
	/* program left/right clock distribution */
2912
	/* program left/right clock distribution */
Line 2597... Line 2935...
2597
		val &= ~CHV_PCS_USEDCLKCHANNEL;
2935
		val &= ~CHV_PCS_USEDCLKCHANNEL;
2598
	else
2936
	else
2599
		val |= CHV_PCS_USEDCLKCHANNEL;
2937
		val |= CHV_PCS_USEDCLKCHANNEL;
2600
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
2938
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
Line -... Line 2939...
-
 
2939
 
2601
 
2940
	if (intel_crtc->config->lane_count > 2) {
2602
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
2941
		val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
2603
	val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
2942
		val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
2604
	if (pipe != PIPE_B)
2943
		if (pipe != PIPE_B)
2605
		val &= ~CHV_PCS_USEDCLKCHANNEL;
2944
			val &= ~CHV_PCS_USEDCLKCHANNEL;
2606
	else
2945
		else
2607
		val |= CHV_PCS_USEDCLKCHANNEL;
2946
			val |= CHV_PCS_USEDCLKCHANNEL;
-
 
2947
		vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
Line 2608... Line 2948...
2608
	vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
2948
	}
2609
 
2949
 
2610
	/*
2950
	/*
2611
	 * This a a bit weird since generally CL
2951
	 * This a a bit weird since generally CL
Line 2617... Line 2957...
2617
		val &= ~CHV_CMN_USEDCLKCHANNEL;
2957
		val &= ~CHV_CMN_USEDCLKCHANNEL;
2618
	else
2958
	else
2619
		val |= CHV_CMN_USEDCLKCHANNEL;
2959
		val |= CHV_CMN_USEDCLKCHANNEL;
2620
	vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
2960
	vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
Line 2621... Line 2961...
2621
 
2961
 
-
 
2962
	mutex_unlock(&dev_priv->sb_lock);
-
 
2963
}
-
 
2964
 
-
 
2965
static void chv_dp_post_pll_disable(struct intel_encoder *encoder)
-
 
2966
{
-
 
2967
	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
-
 
2968
	enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
-
 
2969
	u32 val;
-
 
2970
 
-
 
2971
	mutex_lock(&dev_priv->sb_lock);
-
 
2972
 
-
 
2973
	/* disable left/right clock distribution */
-
 
2974
	if (pipe != PIPE_B) {
-
 
2975
		val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
-
 
2976
		val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
-
 
2977
		vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
-
 
2978
	} else {
-
 
2979
		val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
-
 
2980
		val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
-
 
2981
		vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
-
 
2982
	}
-
 
2983
 
-
 
2984
	mutex_unlock(&dev_priv->sb_lock);
-
 
2985
 
-
 
2986
	/*
-
 
2987
	 * Leave the power down bit cleared for at least one
-
 
2988
	 * lane so that chv_powergate_phy_ch() will power
-
 
2989
	 * on something when the channel is otherwise unused.
-
 
2990
	 * When the port is off and the override is removed
-
 
2991
	 * the lanes power down anyway, so otherwise it doesn't
-
 
2992
	 * really matter what the state of power down bits is
-
 
2993
	 * after this.
-
 
2994
	 */
2622
	mutex_unlock(&dev_priv->dpio_lock);
2995
	chv_phy_powergate_lanes(encoder, false, 0x0);
Line 2623... Line 2996...
2623
}
2996
}
2624
 
2997
 
2625
/*
2998
/*
Line 2669... Line 3042...
2669
/* These are source-specific values. */
3042
/* These are source-specific values. */
2670
static uint8_t
3043
static uint8_t
2671
intel_dp_voltage_max(struct intel_dp *intel_dp)
3044
intel_dp_voltage_max(struct intel_dp *intel_dp)
2672
{
3045
{
2673
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
3046
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
-
 
3047
	struct drm_i915_private *dev_priv = dev->dev_private;
2674
	enum port port = dp_to_dig_port(intel_dp)->port;
3048
	enum port port = dp_to_dig_port(intel_dp)->port;
Line -... Line 3049...
-
 
3049
 
-
 
3050
	if (IS_BROXTON(dev))
2675
 
3051
		return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
-
 
3052
	else if (INTEL_INFO(dev)->gen >= 9) {
-
 
3053
		if (dev_priv->edp_low_vswing && port == PORT_A)
2676
	if (INTEL_INFO(dev)->gen >= 9)
3054
			return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2677
		return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3055
		return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
2678
	else if (IS_VALLEYVIEW(dev))
3056
	} else if (IS_VALLEYVIEW(dev))
2679
		return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3057
		return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2680
	else if (IS_GEN7(dev) && port == PORT_A)
3058
	else if (IS_GEN7(dev) && port == PORT_A)
2681
		return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3059
		return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
2682
	else if (HAS_PCH_CPT(dev) && port != PORT_A)
3060
	else if (HAS_PCH_CPT(dev) && port != PORT_A)
Line 2697... Line 3075...
2697
			return DP_TRAIN_PRE_EMPH_LEVEL_3;
3075
			return DP_TRAIN_PRE_EMPH_LEVEL_3;
2698
		case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3076
		case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
2699
			return DP_TRAIN_PRE_EMPH_LEVEL_2;
3077
			return DP_TRAIN_PRE_EMPH_LEVEL_2;
2700
		case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3078
		case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
2701
			return DP_TRAIN_PRE_EMPH_LEVEL_1;
3079
			return DP_TRAIN_PRE_EMPH_LEVEL_1;
-
 
3080
		case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
-
 
3081
			return DP_TRAIN_PRE_EMPH_LEVEL_0;
2702
		default:
3082
		default:
2703
			return DP_TRAIN_PRE_EMPH_LEVEL_0;
3083
			return DP_TRAIN_PRE_EMPH_LEVEL_0;
2704
		}
3084
		}
2705
	} else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
3085
	} else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
2706
		switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3086
		switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
Line 2749... Line 3129...
2749
			return DP_TRAIN_PRE_EMPH_LEVEL_0;
3129
			return DP_TRAIN_PRE_EMPH_LEVEL_0;
2750
	}
3130
		}
2751
	}
3131
	}
2752
}
3132
}
Line 2753... Line 3133...
2753
 
3133
 
2754
static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
3134
static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
2755
{
3135
{
2756
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
3136
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
2757
	struct drm_i915_private *dev_priv = dev->dev_private;
3137
	struct drm_i915_private *dev_priv = dev->dev_private;
2758
	struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
3138
	struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
Line 2835... Line 3215...
2835
		break;
3215
		break;
2836
	default:
3216
	default:
2837
		return 0;
3217
		return 0;
2838
	}
3218
	}
Line 2839... Line 3219...
2839
 
3219
 
2840
	mutex_lock(&dev_priv->dpio_lock);
3220
	mutex_lock(&dev_priv->sb_lock);
2841
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
3221
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
2842
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
3222
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
2843
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
3223
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
2844
			 uniqtranscale_reg_value);
3224
			 uniqtranscale_reg_value);
2845
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
3225
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
2846
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
3226
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
2847
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
3227
	vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
2848
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000);
3228
	vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000);
Line 2849... Line 3229...
2849
	mutex_unlock(&dev_priv->dpio_lock);
3229
	mutex_unlock(&dev_priv->sb_lock);
2850
 
3230
 
Line -... Line 3231...
-
 
3231
	return 0;
-
 
3232
}
-
 
3233
 
-
 
3234
static bool chv_need_uniq_trans_scale(uint8_t train_set)
-
 
3235
{
-
 
3236
	return (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) == DP_TRAIN_PRE_EMPH_LEVEL_0 &&
2851
	return 0;
3237
		(train_set & DP_TRAIN_VOLTAGE_SWING_MASK) == DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
2852
}
3238
}
2853
 
3239
 
2854
static uint32_t intel_chv_signal_levels(struct intel_dp *intel_dp)
3240
static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
2855
{
3241
{
2856
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
3242
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
Line 2931... Line 3317...
2931
		break;
3317
		break;
2932
	default:
3318
	default:
2933
		return 0;
3319
		return 0;
2934
	}
3320
	}
Line 2935... Line 3321...
2935
 
3321
 
Line 2936... Line 3322...
2936
	mutex_lock(&dev_priv->dpio_lock);
3322
	mutex_lock(&dev_priv->sb_lock);
2937
 
3323
 
2938
	/* Clear calc init */
3324
	/* Clear calc init */
2939
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
3325
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
2940
	val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
3326
	val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
2941
	val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
3327
	val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
Line -... Line 3328...
-
 
3328
	val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
2942
	val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
3329
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
2943
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
3330
 
2944
 
3331
	if (intel_crtc->config->lane_count > 2) {
2945
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
3332
		val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
2946
	val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
3333
		val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
-
 
3334
		val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
Line 2947... Line 3335...
2947
	val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
3335
		val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
2948
	val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
3336
		vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
2949
	vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
3337
	}
2950
 
3338
 
Line -... Line 3339...
-
 
3339
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
2951
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
3340
	val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
2952
	val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
3341
	val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
2953
	val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
3342
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
2954
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
3343
 
-
 
3344
	if (intel_crtc->config->lane_count > 2) {
Line 2955... Line 3345...
2955
 
3345
		val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
2956
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
3346
		val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
2957
	val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
3347
		val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
2958
	val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
3348
		vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
2959
	vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
3349
	}
2960
 
3350
 
2961
	/* Program swing deemph */
3351
	/* Program swing deemph */
Line 2962... Line 3352...
2962
	for (i = 0; i < 4; i++) {
3352
	for (i = 0; i < intel_crtc->config->lane_count; i++) {
2963
		val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
3353
		val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
2964
		val &= ~DPIO_SWING_DEEMPH9P5_MASK;
3354
		val &= ~DPIO_SWING_DEEMPH9P5_MASK;
-
 
3355
		val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
2965
		val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
3356
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
2966
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
3357
	}
2967
	}
-
 
2968
 
-
 
Line -... Line 3358...
-
 
3358
 
2969
	/* Program swing margin */
3359
	/* Program swing margin */
2970
	for (i = 0; i < 4; i++) {
3360
	for (i = 0; i < intel_crtc->config->lane_count; i++) {
2971
		val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
3361
		val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
-
 
3362
 
2972
		val &= ~DPIO_SWING_MARGIN000_MASK;
3363
		val &= ~DPIO_SWING_MARGIN000_MASK;
2973
		val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
3364
		val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
2974
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
-
 
Line 2975... Line -...
2975
	}
-
 
2976
 
-
 
2977
	/* Disable unique transition scale */
3365
 
2978
	for (i = 0; i < 4; i++) {
-
 
-
 
3366
		/*
Line 2979... Line 3367...
2979
		val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
3367
		 * Supposedly this value shouldn't matter when unique transition
2980
		val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
3368
		 * scale is disabled, but in fact it does matter. Let's just
2981
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
3369
		 * always program the same value and hope it's OK.
2982
	}
3370
		 */
2983
 
3371
		val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
2984
	if (((train_set & DP_TRAIN_PRE_EMPHASIS_MASK)
3372
		val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
2985
			== DP_TRAIN_PRE_EMPH_LEVEL_0) &&
3373
 
2986
		((train_set & DP_TRAIN_VOLTAGE_SWING_MASK)
3374
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
-
 
3375
	}
2987
			== DP_TRAIN_VOLTAGE_SWING_LEVEL_3)) {
3376
 
-
 
3377
	/*
-
 
3378
	 * The document said it needs to set bit 27 for ch0 and bit 26
2988
 
3379
	 * for ch1. Might be a typo in the doc.
2989
		/*
3380
	 * For now, for this unique transition scale selection, set bit
Line 2990... Line -...
2990
		 * The document said it needs to set bit 27 for ch0 and bit 26
-
 
2991
		 * for ch1. Might be a typo in the doc.
-
 
2992
		 * For now, for this unique transition scale selection, set bit
-
 
2993
		 * 27 for ch0 and ch1.
-
 
2994
		 */
-
 
2995
		for (i = 0; i < 4; i++) {
-
 
2996
			val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
-
 
2997
			val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
-
 
2998
			vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
3381
	 * 27 for ch0 and ch1.
2999
		}
3382
	 */
3000
 
3383
	for (i = 0; i < intel_crtc->config->lane_count; i++) {
3001
		for (i = 0; i < 4; i++) {
3384
		val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
Line -... Line 3385...
-
 
3385
		if (chv_need_uniq_trans_scale(train_set))
3002
			val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
3386
			val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
3003
			val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
3387
		else
3004
			val |= (0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT);
3388
			val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
-
 
3389
		vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
Line 3005... Line -...
3005
			vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
-
 
3006
		}
-
 
3007
	}
-
 
3008
 
-
 
3009
	/* Start swing calculation */
-
 
3010
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
3390
	}
Line 3011... Line 3391...
3011
	val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
3391
 
3012
	vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
3392
	/* Start swing calculation */
Line 3013... Line 3393...
3013
 
3393
	val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
Line 3056... Line 3436...
3056
	for (lane = 0; lane < 4; lane++)
3436
	for (lane = 0; lane < 4; lane++)
3057
		intel_dp->train_set[lane] = v | p;
3437
		intel_dp->train_set[lane] = v | p;
3058
}
3438
}
Line 3059... Line 3439...
3059
 
3439
 
3060
static uint32_t
3440
static uint32_t
3061
intel_gen4_signal_levels(uint8_t train_set)
3441
gen4_signal_levels(uint8_t train_set)
3062
{
3442
{
Line 3063... Line 3443...
3063
	uint32_t	signal_levels = 0;
3443
	uint32_t	signal_levels = 0;
3064
 
3444
 
Line 3095... Line 3475...
3095
	return signal_levels;
3475
	return signal_levels;
3096
}
3476
}
Line 3097... Line 3477...
3097
 
3477
 
3098
/* Gen6's DP voltage swing and pre-emphasis control */
3478
/* Gen6's DP voltage swing and pre-emphasis control */
3099
static uint32_t
3479
static uint32_t
3100
intel_gen6_edp_signal_levels(uint8_t train_set)
3480
gen6_edp_signal_levels(uint8_t train_set)
3101
{
3481
{
3102
	int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3482
	int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3103
					 DP_TRAIN_PRE_EMPHASIS_MASK);
3483
					 DP_TRAIN_PRE_EMPHASIS_MASK);
3104
	switch (signal_levels) {
3484
	switch (signal_levels) {
Line 3123... Line 3503...
3123
	}
3503
	}
3124
}
3504
}
Line 3125... Line 3505...
3125
 
3505
 
3126
/* Gen7's DP voltage swing and pre-emphasis control */
3506
/* Gen7's DP voltage swing and pre-emphasis control */
3127
static uint32_t
3507
static uint32_t
3128
intel_gen7_edp_signal_levels(uint8_t train_set)
3508
gen7_edp_signal_levels(uint8_t train_set)
3129
{
3509
{
3130
	int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3510
	int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3131
					 DP_TRAIN_PRE_EMPHASIS_MASK);
3511
					 DP_TRAIN_PRE_EMPHASIS_MASK);
3132
	switch (signal_levels) {
3512
	switch (signal_levels) {
Line 3152... Line 3532...
3152
			      "0x%x\n", signal_levels);
3532
			      "0x%x\n", signal_levels);
3153
		return EDP_LINK_TRAIN_500MV_0DB_IVB;
3533
		return EDP_LINK_TRAIN_500MV_0DB_IVB;
3154
	}
3534
	}
3155
}
3535
}
Line 3156... Line -...
3156
 
-
 
3157
/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
-
 
3158
static uint32_t
-
 
3159
intel_hsw_signal_levels(uint8_t train_set)
-
 
3160
{
-
 
3161
	int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
-
 
3162
					 DP_TRAIN_PRE_EMPHASIS_MASK);
-
 
3163
	switch (signal_levels) {
-
 
3164
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
-
 
3165
		return DDI_BUF_TRANS_SELECT(0);
-
 
3166
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
-
 
3167
		return DDI_BUF_TRANS_SELECT(1);
-
 
3168
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
-
 
3169
		return DDI_BUF_TRANS_SELECT(2);
-
 
3170
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3:
-
 
3171
		return DDI_BUF_TRANS_SELECT(3);
-
 
3172
 
-
 
3173
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
-
 
3174
		return DDI_BUF_TRANS_SELECT(4);
-
 
3175
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
-
 
3176
		return DDI_BUF_TRANS_SELECT(5);
-
 
3177
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
-
 
3178
		return DDI_BUF_TRANS_SELECT(6);
-
 
3179
 
-
 
3180
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
-
 
3181
		return DDI_BUF_TRANS_SELECT(7);
-
 
3182
	case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
-
 
3183
		return DDI_BUF_TRANS_SELECT(8);
-
 
3184
	default:
-
 
3185
		DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
-
 
3186
			      "0x%x\n", signal_levels);
-
 
3187
		return DDI_BUF_TRANS_SELECT(0);
-
 
3188
	}
-
 
3189
}
-
 
3190
 
3536
 
3191
/* Properly updates "DP" with the correct signal levels. */
3537
/* Properly updates "DP" with the correct signal levels. */
3192
static void
3538
static void
3193
intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
3539
intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
3194
{
3540
{
3195
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3541
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3196
	enum port port = intel_dig_port->port;
3542
	enum port port = intel_dig_port->port;
3197
	struct drm_device *dev = intel_dig_port->base.base.dev;
3543
	struct drm_device *dev = intel_dig_port->base.base.dev;
3198
	uint32_t signal_levels, mask;
3544
	uint32_t signal_levels, mask = 0;
Line 3199... Line 3545...
3199
	uint8_t train_set = intel_dp->train_set[0];
3545
	uint8_t train_set = intel_dp->train_set[0];
3200
 
3546
 
-
 
3547
	if (HAS_DDI(dev)) {
-
 
3548
		signal_levels = ddi_signal_levels(intel_dp);
-
 
3549
 
-
 
3550
		if (IS_BROXTON(dev))
3201
	if (IS_HASWELL(dev) || IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) {
3551
			signal_levels = 0;
3202
		signal_levels = intel_hsw_signal_levels(train_set);
3552
		else
3203
		mask = DDI_BUF_EMP_MASK;
3553
			mask = DDI_BUF_EMP_MASK;
3204
	} else if (IS_CHERRYVIEW(dev)) {
-
 
3205
		signal_levels = intel_chv_signal_levels(intel_dp);
3554
	} else if (IS_CHERRYVIEW(dev)) {
3206
		mask = 0;
3555
		signal_levels = chv_signal_levels(intel_dp);
3207
	} else if (IS_VALLEYVIEW(dev)) {
-
 
3208
		signal_levels = intel_vlv_signal_levels(intel_dp);
3556
	} else if (IS_VALLEYVIEW(dev)) {
3209
		mask = 0;
3557
		signal_levels = vlv_signal_levels(intel_dp);
3210
	} else if (IS_GEN7(dev) && port == PORT_A) {
3558
	} else if (IS_GEN7(dev) && port == PORT_A) {
3211
		signal_levels = intel_gen7_edp_signal_levels(train_set);
3559
		signal_levels = gen7_edp_signal_levels(train_set);
3212
		mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
3560
		mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
3213
	} else if (IS_GEN6(dev) && port == PORT_A) {
3561
	} else if (IS_GEN6(dev) && port == PORT_A) {
3214
		signal_levels = intel_gen6_edp_signal_levels(train_set);
3562
		signal_levels = gen6_edp_signal_levels(train_set);
3215
		mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3563
		mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3216
	} else {
3564
	} else {
3217
		signal_levels = intel_gen4_signal_levels(train_set);
3565
		signal_levels = gen4_signal_levels(train_set);
Line -... Line 3566...
-
 
3566
		mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3218
		mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3567
	}
Line -... Line 3568...
-
 
3568
 
-
 
3569
	if (mask)
-
 
3570
		DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
-
 
3571
 
-
 
3572
	DRM_DEBUG_KMS("Using vswing level %d\n",
-
 
3573
		train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3219
	}
3574
	DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3220
 
3575
		(train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
Line 3221... Line 3576...
3221
	DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3576
			DP_TRAIN_PRE_EMPHASIS_SHIFT);
3222
 
3577
 
3223
	*DP = (*DP & ~mask) | signal_levels;
3578
	*DP = (*DP & ~mask) | signal_levels;
3224
}
3579
}
3225
 
3580
 
3226
static bool
3581
static bool
3227
intel_dp_set_link_train(struct intel_dp *intel_dp,
3582
intel_dp_set_link_train(struct intel_dp *intel_dp,
3228
			uint32_t *DP,
3583
			uint32_t *DP,
3229
			uint8_t dp_train_pat)
3584
			uint8_t dp_train_pat)
3230
{
3585
{
Line 3231... Line 3586...
3231
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3586
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Line 3258... Line 3613...
3258
 
3613
 
3259
static bool
3614
static bool
3260
intel_dp_reset_link_train(struct intel_dp *intel_dp, uint32_t *DP,
3615
intel_dp_reset_link_train(struct intel_dp *intel_dp, uint32_t *DP,
3261
			uint8_t dp_train_pat)
3616
			uint8_t dp_train_pat)
-
 
3617
{
3262
{
3618
	if (!intel_dp->train_set_valid)
3263
	memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set));
3619
		memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set));
3264
	intel_dp_set_signal_levels(intel_dp, DP);
3620
	intel_dp_set_signal_levels(intel_dp, DP);
3265
	return intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
3621
	return intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
Line 3266... Line 3622...
3266
}
3622
}
3267
 
3623
 
3268
static bool
3624
static bool
3269
intel_dp_update_link_train(struct intel_dp *intel_dp, uint32_t *DP,
3625
intel_dp_update_link_train(struct intel_dp *intel_dp, uint32_t *DP,
3270
			   const uint8_t link_status[DP_LINK_STATUS_SIZE])
3626
			   const uint8_t link_status[DP_LINK_STATUS_SIZE])
3271
{
3627
{
3272
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3628
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3273
	struct drm_device *dev = intel_dig_port->base.base.dev;
3629
	struct drm_i915_private *dev_priv =
Line 3274... Line 3630...
3274
	struct drm_i915_private *dev_priv = dev->dev_private;
3630
		to_i915(intel_dig_port->base.base.dev);
3275
	int ret;
3631
	int ret;
Line 3316... Line 3672...
3316
		     1))
3672
		     1))
3317
		DRM_ERROR("Timed out waiting for DP idle patterns\n");
3673
		DRM_ERROR("Timed out waiting for DP idle patterns\n");
3318
}
3674
}
Line 3319... Line 3675...
3319
 
3675
 
3320
/* Enable corresponding port and start training pattern 1 */
3676
/* Enable corresponding port and start training pattern 1 */
3321
void
3677
static void
3322
intel_dp_start_link_train(struct intel_dp *intel_dp)
3678
intel_dp_link_training_clock_recovery(struct intel_dp *intel_dp)
3323
{
3679
{
3324
	struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
3680
	struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
3325
	struct drm_device *dev = encoder->dev;
3681
	struct drm_device *dev = encoder->dev;
3326
	int i;
3682
	int i;
3327
	uint8_t voltage;
3683
	uint8_t voltage;
3328
	int voltage_tries, loop_tries;
3684
	int voltage_tries, loop_tries;
3329
	uint32_t DP = intel_dp->DP;
3685
	uint32_t DP = intel_dp->DP;
-
 
3686
	uint8_t link_config[2];
Line 3330... Line 3687...
3330
	uint8_t link_config[2];
3687
	uint8_t link_bw, rate_select;
3331
 
3688
 
Line -... Line 3689...
-
 
3689
	if (HAS_DDI(dev))
-
 
3690
		intel_ddi_prepare_link_retrain(encoder);
-
 
3691
 
3332
	if (HAS_DDI(dev))
3692
	intel_dp_compute_rate(intel_dp, intel_dp->link_rate,
3333
		intel_ddi_prepare_link_retrain(encoder);
3693
			      &link_bw, &rate_select);
3334
 
3694
 
3335
	/* Write the link configuration data */
3695
	/* Write the link configuration data */
3336
	link_config[0] = intel_dp->link_bw;
3696
	link_config[0] = link_bw;
3337
	link_config[1] = intel_dp->lane_count;
3697
	link_config[1] = intel_dp->lane_count;
-
 
3698
	if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
-
 
3699
		link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
-
 
3700
	drm_dp_dpcd_write(&intel_dp->aux, DP_LINK_BW_SET, link_config, 2);
Line 3338... Line 3701...
3338
	if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
3701
	if (intel_dp->num_sink_rates)
3339
		link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
3702
		drm_dp_dpcd_write(&intel_dp->aux, DP_LINK_RATE_SET,
3340
	drm_dp_dpcd_write(&intel_dp->aux, DP_LINK_BW_SET, link_config, 2);
3703
				  &rate_select, 1);
Line 3368... Line 3731...
3368
		if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
3731
		if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
3369
			DRM_DEBUG_KMS("clock recovery OK\n");
3732
			DRM_DEBUG_KMS("clock recovery OK\n");
3370
			break;
3733
			break;
3371
		}
3734
		}
Line -... Line 3735...
-
 
3735
 
-
 
3736
		/*
-
 
3737
		 * if we used previously trained voltage and pre-emphasis values
-
 
3738
		 * and we don't get clock recovery, reset link training values
-
 
3739
		 */
-
 
3740
		if (intel_dp->train_set_valid) {
-
 
3741
			DRM_DEBUG_KMS("clock recovery not ok, reset");
-
 
3742
			/* clear the flag as we are not reusing train set */
-
 
3743
			intel_dp->train_set_valid = false;
-
 
3744
			if (!intel_dp_reset_link_train(intel_dp, &DP,
-
 
3745
						       DP_TRAINING_PATTERN_1 |
-
 
3746
						       DP_LINK_SCRAMBLING_DISABLE)) {
-
 
3747
				DRM_ERROR("failed to enable link training\n");
-
 
3748
				return;
-
 
3749
			}
-
 
3750
			continue;
-
 
3751
		}
3372
 
3752
 
3373
		/* Check to see if we've tried the max voltage */
3753
		/* Check to see if we've tried the max voltage */
3374
		for (i = 0; i < intel_dp->lane_count; i++)
3754
		for (i = 0; i < intel_dp->lane_count; i++)
3375
			if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
3755
			if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
3376
				break;
3756
				break;
Line 3406... Line 3786...
3406
	}
3786
	}
Line 3407... Line 3787...
3407
 
3787
 
3408
	intel_dp->DP = DP;
3788
	intel_dp->DP = DP;
Line 3409... Line 3789...
3409
}
3789
}
3410
 
3790
 
3411
void
3791
static void
-
 
3792
intel_dp_link_training_channel_equalization(struct intel_dp *intel_dp)
-
 
3793
{
3412
intel_dp_complete_link_train(struct intel_dp *intel_dp)
3794
	struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3413
{
3795
	struct drm_device *dev = dig_port->base.base.dev;
3414
	bool channel_eq = false;
3796
	bool channel_eq = false;
3415
	int tries, cr_tries;
3797
	int tries, cr_tries;
Line -... Line 3798...
-
 
3798
	uint32_t DP = intel_dp->DP;
3416
	uint32_t DP = intel_dp->DP;
3799
	uint32_t training_pattern = DP_TRAINING_PATTERN_2;
-
 
3800
 
-
 
3801
	/*
-
 
3802
	 * Training Pattern 3 for HBR2 or 1.2 devices that support it.
-
 
3803
	 *
-
 
3804
	 * Intel platforms that support HBR2 also support TPS3. TPS3 support is
-
 
3805
	 * also mandatory for downstream devices that support HBR2.
-
 
3806
	 *
-
 
3807
	 * Due to WaDisableHBR2 SKL < B0 is the only exception where TPS3 is
3417
	uint32_t training_pattern = DP_TRAINING_PATTERN_2;
3808
	 * supported but still not enabled.
3418
 
3809
	 */
-
 
3810
	if (intel_dp_source_supports_hbr2(dev) &&
-
 
3811
	    drm_dp_tps3_supported(intel_dp->dpcd))
Line 3419... Line 3812...
3419
	/* Training Pattern 3 for HBR2 ot 1.2 devices that support it*/
3812
		training_pattern = DP_TRAINING_PATTERN_3;
3420
	if (intel_dp->link_bw == DP_LINK_BW_5_4 || intel_dp->use_tps3)
3813
	else if (intel_dp->link_rate == 540000)
3421
		training_pattern = DP_TRAINING_PATTERN_3;
3814
		DRM_ERROR("5.4 Gbps link rate without HBR2/TPS3 support\n");
3422
 
3815
 
Line 3444... Line 3837...
3444
			DRM_ERROR("failed to get link status\n");
3837
			DRM_ERROR("failed to get link status\n");
3445
			break;
3838
			break;
3446
		}
3839
		}
Line 3447... Line 3840...
3447
 
3840
 
3448
		/* Make sure clock is still ok */
3841
		/* Make sure clock is still ok */
-
 
3842
		if (!drm_dp_clock_recovery_ok(link_status,
-
 
3843
					      intel_dp->lane_count)) {
3449
		if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
3844
			intel_dp->train_set_valid = false;
3450
			intel_dp_start_link_train(intel_dp);
3845
			intel_dp_link_training_clock_recovery(intel_dp);
3451
			intel_dp_set_link_train(intel_dp, &DP,
3846
			intel_dp_set_link_train(intel_dp, &DP,
3452
						training_pattern |
3847
						training_pattern |
3453
						DP_LINK_SCRAMBLING_DISABLE);
3848
						DP_LINK_SCRAMBLING_DISABLE);
3454
			cr_tries++;
3849
			cr_tries++;
3455
			continue;
3850
			continue;
Line 3456... Line 3851...
3456
		}
3851
		}
-
 
3852
 
3457
 
3853
		if (drm_dp_channel_eq_ok(link_status,
3458
		if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
3854
					 intel_dp->lane_count)) {
3459
			channel_eq = true;
3855
			channel_eq = true;
Line 3460... Line 3856...
3460
			break;
3856
			break;
3461
		}
3857
		}
-
 
3858
 
3462
 
3859
		/* Try 5 times, then try clock recovery if that fails */
3463
		/* Try 5 times, then try clock recovery if that fails */
3860
		if (tries > 5) {
3464
		if (tries > 5) {
3861
			intel_dp->train_set_valid = false;
3465
			intel_dp_start_link_train(intel_dp);
3862
			intel_dp_link_training_clock_recovery(intel_dp);
3466
			intel_dp_set_link_train(intel_dp, &DP,
3863
			intel_dp_set_link_train(intel_dp, &DP,
3467
						training_pattern |
3864
						training_pattern |
Line 3481... Line 3878...
3481
 
3878
 
Line 3482... Line 3879...
3482
	intel_dp_set_idle_link_train(intel_dp);
3879
	intel_dp_set_idle_link_train(intel_dp);
Line 3483... Line 3880...
3483
 
3880
 
-
 
3881
	intel_dp->DP = DP;
3484
	intel_dp->DP = DP;
3882
 
3485
 
3883
	if (channel_eq) {
3486
	if (channel_eq)
3884
		intel_dp->train_set_valid = true;
Line 3487... Line 3885...
3487
		DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
3885
		DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
3488
 
3886
	}
3489
}
3887
}
3490
 
3888
 
3491
void intel_dp_stop_link_train(struct intel_dp *intel_dp)
3889
void intel_dp_stop_link_train(struct intel_dp *intel_dp)
Line -... Line 3890...
-
 
3890
{
-
 
3891
	intel_dp_set_link_train(intel_dp, &intel_dp->DP,
-
 
3892
				DP_TRAINING_PATTERN_DISABLE);
-
 
3893
}
-
 
3894
 
-
 
3895
void
-
 
3896
intel_dp_start_link_train(struct intel_dp *intel_dp)
3492
{
3897
{
3493
	intel_dp_set_link_train(intel_dp, &intel_dp->DP,
3898
	intel_dp_link_training_clock_recovery(intel_dp);
3494
				DP_TRAINING_PATTERN_DISABLE);
3899
	intel_dp_link_training_channel_equalization(intel_dp);
3495
}
3900
}
-
 
3901
 
3496
 
3902
static void
3497
static void
3903
intel_dp_link_down(struct intel_dp *intel_dp)
3498
intel_dp_link_down(struct intel_dp *intel_dp)
3904
{
3499
{
-
 
3500
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
-
 
3501
	enum port port = intel_dig_port->port;
3905
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
Line 3502... Line 3906...
3502
	struct drm_device *dev = intel_dig_port->base.base.dev;
3906
	struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
3503
	struct drm_i915_private *dev_priv = dev->dev_private;
3907
	enum port port = intel_dig_port->port;
Line 3504... Line 3908...
3504
	struct intel_crtc *intel_crtc =
3908
	struct drm_device *dev = intel_dig_port->base.base.dev;
3505
		to_intel_crtc(intel_dig_port->base.base.crtc);
3909
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 3506... Line 3910...
3506
	uint32_t DP = intel_dp->DP;
3910
	uint32_t DP = intel_dp->DP;
Line -... Line 3911...
-
 
3911
 
3507
 
3912
	if (WARN_ON(HAS_DDI(dev)))
3508
	if (WARN_ON(HAS_DDI(dev)))
3913
		return;
3509
		return;
3914
 
3510
 
3915
	if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
3511
	if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
3916
		return;
3512
		return;
3917
 
3513
 
3918
	DRM_DEBUG_KMS("\n");
3514
	DRM_DEBUG_KMS("\n");
3919
 
3515
 
3920
	if ((IS_GEN7(dev) && port == PORT_A) ||
3516
	if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
3921
	    (HAS_PCH_CPT(dev) && port != PORT_A)) {
-
 
3922
		DP &= ~DP_LINK_TRAIN_MASK_CPT;
3517
		DP &= ~DP_LINK_TRAIN_MASK_CPT;
3923
		DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
Line 3518... Line 3924...
3518
		I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
3924
	} else {
3519
	} else {
3925
		if (IS_CHERRYVIEW(dev))
3520
		if (IS_CHERRYVIEW(dev))
3926
			DP &= ~DP_LINK_TRAIN_MASK_CHV;
Line -... Line 3927...
-
 
3927
		else
3521
			DP &= ~DP_LINK_TRAIN_MASK_CHV;
3928
			DP &= ~DP_LINK_TRAIN_MASK;
3522
		else
3929
		DP |= DP_LINK_TRAIN_PAT_IDLE;
3523
		DP &= ~DP_LINK_TRAIN_MASK;
3930
	}
3524
		I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
3931
	I915_WRITE(intel_dp->output_reg, DP);
3525
	}
3932
	POSTING_READ(intel_dp->output_reg);
3526
	POSTING_READ(intel_dp->output_reg);
3933
 
3527
 
3934
	DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3528
	if (HAS_PCH_IBX(dev) &&
-
 
3529
	    I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
3935
	I915_WRITE(intel_dp->output_reg, DP);
3530
		struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
3936
	POSTING_READ(intel_dp->output_reg);
-
 
3937
 
Line 3531... Line -...
3531
 
-
 
3532
		/* Hardware workaround: leaving our transcoder select
3938
	/*
3533
		 * set to transcoder B while it's off will prevent the
-
 
3534
		 * corresponding HDMI output on transcoder A.
3939
	 * HW workaround for IBX, we need to move the port
3535
		 *
-
 
3536
		 * Combine this with another hardware workaround:
-
 
3537
		 * transcoder select bit can only be cleared while the
-
 
3538
		 * port is enabled.
3940
	 * to transcoder A after disabling it to allow the
3539
		 */
-
 
3540
		DP &= ~DP_PIPEB_SELECT;
-
 
3541
		I915_WRITE(intel_dp->output_reg, DP);
-
 
3542
 
3941
	 * matching HDMI port to be enabled on transcoder A.
Line 3543... Line -...
3543
		/* Changes to enable or select take place the vblank
-
 
3544
		 * after being written.
-
 
3545
		 */
-
 
3546
		if (WARN_ON(crtc == NULL)) {
3942
	 */
3547
			/* We should never try to disable a port without a crtc
3943
	if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B && port != PORT_A) {
Line 3548... Line 3944...
3548
			 * attached. For paranoia keep the code around for a
3944
		/* always enable with pattern 1 (as per spec) */
3549
			 * bit. */
3945
		DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3550
			POSTING_READ(intel_dp->output_reg);
3946
		DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3551
			msleep(50);
3947
		I915_WRITE(intel_dp->output_reg, DP);
3552
		} else
3948
		POSTING_READ(intel_dp->output_reg);
3553
			intel_wait_for_vblank(dev, intel_crtc->pipe);
3949
 
-
 
3950
		DP &= ~DP_PORT_EN;
Line 3554... Line 3951...
3554
	}
3951
		I915_WRITE(intel_dp->output_reg, DP);
3555
 
3952
		POSTING_READ(intel_dp->output_reg);
3556
	DP &= ~DP_AUDIO_OUTPUT_ENABLE;
3953
	}
Line 3583... Line 3980...
3583
				       sizeof(intel_dp->psr_dpcd));
3980
					sizeof(intel_dp->psr_dpcd));
3584
		if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3981
		if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3585
			dev_priv->psr.sink_support = true;
3982
			dev_priv->psr.sink_support = true;
3586
		DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3983
			DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3587
		}
3984
		}
-
 
3985
 
-
 
3986
		if (INTEL_INFO(dev)->gen >= 9 &&
-
 
3987
			(intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
-
 
3988
			uint8_t frame_sync_cap;
-
 
3989
 
-
 
3990
			dev_priv->psr.sink_support = true;
-
 
3991
			intel_dp_dpcd_read_wake(&intel_dp->aux,
-
 
3992
					DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
-
 
3993
					&frame_sync_cap, 1);
-
 
3994
			dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
-
 
3995
			/* PSR2 needs frame sync as well */
-
 
3996
			dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
-
 
3997
			DRM_DEBUG_KMS("PSR2 %s on sink",
-
 
3998
				dev_priv->psr.psr2_support ? "supported" : "not supported");
-
 
3999
		}
3588
	}
4000
	}
Line 3589... Line 4001...
3589
 
4001
 
3590
	/* Training Pattern 3 support, both source and sink */
4002
	DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
-
 
4003
		      yesno(intel_dp_source_supports_hbr2(dev)),
-
 
4004
		      yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
-
 
4005
 
-
 
4006
	/* Intermediate frequency support */
3591
	if (intel_dp->dpcd[DP_DPCD_REV] >= 0x12 &&
4007
	if (is_edp(intel_dp) &&
3592
	    intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED &&
4008
	    (intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] &	DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
-
 
4009
	    (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_EDP_DPCD_REV, &rev, 1) == 1) &&
-
 
4010
	    (rev >= 0x03)) { /* eDp v1.4 or higher */
-
 
4011
		__le16 sink_rates[DP_MAX_SUPPORTED_RATES];
-
 
4012
		int i;
3593
	    (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8)) {
4013
 
-
 
4014
		intel_dp_dpcd_read_wake(&intel_dp->aux,
-
 
4015
				DP_SUPPORTED_LINK_RATES,
-
 
4016
				sink_rates,
-
 
4017
				sizeof(sink_rates));
-
 
4018
 
3594
		intel_dp->use_tps3 = true;
4019
		for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
-
 
4020
			int val = le16_to_cpu(sink_rates[i]);
-
 
4021
 
3595
		DRM_DEBUG_KMS("Displayport TPS3 supported\n");
4022
			if (val == 0)
-
 
4023
				break;
-
 
4024
 
-
 
4025
			/* Value read is in kHz while drm clock is saved in deca-kHz */
-
 
4026
			intel_dp->sink_rates[i] = (val * 200) / 10;
3596
	} else
4027
		}
-
 
4028
		intel_dp->num_sink_rates = i;
-
 
4029
	}
-
 
4030
 
Line 3597... Line 4031...
3597
		intel_dp->use_tps3 = false;
4031
	intel_dp_print_rates(intel_dp);
3598
 
4032
 
3599
	if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4033
	if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
Line 3651... Line 4085...
3651
 
4085
 
3652
	drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4086
	drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
3653
	return intel_dp->is_mst;
4087
	return intel_dp->is_mst;
Line 3654... Line 4088...
3654
}
4088
}
3655
 
4089
 
3656
int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
4090
static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
3657
{
-
 
3658
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
-
 
3659
	struct drm_device *dev = intel_dig_port->base.base.dev;
4091
{
3660
	struct intel_crtc *intel_crtc =
4092
	struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3661
		to_intel_crtc(intel_dig_port->base.base.crtc);
4093
	struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
-
 
4094
	u8 buf;
-
 
4095
	int ret = 0;
-
 
4096
 
-
 
4097
	if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
-
 
4098
		DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
-
 
4099
		ret = -EIO;
-
 
4100
		goto out;
-
 
4101
	}
-
 
4102
 
-
 
4103
	if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
-
 
4104
			       buf & ~DP_TEST_SINK_START) < 0) {
-
 
4105
		DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
-
 
4106
		ret = -EIO;
-
 
4107
		goto out;
-
 
4108
	}
-
 
4109
 
-
 
4110
	intel_dp->sink_crc.started = false;
-
 
4111
 out:
-
 
4112
	hsw_enable_ips(intel_crtc);
-
 
4113
	return ret;
-
 
4114
}
-
 
4115
 
-
 
4116
static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
-
 
4117
{
-
 
4118
	struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3662
	u8 buf;
4119
	struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
-
 
4120
	u8 buf;
-
 
4121
	int ret;
-
 
4122
 
-
 
4123
	if (intel_dp->sink_crc.started) {
-
 
4124
		ret = intel_dp_sink_crc_stop(intel_dp);
-
 
4125
		if (ret)
Line 3663... Line 4126...
3663
	int test_crc_count;
4126
			return ret;
3664
	int attempts = 6;
4127
	}
Line 3665... Line 4128...
3665
 
4128
 
3666
	if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
4129
	if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
Line -... Line 4130...
-
 
4130
		return -EIO;
-
 
4131
 
3667
		return -EIO;
4132
	if (!(buf & DP_TEST_CRC_SUPPORTED))
3668
 
4133
		return -ENOTTY;
Line -... Line 4134...
-
 
4134
 
-
 
4135
	intel_dp->sink_crc.last_count = buf & DP_TEST_COUNT_MASK;
3669
	if (!(buf & DP_TEST_CRC_SUPPORTED))
4136
 
3670
		return -ENOTTY;
4137
	if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
-
 
4138
		return -EIO;
3671
 
4139
 
-
 
4140
	hsw_disable_ips(intel_crtc);
Line 3672... Line 4141...
3672
	if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
4141
 
3673
		return -EIO;
4142
	if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
-
 
4143
			       buf | DP_TEST_SINK_START) < 0) {
-
 
4144
		hsw_enable_ips(intel_crtc);
-
 
4145
		return -EIO;
-
 
4146
	}
-
 
4147
 
3674
 
4148
	intel_dp->sink_crc.started = true;
-
 
4149
	return 0;
-
 
4150
}
-
 
4151
 
-
 
4152
int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
-
 
4153
{
-
 
4154
	struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
-
 
4155
	struct drm_device *dev = dig_port->base.base.dev;
-
 
4156
	struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
-
 
4157
	u8 buf;
Line 3675... Line 4158...
3675
	if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
4158
	int count, ret;
3676
				buf | DP_TEST_SINK_START) < 0)
-
 
3677
		return -EIO;
-
 
3678
 
-
 
3679
	if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
4159
	int attempts = 6;
3680
		return -EIO;
-
 
Line 3681... Line 4160...
3681
	test_crc_count = buf & DP_TEST_COUNT_MASK;
4160
	bool old_equal_new;
3682
 
4161
 
3683
	do {
4162
	ret = intel_dp_sink_crc_start(intel_dp);
-
 
4163
	if (ret)
3684
		if (drm_dp_dpcd_readb(&intel_dp->aux,
4164
		return ret;
-
 
4165
 
Line -... Line 4166...
-
 
4166
	do {
3685
				      DP_TEST_SINK_MISC, &buf) < 0)
4167
		intel_wait_for_vblank(dev, intel_crtc->pipe);
-
 
4168
 
-
 
4169
		if (drm_dp_dpcd_readb(&intel_dp->aux,
3686
			return -EIO;
4170
				      DP_TEST_SINK_MISC, &buf) < 0) {
-
 
4171
			ret = -EIO;
Line 3687... Line 4172...
3687
	intel_wait_for_vblank(dev, intel_crtc->pipe);
4172
			goto stop;
3688
	} while (--attempts && (buf & DP_TEST_COUNT_MASK) == test_crc_count);
4173
		}
3689
 
-
 
3690
	if (attempts == 0) {
-
 
3691
		DRM_DEBUG_KMS("Panel is unable to calculate CRC after 6 vblanks\n");
4174
		count = buf & DP_TEST_COUNT_MASK;
-
 
4175
 
Line -... Line 4176...
-
 
4176
		/*
-
 
4177
		 * Count might be reset during the loop. In this case
-
 
4178
		 * last known count needs to be reset as well.
-
 
4179
		 */
-
 
4180
		if (count == 0)
-
 
4181
			intel_dp->sink_crc.last_count = 0;
-
 
4182
 
-
 
4183
		if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
-
 
4184
			ret = -EIO;
-
 
4185
			goto stop;
-
 
4186
		}
-
 
4187
 
-
 
4188
		old_equal_new = (count == intel_dp->sink_crc.last_count &&
-
 
4189
				 !memcmp(intel_dp->sink_crc.last_crc, crc,
-
 
4190
					 6 * sizeof(u8)));
-
 
4191
 
-
 
4192
	} while (--attempts && (count == 0 || old_equal_new));
-
 
4193
 
-
 
4194
	intel_dp->sink_crc.last_count = buf & DP_TEST_COUNT_MASK;
-
 
4195
	memcpy(intel_dp->sink_crc.last_crc, crc, 6 * sizeof(u8));
-
 
4196
 
3692
		return -ETIMEDOUT;
4197
	if (attempts == 0) {
3693
	}
4198
		if (old_equal_new) {
Line 3694... Line 4199...
3694
 
4199
			DRM_DEBUG_KMS("Unreliable Sink CRC counter: Current returned CRC is identical to the previous one\n");
3695
	if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0)
4200
		} else {
3696
		return -EIO;
4201
			DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
Line 3724... Line 4229...
3724
		return false;
4229
		return false;
Line 3725... Line 4230...
3725
 
4230
 
3726
	return true;
4231
	return true;
Line -... Line 4232...
-
 
4232
}
-
 
4233
 
-
 
4234
static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
3727
}
4235
{
-
 
4236
	uint8_t test_result = DP_TEST_ACK;
-
 
4237
	return test_result;
-
 
4238
}
-
 
4239
 
-
 
4240
static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
-
 
4241
{
-
 
4242
	uint8_t test_result = DP_TEST_NAK;
-
 
4243
	return test_result;
3728
 
4244
}
3729
static void
4245
 
-
 
4246
static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
-
 
4247
{
-
 
4248
	uint8_t test_result = DP_TEST_NAK;
-
 
4249
	struct intel_connector *intel_connector = intel_dp->attached_connector;
-
 
4250
	struct drm_connector *connector = &intel_connector->base;
-
 
4251
 
-
 
4252
	if (intel_connector->detect_edid == NULL ||
-
 
4253
	    connector->edid_corrupt ||
-
 
4254
	    intel_dp->aux.i2c_defer_count > 6) {
-
 
4255
		/* Check EDID read for NACKs, DEFERs and corruption
-
 
4256
		 * (DP CTS 1.2 Core r1.1)
-
 
4257
		 *    4.2.2.4 : Failed EDID read, I2C_NAK
-
 
4258
		 *    4.2.2.5 : Failed EDID read, I2C_DEFER
-
 
4259
		 *    4.2.2.6 : EDID corruption detected
-
 
4260
		 * Use failsafe mode for all cases
-
 
4261
		 */
-
 
4262
		if (intel_dp->aux.i2c_nack_count > 0 ||
-
 
4263
			intel_dp->aux.i2c_defer_count > 0)
-
 
4264
			DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
-
 
4265
				      intel_dp->aux.i2c_nack_count,
-
 
4266
				      intel_dp->aux.i2c_defer_count);
-
 
4267
		intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
-
 
4268
	} else {
-
 
4269
		struct edid *block = intel_connector->detect_edid;
-
 
4270
 
-
 
4271
		/* We have to write the checksum
-
 
4272
		 * of the last block read
-
 
4273
		 */
-
 
4274
		block += intel_connector->detect_edid->extensions;
-
 
4275
 
-
 
4276
		if (!drm_dp_dpcd_write(&intel_dp->aux,
-
 
4277
					DP_TEST_EDID_CHECKSUM,
-
 
4278
					&block->checksum,
-
 
4279
					1))
-
 
4280
			DRM_DEBUG_KMS("Failed to write EDID checksum\n");
-
 
4281
 
-
 
4282
		test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
-
 
4283
		intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
-
 
4284
	}
-
 
4285
 
-
 
4286
	/* Set test active flag here so userspace doesn't interrupt things */
-
 
4287
	intel_dp->compliance_test_active = 1;
-
 
4288
 
-
 
4289
	return test_result;
-
 
4290
}
-
 
4291
 
-
 
4292
static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
-
 
4293
{
-
 
4294
	uint8_t test_result = DP_TEST_NAK;
-
 
4295
	return test_result;
-
 
4296
}
-
 
4297
 
-
 
4298
static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
3730
intel_dp_handle_test_request(struct intel_dp *intel_dp)
4299
{
-
 
4300
	uint8_t response = DP_TEST_NAK;
-
 
4301
	uint8_t rxdata = 0;
-
 
4302
	int status = 0;
-
 
4303
 
-
 
4304
	intel_dp->compliance_test_active = 0;
-
 
4305
	intel_dp->compliance_test_type = 0;
-
 
4306
	intel_dp->compliance_test_data = 0;
-
 
4307
 
-
 
4308
	intel_dp->aux.i2c_nack_count = 0;
3731
{
4309
	intel_dp->aux.i2c_defer_count = 0;
-
 
4310
 
-
 
4311
	status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
-
 
4312
	if (status <= 0) {
-
 
4313
		DRM_DEBUG_KMS("Could not read test request from sink\n");
-
 
4314
		goto update_status;
-
 
4315
	}
-
 
4316
 
-
 
4317
	switch (rxdata) {
-
 
4318
	case DP_TEST_LINK_TRAINING:
-
 
4319
		DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
-
 
4320
		intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
-
 
4321
		response = intel_dp_autotest_link_training(intel_dp);
-
 
4322
		break;
-
 
4323
	case DP_TEST_LINK_VIDEO_PATTERN:
-
 
4324
		DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
-
 
4325
		intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
-
 
4326
		response = intel_dp_autotest_video_pattern(intel_dp);
-
 
4327
		break;
-
 
4328
	case DP_TEST_LINK_EDID_READ:
-
 
4329
		DRM_DEBUG_KMS("EDID test requested\n");
-
 
4330
		intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
-
 
4331
		response = intel_dp_autotest_edid(intel_dp);
-
 
4332
		break;
-
 
4333
	case DP_TEST_LINK_PHY_TEST_PATTERN:
-
 
4334
		DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
-
 
4335
		intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
-
 
4336
		response = intel_dp_autotest_phy_pattern(intel_dp);
-
 
4337
		break;
-
 
4338
	default:
-
 
4339
		DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
-
 
4340
		break;
-
 
4341
	}
-
 
4342
 
-
 
4343
update_status:
-
 
4344
	status = drm_dp_dpcd_write(&intel_dp->aux,
-
 
4345
				   DP_TEST_RESPONSE,
-
 
4346
				   &response, 1);
3732
	/* NAK by default */
4347
	if (status <= 0)
Line 3733... Line 4348...
3733
	drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, DP_TEST_NAK);
4348
		DRM_DEBUG_KMS("Could not write test response to sink\n");
3734
}
4349
}
3735
 
4350
 
Line 3746... Line 4361...
3746
		bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4361
		bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3747
go_again:
4362
go_again:
3748
		if (bret == true) {
4363
		if (bret == true) {
Line 3749... Line 4364...
3749
 
4364
 
-
 
4365
			/* check link status - esi[10] = 0x200c */
3750
			/* check link status - esi[10] = 0x200c */
4366
			if (intel_dp->active_mst_links &&
3751
			if (intel_dp->active_mst_links && !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
4367
			    !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
3752
				DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4368
				DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
3753
				intel_dp_start_link_train(intel_dp);
-
 
3754
				intel_dp_complete_link_train(intel_dp);
4369
				intel_dp_start_link_train(intel_dp);
3755
				intel_dp_stop_link_train(intel_dp);
4370
				intel_dp_stop_link_train(intel_dp);
Line 3756... Line 4371...
3756
			}
4371
			}
3757
 
4372
 
Line 3758... Line 4373...
3758
			DRM_DEBUG_KMS("got esi %02x %02x %02x\n", esi[0], esi[1], esi[2]);
4373
			DRM_DEBUG_KMS("got esi %3ph\n", esi);
3759
			ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4374
			ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3760
 
4375
 
Line 3769... Line 4384...
3769
					}
4384
					}
3770
				}
4385
				}
Line 3771... Line 4386...
3771
 
4386
 
3772
				bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4387
				bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3773
				if (bret == true) {
4388
				if (bret == true) {
3774
					DRM_DEBUG_KMS("got esi2 %02x %02x %02x\n", esi[0], esi[1], esi[2]);
4389
					DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
3775
					goto go_again;
4390
					goto go_again;
3776
				}
4391
				}
3777
			} else
4392
			} else
Line 3796... Line 4411...
3796
 *  1. Read DPCD
4411
 *  1. Read DPCD
3797
 *  2. Configure link according to Receiver Capabilities
4412
 *  2. Configure link according to Receiver Capabilities
3798
 *  3. Use Link Training from 2.5.3.3 and 3.5.1.3
4413
 *  3. Use Link Training from 2.5.3.3 and 3.5.1.3
3799
 *  4. Check link status on receipt of hot-plug interrupt
4414
 *  4. Check link status on receipt of hot-plug interrupt
3800
 */
4415
 */
3801
void
4416
static void
3802
intel_dp_check_link_status(struct intel_dp *intel_dp)
4417
intel_dp_check_link_status(struct intel_dp *intel_dp)
3803
{
4418
{
3804
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
4419
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
3805
	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4420
	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
3806
	u8 sink_irq_vector;
4421
	u8 sink_irq_vector;
3807
	u8 link_status[DP_LINK_STATUS_SIZE];
4422
	u8 link_status[DP_LINK_STATUS_SIZE];
Line 3808... Line 4423...
3808
 
4423
 
Line 3809... Line -...
3809
	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
-
 
3810
 
-
 
3811
	if (!intel_encoder->connectors_active)
-
 
3812
		return;
4424
	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
3813
 
4425
 
Line 3814... Line 4426...
3814
	if (WARN_ON(!intel_encoder->base.crtc))
4426
	if (!intel_encoder->base.crtc)
3815
		return;
4427
		return;
Line 3834... Line 4446...
3834
		drm_dp_dpcd_writeb(&intel_dp->aux,
4446
		drm_dp_dpcd_writeb(&intel_dp->aux,
3835
					    DP_DEVICE_SERVICE_IRQ_VECTOR,
4447
				   DP_DEVICE_SERVICE_IRQ_VECTOR,
3836
					    sink_irq_vector);
4448
				   sink_irq_vector);
Line 3837... Line 4449...
3837
 
4449
 
3838
		if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4450
		if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
3839
			intel_dp_handle_test_request(intel_dp);
4451
			DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
3840
		if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4452
		if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
3841
			DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4453
			DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
Line 3842... Line 4454...
3842
	}
4454
	}
3843
 
4455
 
3844
	if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
4456
	if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
3845
		DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4457
		DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
3846
			      intel_encoder->base.name);
-
 
3847
		intel_dp_start_link_train(intel_dp);
4458
			      intel_encoder->base.name);
3848
		intel_dp_complete_link_train(intel_dp);
4459
		intel_dp_start_link_train(intel_dp);
3849
		intel_dp_stop_link_train(intel_dp);
4460
		intel_dp_stop_link_train(intel_dp);
Line 3850... Line 4461...
3850
	}
4461
	}
Line 3911... Line 4522...
3911
			status = connector_status_connected;
4522
		status = connector_status_connected;
Line 3912... Line 4523...
3912
 
4523
 
3913
		return status;
4524
	return status;
Line 3914... Line 4525...
3914
}
4525
}
3915
 
4526
 
3916
static enum drm_connector_status
4527
static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
3917
ironlake_dp_detect(struct intel_dp *intel_dp)
4528
				       struct intel_digital_port *port)
3918
{
-
 
3919
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
-
 
Line -... Line 4529...
-
 
4529
{
-
 
4530
	u32 bit;
-
 
4531
 
-
 
4532
	switch (port->port) {
-
 
4533
	case PORT_A:
-
 
4534
		return true;
-
 
4535
	case PORT_B:
-
 
4536
		bit = SDE_PORTB_HOTPLUG;
-
 
4537
		break;
-
 
4538
	case PORT_C:
-
 
4539
		bit = SDE_PORTC_HOTPLUG;
-
 
4540
		break;
-
 
4541
	case PORT_D:
3920
	struct drm_i915_private *dev_priv = dev->dev_private;
4542
		bit = SDE_PORTD_HOTPLUG;
3921
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4543
		break;
-
 
4544
	default:
Line 3922... Line 4545...
3922
 
4545
		MISSING_CASE(port->port);
3923
	if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
4546
		return false;
Line 3924... Line 4547...
3924
		return connector_status_disconnected;
4547
	}
3925
 
4548
 
3926
	return intel_dp_detect_dpcd(intel_dp);
4549
	return I915_READ(SDEISR) & bit;
3927
}
-
 
3928
 
4550
}
Line 3929... Line 4551...
3929
static int g4x_digital_port_connected(struct drm_device *dev,
4551
 
-
 
4552
static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
3930
				       struct intel_digital_port *intel_dig_port)
4553
				       struct intel_digital_port *port)
3931
{
4554
{
3932
	struct drm_i915_private *dev_priv = dev->dev_private;
4555
	u32 bit;
3933
	uint32_t bit;
4556
 
3934
 
4557
	switch (port->port) {
3935
	if (IS_VALLEYVIEW(dev)) {
4558
	case PORT_A:
3936
		switch (intel_dig_port->port) {
4559
		return true;
3937
		case PORT_B:
4560
	case PORT_B:
-
 
4561
		bit = SDE_PORTB_HOTPLUG_CPT;
-
 
4562
		break;
-
 
4563
	case PORT_C:
3938
			bit = PORTB_HOTPLUG_LIVE_STATUS_VLV;
4564
		bit = SDE_PORTC_HOTPLUG_CPT;
3939
			break;
4565
		break;
3940
		case PORT_C:
4566
	case PORT_D:
-
 
4567
		bit = SDE_PORTD_HOTPLUG_CPT;
3941
			bit = PORTC_HOTPLUG_LIVE_STATUS_VLV;
4568
		break;
3942
			break;
4569
	case PORT_E:
-
 
4570
		bit = SDE_PORTE_HOTPLUG_SPT;
-
 
4571
		break;
-
 
4572
	default:
-
 
4573
		MISSING_CASE(port->port);
-
 
4574
		return false;
-
 
4575
	}
-
 
4576
 
3943
		case PORT_D:
4577
	return I915_READ(SDEISR) & bit;
-
 
4578
}
3944
			bit = PORTD_HOTPLUG_LIVE_STATUS_VLV;
4579
 
3945
			break;
4580
static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
3946
		default:
4581
				       struct intel_digital_port *port)
3947
			return -EINVAL;
4582
{
3948
		}
4583
	u32 bit;
3949
	} else {
4584
 
3950
	switch (intel_dig_port->port) {
4585
	switch (port->port) {
3951
	case PORT_B:
4586
	case PORT_B:
3952
			bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4587
		bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
3953
		break;
4588
		break;
3954
	case PORT_C:
4589
	case PORT_C:
-
 
4590
		bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
3955
			bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4591
		break;
3956
		break;
4592
	case PORT_D:
-
 
4593
		bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
-
 
4594
		break;
3957
	case PORT_D:
4595
	default:
Line -... Line 4596...
-
 
4596
		MISSING_CASE(port->port);
-
 
4597
		return false;
-
 
4598
	}
-
 
4599
 
-
 
4600
	return I915_READ(PORT_HOTPLUG_STAT) & bit;
-
 
4601
}
-
 
4602
 
3958
			bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4603
static bool vlv_digital_port_connected(struct drm_i915_private *dev_priv,
-
 
4604
				       struct intel_digital_port *port)
-
 
4605
{
-
 
4606
	u32 bit;
-
 
4607
 
-
 
4608
	switch (port->port) {
-
 
4609
	case PORT_B:
3959
		break;
4610
		bit = PORTB_HOTPLUG_LIVE_STATUS_VLV;
-
 
4611
		break;
-
 
4612
	case PORT_C:
3960
	default:
4613
		bit = PORTC_HOTPLUG_LIVE_STATUS_VLV;
-
 
4614
		break;
-
 
4615
	case PORT_D:
-
 
4616
		bit = PORTD_HOTPLUG_LIVE_STATUS_VLV;
-
 
4617
		break;
-
 
4618
	default:
-
 
4619
		MISSING_CASE(port->port);
-
 
4620
		return false;
-
 
4621
	}
-
 
4622
 
-
 
4623
	return I915_READ(PORT_HOTPLUG_STAT) & bit;
-
 
4624
}
-
 
4625
 
-
 
4626
static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
-
 
4627
				       struct intel_digital_port *intel_dig_port)
-
 
4628
{
-
 
4629
	struct intel_encoder *intel_encoder = &intel_dig_port->base;
-
 
4630
	enum port port;
-
 
4631
    u32 bit = 0;
-
 
4632
 
-
 
4633
 
-
 
4634
	return I915_READ(GEN8_DE_PORT_ISR) & bit;
-
 
4635
}
-
 
4636
 
-
 
4637
/*
-
 
4638
 * intel_digital_port_connected - is the specified port connected?
-
 
4639
 * @dev_priv: i915 private structure
-
 
4640
 * @port: the port to test
-
 
4641
 *
-
 
4642
 * Return %true if @port is connected, %false otherwise.
-
 
4643
 */
-
 
4644
bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
-
 
4645
					 struct intel_digital_port *port)
-
 
4646
{
-
 
4647
	if (HAS_PCH_IBX(dev_priv))
-
 
4648
		return ibx_digital_port_connected(dev_priv, port);
-
 
4649
	if (HAS_PCH_SPLIT(dev_priv))
-
 
4650
		return cpt_digital_port_connected(dev_priv, port);
-
 
4651
	else if (IS_BROXTON(dev_priv))
-
 
4652
		return bxt_digital_port_connected(dev_priv, port);
-
 
4653
	else if (IS_VALLEYVIEW(dev_priv))
-
 
4654
		return vlv_digital_port_connected(dev_priv, port);
-
 
4655
	else
-
 
4656
		return g4x_digital_port_connected(dev_priv, port);
-
 
4657
}
-
 
4658
 
-
 
4659
static enum drm_connector_status
-
 
4660
ironlake_dp_detect(struct intel_dp *intel_dp)
-
 
4661
{
-
 
4662
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
3961
			return -EINVAL;
4663
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 3962... Line 4664...
3962
	}
4664
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3963
	}
4665
 
3964
 
4666
	if (!intel_digital_port_connected(dev_priv, intel_dig_port))
3965
	if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
4667
		return connector_status_disconnected;
3966
		return 0;
4668
 
3967
	return 1;
-
 
Line 3968... Line 4669...
3968
}
4669
	return intel_dp_detect_dpcd(intel_dp);
3969
 
4670
}
3970
static enum drm_connector_status
4671
 
Line 3982... Line 4683...
3982
		if (status == connector_status_unknown)
4683
		if (status == connector_status_unknown)
3983
			status = connector_status_connected;
4684
			status = connector_status_connected;
3984
		return status;
4685
		return status;
3985
	}
4686
	}
Line 3986... Line 4687...
3986
 
4687
 
3987
	ret = g4x_digital_port_connected(dev, intel_dig_port);
-
 
3988
	if (ret == -EINVAL)
-
 
3989
		return connector_status_unknown;
-
 
3990
	else if (ret == 0)
4688
	if (!intel_digital_port_connected(dev->dev_private, intel_dig_port))
Line 3991... Line 4689...
3991
		return connector_status_disconnected;
4689
		return connector_status_disconnected;
3992
 
4690
 
Line 4034... Line 4732...
4034
	intel_connector->detect_edid = NULL;
4732
	intel_connector->detect_edid = NULL;
Line 4035... Line 4733...
4035
 
4733
 
4036
	intel_dp->has_audio = false;
4734
	intel_dp->has_audio = false;
Line 4037... Line -...
4037
}
-
 
4038
 
-
 
4039
static enum intel_display_power_domain
-
 
4040
intel_dp_power_get(struct intel_dp *dp)
-
 
4041
{
-
 
4042
	struct intel_encoder *encoder = &dp_to_dig_port(dp)->base;
-
 
4043
	enum intel_display_power_domain power_domain;
-
 
4044
 
-
 
4045
	power_domain = intel_display_port_power_domain(encoder);
-
 
4046
	intel_display_power_get(to_i915(encoder->base.dev), power_domain);
-
 
4047
 
-
 
4048
	return power_domain;
-
 
4049
}
-
 
4050
 
-
 
4051
static void
-
 
4052
intel_dp_power_put(struct intel_dp *dp,
-
 
4053
		   enum intel_display_power_domain power_domain)
-
 
4054
{
-
 
4055
	struct intel_encoder *encoder = &dp_to_dig_port(dp)->base;
-
 
4056
	intel_display_power_put(to_i915(encoder->base.dev), power_domain);
-
 
4057
}
4735
}
4058
 
4736
 
4059
static enum drm_connector_status
4737
static enum drm_connector_status
4060
intel_dp_detect(struct drm_connector *connector, bool force)
4738
intel_dp_detect(struct drm_connector *connector, bool force)
4061
{
4739
{
4062
	struct intel_dp *intel_dp = intel_attached_dp(connector);
4740
	struct intel_dp *intel_dp = intel_attached_dp(connector);
4063
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4741
	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4064
	struct intel_encoder *intel_encoder = &intel_dig_port->base;
4742
	struct intel_encoder *intel_encoder = &intel_dig_port->base;
4065
	struct drm_device *dev = connector->dev;
4743
	struct drm_device *dev = connector->dev;
4066
	enum drm_connector_status status;
4744
	enum drm_connector_status status;
-
 
4745
	enum intel_display_power_domain power_domain;
Line 4067... Line 4746...
4067
	enum intel_display_power_domain power_domain;
4746
	bool ret;
4068
	bool ret;
4747
	u8 sink_irq_vector;
4069
 
4748
 
Line 4076... Line 4755...
4076
		if (intel_encoder->type != INTEL_OUTPUT_EDP)
4755
		if (intel_encoder->type != INTEL_OUTPUT_EDP)
4077
			intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4756
			intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4078
		return connector_status_disconnected;
4757
		return connector_status_disconnected;
4079
	}
4758
	}
Line 4080... Line 4759...
4080
 
4759
 
-
 
4760
	power_domain = intel_display_port_aux_power_domain(intel_encoder);
Line 4081... Line 4761...
4081
	power_domain = intel_dp_power_get(intel_dp);
4761
	intel_display_power_get(to_i915(dev), power_domain);
4082
 
4762
 
4083
	/* Can't disconnect eDP, but you can close the lid... */
4763
	/* Can't disconnect eDP, but you can close the lid... */
4084
	if (is_edp(intel_dp))
4764
	if (is_edp(intel_dp))
Line 4106... Line 4786...
4106
 
4786
 
4107
	if (intel_encoder->type != INTEL_OUTPUT_EDP)
4787
	if (intel_encoder->type != INTEL_OUTPUT_EDP)
4108
		intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
4788
		intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
Line -... Line 4789...
-
 
4789
	status = connector_status_connected;
-
 
4790
 
-
 
4791
	/* Try to read the source of the interrupt */
-
 
4792
	if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
-
 
4793
	    intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
-
 
4794
		/* Clear interrupt source */
-
 
4795
		drm_dp_dpcd_writeb(&intel_dp->aux,
-
 
4796
				   DP_DEVICE_SERVICE_IRQ_VECTOR,
-
 
4797
				   sink_irq_vector);
-
 
4798
 
-
 
4799
		if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
-
 
4800
			intel_dp_handle_test_request(intel_dp);
-
 
4801
		if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
-
 
4802
			DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4109
	status = connector_status_connected;
4803
	}
4110
 
4804
 
4111
out:
4805
out:
4112
	intel_dp_power_put(intel_dp, power_domain);
4806
	intel_display_power_put(to_i915(dev), power_domain);
Line 4113... Line 4807...
4113
	return status;
4807
	return status;
4114
}
4808
}
4115
 
4809
 
4116
static void
4810
static void
4117
intel_dp_force(struct drm_connector *connector)
4811
intel_dp_force(struct drm_connector *connector)
-
 
4812
{
4118
{
4813
	struct intel_dp *intel_dp = intel_attached_dp(connector);
Line 4119... Line 4814...
4119
	struct intel_dp *intel_dp = intel_attached_dp(connector);
4814
	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4120
	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4815
	struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
4121
	enum intel_display_power_domain power_domain;
4816
	enum intel_display_power_domain power_domain;
Line 4122... Line 4817...
4122
 
4817
 
4123
	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4818
	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
Line 4124... Line 4819...
4124
		      connector->base.id, connector->name);
4819
		      connector->base.id, connector->name);
-
 
4820
	intel_dp_unset_edid(intel_dp);
Line 4125... Line 4821...
4125
	intel_dp_unset_edid(intel_dp);
4821
 
Line 4126... Line 4822...
4126
 
4822
	if (connector->status != connector_status_connected)
Line 4127... Line 4823...
4127
	if (connector->status != connector_status_connected)
4823
		return;
4128
		return;
4824
 
4129
 
4825
	power_domain = intel_display_port_aux_power_domain(intel_encoder);
Line 4214... Line 4910...
4214
		goto done;
4910
		goto done;
4215
	}
4911
	}
Line 4216... Line 4912...
4216
 
4912
 
4217
	if (property == dev_priv->broadcast_rgb_property) {
4913
	if (property == dev_priv->broadcast_rgb_property) {
4218
		bool old_auto = intel_dp->color_range_auto;
4914
		bool old_auto = intel_dp->color_range_auto;
Line 4219... Line 4915...
4219
		uint32_t old_range = intel_dp->color_range;
4915
		bool old_range = intel_dp->limited_color_range;
4220
 
4916
 
4221
		switch (val) {
4917
		switch (val) {
4222
		case INTEL_BROADCAST_RGB_AUTO:
4918
		case INTEL_BROADCAST_RGB_AUTO:
4223
			intel_dp->color_range_auto = true;
4919
			intel_dp->color_range_auto = true;
4224
			break;
4920
			break;
4225
		case INTEL_BROADCAST_RGB_FULL:
4921
		case INTEL_BROADCAST_RGB_FULL:
4226
			intel_dp->color_range_auto = false;
4922
			intel_dp->color_range_auto = false;
4227
			intel_dp->color_range = 0;
4923
			intel_dp->limited_color_range = false;
4228
			break;
4924
			break;
4229
		case INTEL_BROADCAST_RGB_LIMITED:
4925
		case INTEL_BROADCAST_RGB_LIMITED:
4230
			intel_dp->color_range_auto = false;
4926
			intel_dp->color_range_auto = false;
4231
			intel_dp->color_range = DP_COLOR_RANGE_16_235;
4927
			intel_dp->limited_color_range = true;
4232
			break;
4928
			break;
4233
		default:
4929
		default:
Line 4234... Line 4930...
4234
			return -EINVAL;
4930
			return -EINVAL;
4235
		}
4931
		}
4236
 
4932
 
Line 4237... Line 4933...
4237
		if (old_auto == intel_dp->color_range_auto &&
4933
		if (old_auto == intel_dp->color_range_auto &&
4238
		    old_range == intel_dp->color_range)
4934
		    old_range == intel_dp->limited_color_range)
Line 4290... Line 4986...
4290
	struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4986
	struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4291
	struct intel_dp *intel_dp = &intel_dig_port->dp;
4987
	struct intel_dp *intel_dp = &intel_dig_port->dp;
Line 4292... Line 4988...
4292
 
4988
 
4293
	drm_dp_aux_unregister(&intel_dp->aux);
4989
	drm_dp_aux_unregister(&intel_dp->aux);
4294
	intel_dp_mst_encoder_cleanup(intel_dig_port);
-
 
4295
	drm_encoder_cleanup(encoder);
4990
	intel_dp_mst_encoder_cleanup(intel_dig_port);
4296
	if (is_edp(intel_dp)) {
4991
	if (is_edp(intel_dp)) {
4297
		cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4992
		cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4298
		/*
4993
		/*
4299
		 * vdd might still be enabled do to the delayed vdd off.
4994
		 * vdd might still be enabled do to the delayed vdd off.
Line 4302... Line 4997...
4302
		pps_lock(intel_dp);
4997
		pps_lock(intel_dp);
4303
		edp_panel_vdd_off_sync(intel_dp);
4998
		edp_panel_vdd_off_sync(intel_dp);
4304
		pps_unlock(intel_dp);
4999
		pps_unlock(intel_dp);
Line 4305... Line 5000...
4305
 
5000
 
-
 
5001
	}
4306
	}
5002
	drm_encoder_cleanup(encoder);
4307
	kfree(intel_dig_port);
5003
	kfree(intel_dig_port);
Line 4308... Line 5004...
4308
}
5004
}
4309
 
5005
 
Line 4341... Line 5037...
4341
	 * already enabled when we boot or resume, grab this reference and
5037
	 * already enabled when we boot or resume, grab this reference and
4342
	 * schedule a vdd off, so we don't hold on to the reference
5038
	 * schedule a vdd off, so we don't hold on to the reference
4343
	 * indefinitely.
5039
	 * indefinitely.
4344
	 */
5040
	 */
4345
	DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
5041
	DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
4346
	power_domain = intel_display_port_power_domain(&intel_dig_port->base);
5042
	power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
4347
	intel_display_power_get(dev_priv, power_domain);
5043
	intel_display_power_get(dev_priv, power_domain);
Line 4348... Line 5044...
4348
 
5044
 
4349
	edp_panel_vdd_schedule_off(intel_dp);
5045
	edp_panel_vdd_schedule_off(intel_dp);
Line 4371... Line 5067...
4371
 
5067
 
4372
	pps_unlock(intel_dp);
5068
	pps_unlock(intel_dp);
Line 4373... Line 5069...
4373
}
5069
}
4374
 
5070
 
4375
static const struct drm_connector_funcs intel_dp_connector_funcs = {
5071
static const struct drm_connector_funcs intel_dp_connector_funcs = {
4376
	.dpms = intel_connector_dpms,
5072
	.dpms = drm_atomic_helper_connector_dpms,
4377
	.detect = intel_dp_detect,
5073
	.detect = intel_dp_detect,
4378
	.force = intel_dp_force,
5074
	.force = intel_dp_force,
-
 
5075
	.fill_modes = drm_helper_probe_single_connector_modes,
4379
	.fill_modes = drm_helper_probe_single_connector_modes,
5076
	.set_property = intel_dp_set_property,
-
 
5077
	.atomic_get_property = intel_connector_atomic_get_property,
-
 
5078
	.destroy = intel_dp_connector_destroy,
4380
	.set_property = intel_dp_set_property,
5079
	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Line 4381... Line 5080...
4381
	.destroy = intel_dp_connector_destroy,
5080
	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
4382
};
5081
};
4383
 
5082
 
Line 4390... Line 5089...
4390
static const struct drm_encoder_funcs intel_dp_enc_funcs = {
5089
static const struct drm_encoder_funcs intel_dp_enc_funcs = {
4391
	.reset = intel_dp_encoder_reset,
5090
	.reset = intel_dp_encoder_reset,
4392
	.destroy = intel_dp_encoder_destroy,
5091
	.destroy = intel_dp_encoder_destroy,
4393
};
5092
};
Line 4394... Line -...
4394
 
-
 
4395
void
-
 
4396
intel_dp_hot_plug(struct intel_encoder *intel_encoder)
-
 
4397
{
5093
 
4398
	return;
-
 
4399
}
-
 
4400
 
-
 
4401
bool
5094
enum irqreturn
4402
intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5095
intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
4403
{
5096
{
4404
	struct intel_dp *intel_dp = &intel_dig_port->dp;
5097
	struct intel_dp *intel_dp = &intel_dig_port->dp;
4405
	struct intel_encoder *intel_encoder = &intel_dig_port->base;
5098
	struct intel_encoder *intel_encoder = &intel_dig_port->base;
4406
	struct drm_device *dev = intel_dig_port->base.base.dev;
5099
	struct drm_device *dev = intel_dig_port->base.base.dev;
4407
	struct drm_i915_private *dev_priv = dev->dev_private;
5100
	struct drm_i915_private *dev_priv = dev->dev_private;
4408
	enum intel_display_power_domain power_domain;
5101
	enum intel_display_power_domain power_domain;
Line 4409... Line 5102...
4409
	bool ret = true;
5102
	enum irqreturn ret = IRQ_NONE;
-
 
5103
 
4410
 
5104
	if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
Line 4411... Line 5105...
4411
	if (intel_dig_port->base.type != INTEL_OUTPUT_EDP)
5105
	    intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
4412
		intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT;
5106
		intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT;
4413
 
5107
 
Line 4418... Line 5112...
4418
		 * would end up in an endless cycle of
5112
		 * would end up in an endless cycle of
4419
		 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5113
		 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
4420
		 */
5114
		 */
4421
		DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5115
		DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
4422
			      port_name(intel_dig_port->port));
5116
			      port_name(intel_dig_port->port));
4423
		return false;
5117
		return IRQ_HANDLED;
4424
	}
5118
	}
Line 4425... Line 5119...
4425
 
5119
 
4426
	DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5120
	DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
4427
		      port_name(intel_dig_port->port),
5121
		      port_name(intel_dig_port->port),
Line 4428... Line 5122...
4428
		      long_hpd ? "long" : "short");
5122
		      long_hpd ? "long" : "short");
4429
 
5123
 
Line 4430... Line 5124...
4430
	power_domain = intel_display_port_power_domain(intel_encoder);
5124
	power_domain = intel_display_port_aux_power_domain(intel_encoder);
-
 
5125
	intel_display_power_get(dev_priv, power_domain);
-
 
5126
 
Line 4431... Line -...
4431
	intel_display_power_get(dev_priv, power_domain);
-
 
4432
 
5127
	if (long_hpd) {
4433
	if (long_hpd) {
-
 
4434
 
-
 
4435
		if (HAS_PCH_SPLIT(dev)) {
-
 
4436
		if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
5128
		/* indicate that we need to restart link training */
4437
			goto mst_fail;
-
 
Line 4438... Line 5129...
4438
		} else {
5129
		intel_dp->train_set_valid = false;
4439
			if (g4x_digital_port_connected(dev, intel_dig_port) != 1)
5130
 
4440
				goto mst_fail;
5131
		if (!intel_digital_port_connected(dev_priv, intel_dig_port))
Line 4441... Line 5132...
4441
		}
5132
			goto mst_fail;
Line 4442... Line 5133...
4442
 
5133
 
-
 
5134
		if (!intel_dp_get_dpcd(intel_dp)) {
-
 
5135
			goto mst_fail;
-
 
5136
		}
4443
		if (!intel_dp_get_dpcd(intel_dp)) {
5137
 
4444
			goto mst_fail;
5138
		intel_dp_probe_oui(intel_dp);
4445
		}
5139
 
4446
 
5140
		if (!intel_dp_probe_mst(intel_dp)) {
4447
		intel_dp_probe_oui(intel_dp);
5141
			drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4448
 
5142
			intel_dp_check_link_status(intel_dp);
4449
		if (!intel_dp_probe_mst(intel_dp))
5143
			drm_modeset_unlock(&dev->mode_config.connection_mutex);
Line 4450... Line 5144...
4450
			goto mst_fail;
5144
			goto mst_fail;
4451
 
-
 
4452
	} else {
-
 
4453
		if (intel_dp->is_mst) {
-
 
4454
			if (intel_dp_check_mst_status(intel_dp) == -EINVAL)
-
 
4455
				goto mst_fail;
5145
		}
4456
		}
5146
	} else {
4457
 
5147
		if (intel_dp->is_mst) {
4458
		if (!intel_dp->is_mst) {
5148
			if (intel_dp_check_mst_status(intel_dp) == -EINVAL)
4459
			/*
5149
				goto mst_fail;
-
 
5150
		}
4460
			 * we'll check the link status via the normal hot plug path later -
5151
 
-
 
5152
		if (!intel_dp->is_mst) {
4461
			 * but for short hpds we should check it now
5153
			drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
4462
			 */
5154
			intel_dp_check_link_status(intel_dp);
4463
			drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
5155
			drm_modeset_unlock(&dev->mode_config.connection_mutex);
4464
			intel_dp_check_link_status(intel_dp);
5156
		}
4465
			drm_modeset_unlock(&dev->mode_config.connection_mutex);
5157
	}
Line 4497... Line 5189...
4497
	}
5189
	}
Line 4498... Line 5190...
4498
 
5190
 
4499
	return -1;
5191
	return -1;
Line 4500... Line 5192...
4500
}
5192
}
4501
 
5193
 
4502
/* check the VBT to see whether the eDP is on DP-D port */
5194
/* check the VBT to see whether the eDP is on another port */
4503
bool intel_dp_is_edp(struct drm_device *dev, enum port port)
5195
bool intel_dp_is_edp(struct drm_device *dev, enum port port)
4504
{
5196
{
4505
	struct drm_i915_private *dev_priv = dev->dev_private;
5197
	struct drm_i915_private *dev_priv = dev->dev_private;
4506
	union child_device_config *p_child;
5198
	union child_device_config *p_child;
4507
	int i;
5199
	int i;
4508
	static const short port_mapping[] = {
5200
	static const short port_mapping[] = {
4509
		[PORT_B] = PORT_IDPB,
5201
		[PORT_B] = DVO_PORT_DPB,
-
 
5202
		[PORT_C] = DVO_PORT_DPC,
4510
		[PORT_C] = PORT_IDPC,
5203
		[PORT_D] = DVO_PORT_DPD,
Line -... Line 5204...
-
 
5204
		[PORT_E] = DVO_PORT_DPE,
-
 
5205
	};
-
 
5206
 
-
 
5207
	/*
-
 
5208
	 * eDP not supported on g4x. so bail out early just
-
 
5209
	 * for a bit extra safety in case the VBT is bonkers.
-
 
5210
	 */
4511
		[PORT_D] = PORT_IDPD,
5211
	if (INTEL_INFO(dev)->gen < 5)
4512
	};
5212
		return false;
Line 4513... Line 5213...
4513
 
5213
 
4514
	if (port == PORT_A)
5214
	if (port == PORT_A)
Line 4559... Line 5259...
4559
				    struct intel_dp *intel_dp)
5259
				    struct intel_dp *intel_dp)
4560
{
5260
{
4561
	struct drm_i915_private *dev_priv = dev->dev_private;
5261
	struct drm_i915_private *dev_priv = dev->dev_private;
4562
	struct edp_power_seq cur, vbt, spec,
5262
	struct edp_power_seq cur, vbt, spec,
4563
		*final = &intel_dp->pps_delays;
5263
		*final = &intel_dp->pps_delays;
4564
	u32 pp_on, pp_off, pp_div, pp;
5264
	u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
4565
	int pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
5265
	int pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg = 0;
Line 4566... Line 5266...
4566
 
5266
 
Line 4567... Line 5267...
4567
	lockdep_assert_held(&dev_priv->pps_mutex);
5267
	lockdep_assert_held(&dev_priv->pps_mutex);
4568
 
5268
 
4569
	/* already initialized? */
5269
	/* already initialized? */
Line -... Line 5270...
-
 
5270
	if (final->t11_t12 != 0)
-
 
5271
		return;
-
 
5272
 
-
 
5273
	if (IS_BROXTON(dev)) {
-
 
5274
		/*
-
 
5275
		 * TODO: BXT has 2 sets of PPS registers.
-
 
5276
		 * Correct Register for Broxton need to be identified
-
 
5277
		 * using VBT. hardcoding for now
-
 
5278
		 */
4570
	if (final->t11_t12 != 0)
5279
		pp_ctrl_reg = BXT_PP_CONTROL(0);
4571
		return;
5280
		pp_on_reg = BXT_PP_ON_DELAYS(0);
4572
 
5281
		pp_off_reg = BXT_PP_OFF_DELAYS(0);
4573
	if (HAS_PCH_SPLIT(dev)) {
5282
	} else if (HAS_PCH_SPLIT(dev)) {
4574
		pp_ctrl_reg = PCH_PP_CONTROL;
5283
		pp_ctrl_reg = PCH_PP_CONTROL;
4575
		pp_on_reg = PCH_PP_ON_DELAYS;
5284
		pp_on_reg = PCH_PP_ON_DELAYS;
Line 4584... Line 5293...
4584
		pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
5293
		pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
4585
	}
5294
	}
Line 4586... Line 5295...
4586
 
5295
 
4587
	/* Workaround: Need to write PP_CONTROL with the unlock key as
5296
	/* Workaround: Need to write PP_CONTROL with the unlock key as
4588
	 * the very first thing. */
5297
	 * the very first thing. */
4589
	pp = ironlake_get_pp_control(intel_dp);
-
 
Line 4590... Line 5298...
4590
	I915_WRITE(pp_ctrl_reg, pp);
5298
	pp_ctl = ironlake_get_pp_control(intel_dp);
4591
 
5299
 
-
 
5300
	pp_on = I915_READ(pp_on_reg);
-
 
5301
	pp_off = I915_READ(pp_off_reg);
4592
	pp_on = I915_READ(pp_on_reg);
5302
	if (!IS_BROXTON(dev)) {
-
 
5303
		I915_WRITE(pp_ctrl_reg, pp_ctl);
Line 4593... Line 5304...
4593
	pp_off = I915_READ(pp_off_reg);
5304
		pp_div = I915_READ(pp_div_reg);
4594
	pp_div = I915_READ(pp_div_reg);
5305
	}
4595
 
5306
 
Line 4604... Line 5315...
4604
		PANEL_LIGHT_OFF_DELAY_SHIFT;
5315
		PANEL_LIGHT_OFF_DELAY_SHIFT;
Line 4605... Line 5316...
4605
 
5316
 
4606
	cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5317
	cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
Line -... Line 5318...
-
 
5318
		PANEL_POWER_DOWN_DELAY_SHIFT;
-
 
5319
 
-
 
5320
	if (IS_BROXTON(dev)) {
-
 
5321
		u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
-
 
5322
			BXT_POWER_CYCLE_DELAY_SHIFT;
-
 
5323
		if (tmp > 0)
-
 
5324
			cur.t11_t12 = (tmp - 1) * 1000;
-
 
5325
		else
4607
		PANEL_POWER_DOWN_DELAY_SHIFT;
5326
			cur.t11_t12 = 0;
4608
 
5327
	} else {
-
 
5328
		cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
Line 4609... Line 5329...
4609
	cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
5329
		       PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
4610
		       PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
5330
	}
Line 4611... Line 5331...
4611
 
5331
 
Line 4662... Line 5382...
4662
					      struct intel_dp *intel_dp)
5382
					      struct intel_dp *intel_dp)
4663
{
5383
{
4664
	struct drm_i915_private *dev_priv = dev->dev_private;
5384
	struct drm_i915_private *dev_priv = dev->dev_private;
4665
	u32 pp_on, pp_off, pp_div, port_sel = 0;
5385
	u32 pp_on, pp_off, pp_div, port_sel = 0;
4666
	int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
5386
	int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
4667
	int pp_on_reg, pp_off_reg, pp_div_reg;
5387
	int pp_on_reg, pp_off_reg, pp_div_reg = 0, pp_ctrl_reg;
4668
	enum port port = dp_to_dig_port(intel_dp)->port;
5388
	enum port port = dp_to_dig_port(intel_dp)->port;
4669
	const struct edp_power_seq *seq = &intel_dp->pps_delays;
5389
	const struct edp_power_seq *seq = &intel_dp->pps_delays;
Line 4670... Line 5390...
4670
 
5390
 
Line -... Line 5391...
-
 
5391
	lockdep_assert_held(&dev_priv->pps_mutex);
-
 
5392
 
-
 
5393
	if (IS_BROXTON(dev)) {
-
 
5394
		/*
-
 
5395
		 * TODO: BXT has 2 sets of PPS registers.
-
 
5396
		 * Correct Register for Broxton need to be identified
-
 
5397
		 * using VBT. hardcoding for now
-
 
5398
		 */
-
 
5399
		pp_ctrl_reg = BXT_PP_CONTROL(0);
-
 
5400
		pp_on_reg = BXT_PP_ON_DELAYS(0);
4671
	lockdep_assert_held(&dev_priv->pps_mutex);
5401
		pp_off_reg = BXT_PP_OFF_DELAYS(0);
4672
 
5402
 
4673
	if (HAS_PCH_SPLIT(dev)) {
5403
	} else if (HAS_PCH_SPLIT(dev)) {
4674
		pp_on_reg = PCH_PP_ON_DELAYS;
5404
		pp_on_reg = PCH_PP_ON_DELAYS;
4675
		pp_off_reg = PCH_PP_OFF_DELAYS;
5405
		pp_off_reg = PCH_PP_OFF_DELAYS;
4676
		pp_div_reg = PCH_PP_DIVISOR;
5406
		pp_div_reg = PCH_PP_DIVISOR;
Line 4694... Line 5424...
4694
		(1 << PANEL_LIGHT_ON_DELAY_SHIFT);
5424
		(1 << PANEL_LIGHT_ON_DELAY_SHIFT);
4695
	pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
5425
	pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
4696
		 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
5426
		 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
4697
	/* Compute the divisor for the pp clock, simply match the Bspec
5427
	/* Compute the divisor for the pp clock, simply match the Bspec
4698
	 * formula. */
5428
	 * formula. */
-
 
5429
	if (IS_BROXTON(dev)) {
-
 
5430
		pp_div = I915_READ(pp_ctrl_reg);
-
 
5431
		pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
-
 
5432
		pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
-
 
5433
				<< BXT_POWER_CYCLE_DELAY_SHIFT);
-
 
5434
	} else {
4699
	pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5435
		pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
4700
	pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5436
		pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
4701
			<< PANEL_POWER_CYCLE_DELAY_SHIFT);
5437
				<< PANEL_POWER_CYCLE_DELAY_SHIFT);
-
 
5438
	}
Line 4702... Line 5439...
4702
 
5439
 
4703
	/* Haswell doesn't have any port selection bits for the panel
5440
	/* Haswell doesn't have any port selection bits for the panel
4704
	 * power sequencer any more. */
5441
	 * power sequencer any more. */
4705
	if (IS_VALLEYVIEW(dev)) {
5442
	if (IS_VALLEYVIEW(dev)) {
Line 4713... Line 5450...
4713
 
5450
 
Line 4714... Line 5451...
4714
	pp_on |= port_sel;
5451
	pp_on |= port_sel;
4715
 
5452
 
-
 
5453
	I915_WRITE(pp_on_reg, pp_on);
-
 
5454
	I915_WRITE(pp_off_reg, pp_off);
-
 
5455
	if (IS_BROXTON(dev))
4716
	I915_WRITE(pp_on_reg, pp_on);
5456
		I915_WRITE(pp_ctrl_reg, pp_div);
Line 4717... Line 5457...
4717
	I915_WRITE(pp_off_reg, pp_off);
5457
	else
4718
	I915_WRITE(pp_div_reg, pp_div);
5458
		I915_WRITE(pp_div_reg, pp_div);
4719
 
5459
 
-
 
5460
	DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
-
 
5461
		      I915_READ(pp_on_reg),
4720
	DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
5462
		      I915_READ(pp_off_reg),
4721
		      I915_READ(pp_on_reg),
5463
		      IS_BROXTON(dev) ?
Line -... Line 5464...
-
 
5464
		      (I915_READ(pp_ctrl_reg) & BXT_POWER_CYCLE_DELAY_MASK) :
-
 
5465
		      I915_READ(pp_div_reg));
-
 
5466
}
-
 
5467
 
-
 
5468
/**
-
 
5469
 * intel_dp_set_drrs_state - program registers for RR switch to take effect
-
 
5470
 * @dev: DRM device
-
 
5471
 * @refresh_rate: RR to be programmed
-
 
5472
 *
-
 
5473
 * This function gets called when refresh rate (RR) has to be changed from
-
 
5474
 * one frequency to another. Switches can be between high and low RR
-
 
5475
 * supported by the panel or to any other RR based on media playback (in
4722
		      I915_READ(pp_off_reg),
5476
 * this case, RR value needs to be passed from user space).
4723
		      I915_READ(pp_div_reg));
5477
 *
4724
}
5478
 * The caller of this function needs to take a lock on dev_priv->drrs.
4725
 
5479
 */
-
 
5480
static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
4726
void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
5481
{
4727
{
5482
	struct drm_i915_private *dev_priv = dev->dev_private;
4728
	struct drm_i915_private *dev_priv = dev->dev_private;
5483
	struct intel_encoder *encoder;
4729
	struct intel_encoder *encoder;
-
 
4730
	struct intel_dp *intel_dp = NULL;
-
 
4731
	struct intel_crtc_config *config = NULL;
5484
	struct intel_digital_port *dig_port = NULL;
Line 4732... Line 5485...
4732
	struct intel_crtc *intel_crtc = NULL;
5485
	struct intel_dp *intel_dp = dev_priv->drrs.dp;
4733
	struct intel_connector *intel_connector = dev_priv->drrs.connector;
5486
	struct intel_crtc_state *config = NULL;
4734
	u32 reg, val;
5487
	struct intel_crtc *intel_crtc = NULL;
4735
	enum edp_drrs_refresh_rate_type index = DRRS_HIGH_RR;
5488
	enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
Line 4736... Line 5489...
4736
 
5489
 
4737
	if (refresh_rate <= 0) {
5490
	if (refresh_rate <= 0) {
4738
		DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5491
		DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
4739
		return;
5492
		return;
Line 4740... Line 5493...
4740
	}
5493
	}
4741
 
5494
 
4742
	if (intel_connector == NULL) {
5495
	if (intel_dp == NULL) {
4743
		DRM_DEBUG_KMS("DRRS supported for eDP only.\n");
-
 
4744
		return;
5496
		DRM_DEBUG_KMS("DRRS not supported.\n");
4745
	}
-
 
4746
 
-
 
4747
	/*
-
 
4748
	 * FIXME: This needs proper synchronization with psr state. But really
-
 
Line 4749... Line 5497...
4749
	 * hard to tell without seeing the user of this function of this code.
5497
		return;
4750
	 * Check locking and ordering once that lands.
5498
	}
4751
	 */
5499
 
Line 4752... Line 5500...
4752
	if (INTEL_INFO(dev)->gen < 8 && intel_psr_is_enabled(dev)) {
5500
	/*
4753
		DRM_DEBUG_KMS("DRRS is disabled as PSR is enabled\n");
5501
	 * FIXME: This needs proper synchronization with psr state for some
4754
		return;
5502
	 * platforms that cannot have PSR and DRRS enabled at the same time.
4755
	}
5503
	 */
Line 4756... Line 5504...
4756
 
5504
 
Line 4757... Line 5505...
4757
	encoder = intel_attached_encoder(&intel_connector->base);
5505
	dig_port = dp_to_dig_port(intel_dp);
4758
	intel_dp = enc_to_intel_dp(&encoder->base);
5506
	encoder = &dig_port->base;
4759
	intel_crtc = encoder->new_crtc;
5507
	intel_crtc = to_intel_crtc(encoder->base.crtc);
4760
 
5508
 
Line 4761... Line 5509...
4761
	if (!intel_crtc) {
5509
	if (!intel_crtc) {
-
 
5510
		DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
4762
		DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5511
		return;
Line 4763... Line 5512...
4763
		return;
5512
	}
4764
	}
5513
 
4765
 
5514
	config = intel_crtc->config;
4766
	config = &intel_crtc->config;
5515
 
4767
 
5516
	if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
Line 4768... Line 5517...
4768
	if (intel_dp->drrs_state.type < SEAMLESS_DRRS_SUPPORT) {
5517
		DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
4769
		DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5518
		return;
4770
		return;
5519
	}
4771
	}
5520
 
Line 4772... Line 5521...
4772
 
5521
	if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
-
 
5522
			refresh_rate)
-
 
5523
		index = DRRS_LOW_RR;
-
 
5524
 
-
 
5525
	if (index == dev_priv->drrs.refresh_rate_type) {
-
 
5526
		DRM_DEBUG_KMS(
-
 
5527
			"DRRS requested for previously set RR...ignoring\n");
-
 
5528
		return;
-
 
5529
	}
-
 
5530
 
-
 
5531
	if (!intel_crtc->active) {
-
 
5532
		DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
-
 
5533
		return;
4773
	if (intel_connector->panel.downclock_mode->vrefresh == refresh_rate)
5534
	}
-
 
5535
 
-
 
5536
	if (INTEL_INFO(dev)->gen >= 8 && !IS_CHERRYVIEW(dev)) {
4774
		index = DRRS_LOW_RR;
5537
		switch (index) {
4775
 
5538
		case DRRS_HIGH_RR:
-
 
5539
			intel_dp_set_m_n(intel_crtc, M1_N1);
-
 
5540
			break;
-
 
5541
		case DRRS_LOW_RR:
4776
	if (index == intel_dp->drrs_state.refresh_rate_type) {
5542
			intel_dp_set_m_n(intel_crtc, M2_N2);
4777
		DRM_DEBUG_KMS(
-
 
4778
			"DRRS requested for previously set RR...ignoring\n");
5543
			break;
-
 
5544
		case DRRS_MAX_RR:
-
 
5545
		default:
-
 
5546
			DRM_ERROR("Unsupported refreshrate type\n");
4779
		return;
5547
		}
4780
	}
5548
	} else if (INTEL_INFO(dev)->gen > 6) {
4781
 
5549
		u32 reg = PIPECONF(intel_crtc->config->cpu_transcoder);
4782
	if (!intel_crtc->active) {
5550
		u32 val;
Line -... Line 5551...
-
 
5551
 
-
 
5552
		val = I915_READ(reg);
-
 
5553
		if (index > DRRS_HIGH_RR) {
-
 
5554
			if (IS_VALLEYVIEW(dev))
-
 
5555
				val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
-
 
5556
			else
-
 
5557
				val |= PIPECONF_EDP_RR_MODE_SWITCH;
-
 
5558
		} else {
-
 
5559
			if (IS_VALLEYVIEW(dev))
-
 
5560
				val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
-
 
5561
			else
-
 
5562
				val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
-
 
5563
		}
-
 
5564
		I915_WRITE(reg, val);
-
 
5565
	}
-
 
5566
 
-
 
5567
	dev_priv->drrs.refresh_rate_type = index;
-
 
5568
 
-
 
5569
	DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
-
 
5570
}
-
 
5571
 
-
 
5572
/**
-
 
5573
 * intel_edp_drrs_enable - init drrs struct if supported
-
 
5574
 * @intel_dp: DP struct
-
 
5575
 *
-
 
5576
 * Initializes frontbuffer_bits and drrs.dp
-
 
5577
 */
-
 
5578
void intel_edp_drrs_enable(struct intel_dp *intel_dp)
-
 
5579
{
-
 
5580
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
-
 
5581
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5582
	struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
-
 
5583
	struct drm_crtc *crtc = dig_port->base.base.crtc;
-
 
5584
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5585
 
-
 
5586
	if (!intel_crtc->config->has_drrs) {
-
 
5587
		DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
-
 
5588
		return;
-
 
5589
	}
-
 
5590
 
-
 
5591
	mutex_lock(&dev_priv->drrs.mutex);
-
 
5592
	if (WARN_ON(dev_priv->drrs.dp)) {
-
 
5593
		DRM_ERROR("DRRS already enabled\n");
-
 
5594
		goto unlock;
-
 
5595
	}
-
 
5596
 
-
 
5597
	dev_priv->drrs.busy_frontbuffer_bits = 0;
-
 
5598
 
-
 
5599
	dev_priv->drrs.dp = intel_dp;
-
 
5600
 
-
 
5601
unlock:
-
 
5602
	mutex_unlock(&dev_priv->drrs.mutex);
-
 
5603
}
-
 
5604
 
-
 
5605
/**
-
 
5606
 * intel_edp_drrs_disable - Disable DRRS
-
 
5607
 * @intel_dp: DP struct
-
 
5608
 *
-
 
5609
 */
-
 
5610
void intel_edp_drrs_disable(struct intel_dp *intel_dp)
-
 
5611
{
-
 
5612
	struct drm_device *dev = intel_dp_to_dev(intel_dp);
-
 
5613
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5614
	struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
-
 
5615
	struct drm_crtc *crtc = dig_port->base.base.crtc;
-
 
5616
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
5617
 
-
 
5618
	if (!intel_crtc->config->has_drrs)
-
 
5619
		return;
-
 
5620
 
-
 
5621
	mutex_lock(&dev_priv->drrs.mutex);
-
 
5622
	if (!dev_priv->drrs.dp) {
-
 
5623
		mutex_unlock(&dev_priv->drrs.mutex);
-
 
5624
		return;
-
 
5625
	}
-
 
5626
 
-
 
5627
	if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
-
 
5628
		intel_dp_set_drrs_state(dev_priv->dev,
-
 
5629
			intel_dp->attached_connector->panel.
-
 
5630
			fixed_mode->vrefresh);
-
 
5631
 
-
 
5632
	dev_priv->drrs.dp = NULL;
-
 
5633
	mutex_unlock(&dev_priv->drrs.mutex);
-
 
5634
 
4783
		DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5635
	cancel_delayed_work_sync(&dev_priv->drrs.work);
4784
		return;
5636
}
4785
	}
-
 
4786
 
5637
 
4787
	if (INTEL_INFO(dev)->gen > 6 && INTEL_INFO(dev)->gen < 8) {
-
 
4788
		reg = PIPECONF(intel_crtc->config.cpu_transcoder);
5638
static void intel_edp_drrs_downclock_work(struct work_struct *work)
Line 4789... Line 5639...
4789
		val = I915_READ(reg);
5639
{
-
 
5640
	struct drm_i915_private *dev_priv =
Line 4790... Line 5641...
4790
		if (index > DRRS_HIGH_RR) {
5641
		container_of(work, typeof(*dev_priv), drrs.work.work);
-
 
5642
	struct intel_dp *intel_dp;
-
 
5643
 
-
 
5644
	mutex_lock(&dev_priv->drrs.mutex);
Line -... Line 5645...
-
 
5645
 
4791
			val |= PIPECONF_EDP_RR_MODE_SWITCH;
5646
	intel_dp = dev_priv->drrs.dp;
-
 
5647
 
Line -... Line 5648...
-
 
5648
	if (!intel_dp)
-
 
5649
		goto unlock;
-
 
5650
 
-
 
5651
	/*
-
 
5652
	 * The delayed work can race with an invalidate hence we need to
-
 
5653
	 * recheck.
-
 
5654
	 */
-
 
5655
 
-
 
5656
	if (dev_priv->drrs.busy_frontbuffer_bits)
-
 
5657
		goto unlock;
-
 
5658
 
-
 
5659
	if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR)
-
 
5660
		intel_dp_set_drrs_state(dev_priv->dev,
4792
			intel_dp_set_m_n(intel_crtc);
5661
			intel_dp->attached_connector->panel.
-
 
5662
			downclock_mode->vrefresh);
-
 
5663
 
-
 
5664
unlock:
-
 
5665
	mutex_unlock(&dev_priv->drrs.mutex);
-
 
5666
}
-
 
5667
 
-
 
5668
/**
-
 
5669
 * intel_edp_drrs_invalidate - Disable Idleness DRRS
-
 
5670
 * @dev: DRM device
-
 
5671
 * @frontbuffer_bits: frontbuffer plane tracking bits
-
 
5672
 *
-
 
5673
 * This function gets called everytime rendering on the given planes start.
4793
		} else {
5674
 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
Line -... Line 5675...
-
 
5675
 *
-
 
5676
 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
-
 
5677
 */
-
 
5678
void intel_edp_drrs_invalidate(struct drm_device *dev,
-
 
5679
		unsigned frontbuffer_bits)
-
 
5680
{
-
 
5681
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5682
	struct drm_crtc *crtc;
-
 
5683
	enum pipe pipe;
-
 
5684
 
-
 
5685
	if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
-
 
5686
		return;
-
 
5687
 
-
 
5688
	cancel_delayed_work(&dev_priv->drrs.work);
-
 
5689
 
-
 
5690
	mutex_lock(&dev_priv->drrs.mutex);
-
 
5691
	if (!dev_priv->drrs.dp) {
-
 
5692
		mutex_unlock(&dev_priv->drrs.mutex);
-
 
5693
		return;
-
 
5694
	}
-
 
5695
 
-
 
5696
	crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
-
 
5697
	pipe = to_intel_crtc(crtc)->pipe;
-
 
5698
 
-
 
5699
	frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
-
 
5700
	dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
-
 
5701
 
-
 
5702
	/* invalidate means busy screen hence upclock */
-
 
5703
	if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
-
 
5704
		intel_dp_set_drrs_state(dev_priv->dev,
-
 
5705
				dev_priv->drrs.dp->attached_connector->panel.
-
 
5706
				fixed_mode->vrefresh);
-
 
5707
 
-
 
5708
	mutex_unlock(&dev_priv->drrs.mutex);
-
 
5709
}
-
 
5710
 
-
 
5711
/**
-
 
5712
 * intel_edp_drrs_flush - Restart Idleness DRRS
-
 
5713
 * @dev: DRM device
-
 
5714
 * @frontbuffer_bits: frontbuffer plane tracking bits
-
 
5715
 *
-
 
5716
 * This function gets called every time rendering on the given planes has
-
 
5717
 * completed or flip on a crtc is completed. So DRRS should be upclocked
-
 
5718
 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
-
 
5719
 * if no other planes are dirty.
-
 
5720
 *
-
 
5721
 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
-
 
5722
 */
-
 
5723
void intel_edp_drrs_flush(struct drm_device *dev,
-
 
5724
		unsigned frontbuffer_bits)
-
 
5725
{
-
 
5726
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
5727
	struct drm_crtc *crtc;
-
 
5728
	enum pipe pipe;
-
 
5729
 
-
 
5730
	if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
-
 
5731
		return;
-
 
5732
 
-
 
5733
//	cancel_delayed_work(&dev_priv->drrs.work);
-
 
5734
 
-
 
5735
	mutex_lock(&dev_priv->drrs.mutex);
-
 
5736
	if (!dev_priv->drrs.dp) {
-
 
5737
		mutex_unlock(&dev_priv->drrs.mutex);
-
 
5738
		return;
-
 
5739
	}
-
 
5740
 
-
 
5741
	crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
-
 
5742
	pipe = to_intel_crtc(crtc)->pipe;
-
 
5743
 
-
 
5744
	frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
-
 
5745
	dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
-
 
5746
 
-
 
5747
	/* flush means busy screen hence upclock */
-
 
5748
	if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
-
 
5749
		intel_dp_set_drrs_state(dev_priv->dev,
-
 
5750
				dev_priv->drrs.dp->attached_connector->panel.
-
 
5751
				fixed_mode->vrefresh);
-
 
5752
 
-
 
5753
	mutex_unlock(&dev_priv->drrs.mutex);
-
 
5754
}
-
 
5755
 
-
 
5756
/**
-
 
5757
 * DOC: Display Refresh Rate Switching (DRRS)
-
 
5758
 *
-
 
5759
 * Display Refresh Rate Switching (DRRS) is a power conservation feature
-
 
5760
 * which enables swtching between low and high refresh rates,
-
 
5761
 * dynamically, based on the usage scenario. This feature is applicable
-
 
5762
 * for internal panels.
-
 
5763
 *
-
 
5764
 * Indication that the panel supports DRRS is given by the panel EDID, which
-
 
5765
 * would list multiple refresh rates for one resolution.
-
 
5766
 *
-
 
5767
 * DRRS is of 2 types - static and seamless.
-
 
5768
 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
-
 
5769
 * (may appear as a blink on screen) and is used in dock-undock scenario.
-
 
5770
 * Seamless DRRS involves changing RR without any visual effect to the user
-
 
5771
 * and can be used during normal system usage. This is done by programming
-
 
5772
 * certain registers.
-
 
5773
 *
-
 
5774
 * Support for static/seamless DRRS may be indicated in the VBT based on
-
 
5775
 * inputs from the panel spec.
-
 
5776
 *
-
 
5777
 * DRRS saves power by switching to low RR based on usage scenarios.
-
 
5778
 *
-
 
5779
 * eDP DRRS:-
-
 
5780
 *        The implementation is based on frontbuffer tracking implementation.
-
 
5781
 * When there is a disturbance on the screen triggered by user activity or a
-
 
5782
 * periodic system activity, DRRS is disabled (RR is changed to high RR).
-
 
5783
 * When there is no movement on screen, after a timeout of 1 second, a switch
-
 
5784
 * to low RR is made.
4794
			val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
5785
 *        For integration with frontbuffer tracking code,
4795
		}
5786
 * intel_edp_drrs_invalidate() and intel_edp_drrs_flush() are called.
4796
		I915_WRITE(reg, val);
-
 
4797
	}
5787
 *
4798
 
5788
 * DRRS can be further extended to support other internal panels and also
4799
	/*
5789
 * the scenario of video playback wherein RR is set based on the rate
4800
	 * mutex taken to ensure that there is no race between differnt
-
 
4801
	 * drrs calls trying to update refresh rate. This scenario may occur
5790
 * requested by userspace.
4802
	 * in future when idleness detection based DRRS in kernel and
5791
 */
4803
	 * possible calls from user space to set differnt RR are made.
5792
 
Line -... Line 5793...
-
 
5793
/**
-
 
5794
 * intel_dp_drrs_init - Init basic DRRS work and mutex.
-
 
5795
 * @intel_connector: eDP connector
4804
	 */
5796
 * @fixed_mode: preferred mode of panel
4805
 
5797
 *
4806
	mutex_lock(&intel_dp->drrs_state.mutex);
5798
 * This function is  called only once at driver load to initialize basic
4807
 
5799
 * DRRS stuff.
Line 4835... Line 5827...
4835
 
5827
 
4836
	downclock_mode = intel_find_panel_downclock
5828
	downclock_mode = intel_find_panel_downclock
Line 4837... Line 5829...
4837
					(dev, fixed_mode, connector);
5829
					(dev, fixed_mode, connector);
4838
 
5830
 
4839
	if (!downclock_mode) {
5831
	if (!downclock_mode) {
4840
		DRM_DEBUG_KMS("DRRS not supported\n");
5832
		DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
Line 4841... Line -...
4841
		return NULL;
-
 
4842
	}
-
 
4843
 
-
 
4844
	dev_priv->drrs.connector = intel_connector;
-
 
4845
 
5833
		return NULL;
Line 4846... Line 5834...
4846
	mutex_init(&intel_dp->drrs_state.mutex);
5834
	}
4847
 
5835
 
4848
	intel_dp->drrs_state.type = dev_priv->vbt.drrs_type;
5836
	dev_priv->drrs.type = dev_priv->vbt.drrs_type;
4849
 
5837
 
Line 4850... Line 5838...
4850
	intel_dp->drrs_state.refresh_rate_type = DRRS_HIGH_RR;
5838
	dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
Line 4865... Line 5853...
4865
	bool has_dpcd;
5853
	bool has_dpcd;
4866
	struct drm_display_mode *scan;
5854
	struct drm_display_mode *scan;
4867
	struct edid *edid;
5855
	struct edid *edid;
4868
	enum pipe pipe = INVALID_PIPE;
5856
	enum pipe pipe = INVALID_PIPE;
Line 4869... Line -...
4869
 
-
 
4870
	intel_dp->drrs_state.type = DRRS_NOT_SUPPORTED;
-
 
4871
 
5857
 
4872
	if (!is_edp(intel_dp))
5858
	if (!is_edp(intel_dp))
Line 4873... Line 5859...
4873
		return true;
5859
		return true;
4874
 
5860
 
Line 4914... Line 5900...
4914
	/* prefer fixed mode from EDID if available */
5900
	/* prefer fixed mode from EDID if available */
4915
	list_for_each_entry(scan, &connector->probed_modes, head) {
5901
	list_for_each_entry(scan, &connector->probed_modes, head) {
4916
		if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5902
		if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
4917
			fixed_mode = drm_mode_duplicate(dev, scan);
5903
			fixed_mode = drm_mode_duplicate(dev, scan);
4918
			downclock_mode = intel_dp_drrs_init(
5904
			downclock_mode = intel_dp_drrs_init(
4919
						intel_dig_port,
-
 
4920
						intel_connector, fixed_mode);
5905
						intel_connector, fixed_mode);
4921
			break;
5906
			break;
4922
		}
5907
		}
4923
	}
5908
	}
Line 4952... Line 5937...
4952
		DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5937
		DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
4953
			      pipe_name(pipe));
5938
			      pipe_name(pipe));
4954
	}
5939
	}
Line 4955... Line 5940...
4955
 
5940
 
4956
	intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
5941
	intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
4957
	intel_connector->panel.backlight_power = intel_edp_backlight_power;
5942
	intel_connector->panel.backlight.power = intel_edp_backlight_power;
Line 4958... Line 5943...
4958
	intel_panel_setup_backlight(connector, pipe);
5943
	intel_panel_setup_backlight(connector, pipe);
4959
 
5944
 
Line 5040... Line 6025...
5040
	case PORT_A:
6025
	case PORT_A:
5041
		intel_encoder->hpd_pin = HPD_PORT_A;
6026
		intel_encoder->hpd_pin = HPD_PORT_A;
5042
			break;
6027
		break;
5043
	case PORT_B:
6028
	case PORT_B:
5044
		intel_encoder->hpd_pin = HPD_PORT_B;
6029
		intel_encoder->hpd_pin = HPD_PORT_B;
-
 
6030
		if (IS_BROXTON(dev_priv) && (INTEL_REVID(dev) < BXT_REVID_B0))
-
 
6031
			intel_encoder->hpd_pin = HPD_PORT_A;
5045
			break;
6032
		break;
5046
	case PORT_C:
6033
	case PORT_C:
5047
		intel_encoder->hpd_pin = HPD_PORT_C;
6034
		intel_encoder->hpd_pin = HPD_PORT_C;
5048
			break;
6035
		break;
5049
	case PORT_D:
6036
	case PORT_D:
5050
		intel_encoder->hpd_pin = HPD_PORT_D;
6037
		intel_encoder->hpd_pin = HPD_PORT_D;
5051
			break;
6038
		break;
-
 
6039
	case PORT_E:
-
 
6040
		intel_encoder->hpd_pin = HPD_PORT_E;
-
 
6041
		break;
5052
	default:
6042
	default:
5053
		BUG();
6043
		BUG();
5054
	}
6044
	}
Line 5055... Line 6045...
5055
 
6045
 
Line 5064... Line 6054...
5064
	}
6054
	}
Line 5065... Line 6055...
5065
 
6055
 
Line 5066... Line 6056...
5066
	intel_dp_aux_init(intel_dp, intel_connector);
6056
	intel_dp_aux_init(intel_dp, intel_connector);
5067
 
6057
 
5068
	/* init MST on ports that can support it */
6058
	/* init MST on ports that can support it */
5069
	if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
6059
	if (HAS_DP_MST(dev) &&
5070
		if (port == PORT_B || port == PORT_C || port == PORT_D) {
6060
	    (port == PORT_B || port == PORT_C || port == PORT_D))
5071
			intel_dp_mst_encoder_init(intel_dig_port,
-
 
5072
						  intel_connector->base.base.id);
-
 
Line 5073... Line 6061...
5073
		}
6061
		intel_dp_mst_encoder_init(intel_dig_port,
5074
	}
6062
					  intel_connector->base.base.id);
5075
 
6063
 
5076
	if (!intel_edp_init_connector(intel_dp, intel_connector)) {
6064
	if (!intel_edp_init_connector(intel_dp, intel_connector)) {
Line 5115... Line 6103...
5115
 
6103
 
5116
	intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
6104
	intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
5117
	if (!intel_dig_port)
6105
	if (!intel_dig_port)
Line 5118... Line 6106...
5118
		return;
6106
		return;
5119
 
6107
 
5120
	intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
6108
	intel_connector = intel_connector_alloc();
5121
	if (!intel_connector) {
-
 
5122
		kfree(intel_dig_port);
-
 
Line 5123... Line 6109...
5123
		return;
6109
	if (!intel_connector)
5124
	}
6110
		goto err_connector_alloc;
Line 5125... Line 6111...
5125
 
6111
 
Line 5137... Line 6123...
5137
	if (IS_CHERRYVIEW(dev)) {
6123
	if (IS_CHERRYVIEW(dev)) {
5138
		intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
6124
		intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
5139
		intel_encoder->pre_enable = chv_pre_enable_dp;
6125
		intel_encoder->pre_enable = chv_pre_enable_dp;
5140
		intel_encoder->enable = vlv_enable_dp;
6126
		intel_encoder->enable = vlv_enable_dp;
5141
		intel_encoder->post_disable = chv_post_disable_dp;
6127
		intel_encoder->post_disable = chv_post_disable_dp;
-
 
6128
		intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
5142
	} else if (IS_VALLEYVIEW(dev)) {
6129
	} else if (IS_VALLEYVIEW(dev)) {
5143
		intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
6130
		intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
5144
		intel_encoder->pre_enable = vlv_pre_enable_dp;
6131
		intel_encoder->pre_enable = vlv_pre_enable_dp;
5145
		intel_encoder->enable = vlv_enable_dp;
6132
		intel_encoder->enable = vlv_enable_dp;
5146
		intel_encoder->post_disable = vlv_post_disable_dp;
6133
		intel_encoder->post_disable = vlv_post_disable_dp;
Line 5162... Line 6149...
5162
			intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6149
			intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
5163
	} else {
6150
	} else {
5164
	intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6151
		intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
5165
	}
6152
	}
5166
	intel_encoder->cloneable = 0;
6153
	intel_encoder->cloneable = 0;
5167
	intel_encoder->hot_plug = intel_dp_hot_plug;
-
 
Line 5168... Line 6154...
5168
 
6154
 
5169
	intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
6155
	intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
-
 
6156
	dev_priv->hotplug.irq_port[port] = intel_dig_port;
-
 
6157
 
-
 
6158
	if (!intel_dp_init_connector(intel_dig_port, intel_connector))
Line -... Line 6159...
-
 
6159
		goto err_init_connector;
-
 
6160
 
5170
	dev_priv->hpd_irq_port[port] = intel_dig_port;
6161
	return;
5171
 
6162
 
5172
	if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
-
 
5173
		drm_encoder_cleanup(encoder);
6163
err_init_connector:
-
 
6164
	drm_encoder_cleanup(encoder);
-
 
6165
	kfree(intel_connector);
5174
		kfree(intel_dig_port);
6166
err_connector_alloc:
-
 
6167
	kfree(intel_dig_port);
5175
		kfree(intel_connector);
6168
 
Line 5176... Line 6169...
5176
	}
6169
	return;
5177
}
6170
}
5178
 
6171
 
5179
void intel_dp_mst_suspend(struct drm_device *dev)
6172
void intel_dp_mst_suspend(struct drm_device *dev)
Line 5180... Line 6173...
5180
{
6173
{
5181
	struct drm_i915_private *dev_priv = dev->dev_private;
6174
	struct drm_i915_private *dev_priv = dev->dev_private;
5182
	int i;
6175
	int i;
5183
 
6176
 
5184
	/* disable MST */
6177
	/* disable MST */
Line 5185... Line 6178...
5185
	for (i = 0; i < I915_MAX_PORTS; i++) {
6178
	for (i = 0; i < I915_MAX_PORTS; i++) {
5186
		struct intel_digital_port *intel_dig_port = dev_priv->hpd_irq_port[i];
6179
		struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
Line 5200... Line 6193...
5200
{
6193
{
5201
	struct drm_i915_private *dev_priv = dev->dev_private;
6194
	struct drm_i915_private *dev_priv = dev->dev_private;
5202
	int i;
6195
	int i;
Line 5203... Line 6196...
5203
 
6196
 
5204
	for (i = 0; i < I915_MAX_PORTS; i++) {
6197
	for (i = 0; i < I915_MAX_PORTS; i++) {
5205
		struct intel_digital_port *intel_dig_port = dev_priv->hpd_irq_port[i];
6198
		struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
5206
		if (!intel_dig_port)
6199
		if (!intel_dig_port)
5207
			continue;
6200
			continue;
5208
		if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
6201
		if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {