Subversion Repositories Kolibri OS

Rev

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

Rev 4560 Rev 5060
Line 74... Line 74...
74
 
74
 
75
static const u32 bdw_ddi_translations_edp[] = {
75
static const u32 bdw_ddi_translations_edp[] = {
76
	0x00FFFFFF, 0x00000012,		/* eDP parameters */
76
	0x00FFFFFF, 0x00000012,		/* eDP parameters */
77
	0x00EBAFFF, 0x00020011,
77
	0x00EBAFFF, 0x00020011,
-
 
78
	0x00C71FFF, 0x0006000F,
78
	0x00C71FFF, 0x0006000F,
79
	0x00AAAFFF, 0x000E000A,
79
	0x00FFFFFF, 0x00020011,
80
	0x00FFFFFF, 0x00020011,
80
	0x00DB6FFF, 0x0005000F,
81
	0x00DB6FFF, 0x0005000F,
81
	0x00BEEFFF, 0x000A000C,
82
	0x00BEEFFF, 0x000A000C,
82
	0x00FFFFFF, 0x0005000F,
83
	0x00FFFFFF, 0x0005000F,
83
	0x00DB6FFF, 0x000A000C,
-
 
84
	0x00FFFFFF, 0x000A000C,
84
	0x00DB6FFF, 0x000A000C,
85
	0x00FFFFFF, 0x00140006		/* HDMI parameters 800mV 0dB*/
85
	0x00FFFFFF, 0x00140006		/* HDMI parameters 800mV 0dB*/
Line 86... Line 86...
86
};
86
};
87
 
87
 
88
static const u32 bdw_ddi_translations_dp[] = {
88
static const u32 bdw_ddi_translations_dp[] = {
89
	0x00FFFFFF, 0x0007000E,		/* DP parameters */
89
	0x00FFFFFF, 0x0007000E,		/* DP parameters */
-
 
90
	0x00D75FFF, 0x000E000A,
90
	0x00D75FFF, 0x000E000A,
91
	0x00BEFFFF, 0x00140006,
91
	0x00BEFFFF, 0x00140006,
92
	0x80B2CFFF, 0x001B0002,
92
	0x00FFFFFF, 0x000E000A,
93
	0x00FFFFFF, 0x000E000A,
93
	0x00D75FFF, 0x00180004,
94
	0x00D75FFF, 0x00180004,
94
	0x80CB2FFF, 0x001B0002,
95
	0x80CB2FFF, 0x001B0002,
95
	0x00F7DFFF, 0x00180004,
-
 
96
	0x80D75FFF, 0x001B0002,
96
	0x00F7DFFF, 0x00180004,
97
	0x80FFFFFF, 0x001B0002,
97
	0x80D75FFF, 0x001B0002,
Line 98... Line 98...
98
	0x00FFFFFF, 0x00140006		/* HDMI parameters 800mV 0dB*/
98
	0x00FFFFFF, 0x00140006		/* HDMI parameters 800mV 0dB*/
99
};
99
};
Line 114... Line 114...
114
enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
114
enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
115
{
115
{
116
	struct drm_encoder *encoder = &intel_encoder->base;
116
	struct drm_encoder *encoder = &intel_encoder->base;
117
	int type = intel_encoder->type;
117
	int type = intel_encoder->type;
Line -... Line 118...
-
 
118
 
-
 
119
	if (type == INTEL_OUTPUT_DP_MST) {
-
 
120
		struct intel_digital_port *intel_dig_port = enc_to_mst(encoder)->primary;
118
 
121
		return intel_dig_port->port;
119
	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
122
	} else if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
120
	    type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
123
	    type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
121
		struct intel_digital_port *intel_dig_port =
124
		struct intel_digital_port *intel_dig_port =
122
			enc_to_dig_port(encoder);
125
			enc_to_dig_port(encoder);
Line 275... Line 278...
275
	/* Switch from Rawclk to PCDclk */
278
	/* Switch from Rawclk to PCDclk */
276
	rx_ctl_val |= FDI_PCDCLK;
279
	rx_ctl_val |= FDI_PCDCLK;
277
	I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
280
	I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Line 278... Line 281...
278
 
281
 
279
	/* Configure Port Clock Select */
282
	/* Configure Port Clock Select */
-
 
283
	I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config.ddi_pll_sel);
Line 280... Line 284...
280
	I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->ddi_pll_sel);
284
	WARN_ON(intel_crtc->config.ddi_pll_sel != PORT_CLK_SEL_SPLL);
281
 
285
 
282
	/* Start the training iterating through available voltages and emphasis,
286
	/* Start the training iterating through available voltages and emphasis,
283
	 * testing each value twice. */
287
	 * testing each value twice. */
Line 362... Line 366...
362
	}
366
	}
Line 363... Line 367...
363
 
367
 
364
	DRM_ERROR("FDI link training failed!\n");
368
	DRM_ERROR("FDI link training failed!\n");
Line 365... Line 369...
365
}
369
}
366
 
370
 
367
static void intel_ddi_mode_set(struct intel_encoder *encoder)
-
 
368
{
-
 
369
	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
-
 
370
	int port = intel_ddi_get_encoder_port(encoder);
-
 
371
	int pipe = crtc->pipe;
-
 
372
	int type = encoder->type;
-
 
373
	struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
-
 
374
 
-
 
375
	DRM_DEBUG_KMS("Preparing DDI mode on port %c, pipe %c\n",
-
 
376
		      port_name(port), pipe_name(pipe));
-
 
377
 
-
 
378
	crtc->eld_vld = false;
371
void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
379
	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
372
{
380
		struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
373
	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
Line 381... Line 374...
381
		struct intel_digital_port *intel_dig_port =
374
	struct intel_digital_port *intel_dig_port =
382
			enc_to_dig_port(&encoder->base);
375
		enc_to_dig_port(&encoder->base);
383
 
376
 
Line 384... Line -...
384
		intel_dp->DP = intel_dig_port->saved_port_bits |
-
 
385
			       DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
-
 
386
		intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
-
 
387
 
-
 
388
		if (intel_dp->has_audio) {
-
 
389
			DRM_DEBUG_DRIVER("DP audio on pipe %c on DDI\n",
-
 
390
					 pipe_name(crtc->pipe));
-
 
391
 
-
 
392
			/* write eld */
-
 
393
			DRM_DEBUG_DRIVER("DP audio: write eld information\n");
-
 
394
			intel_write_eld(&encoder->base, adjusted_mode);
-
 
395
		}
-
 
396
	} else if (type == INTEL_OUTPUT_HDMI) {
-
 
397
		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
-
 
398
 
-
 
399
	if (intel_hdmi->has_audio) {
-
 
400
			/* Proper support for digital audio needs a new logic
-
 
401
			 * and a new set of registers, so we leave it for future
-
 
402
			 * patch bombing.
-
 
403
		 */
-
 
404
		DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
-
 
405
					 pipe_name(crtc->pipe));
-
 
406
 
-
 
407
		/* write eld */
-
 
408
		DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
-
 
409
			intel_write_eld(&encoder->base, adjusted_mode);
-
 
410
	}
377
	intel_dp->DP = intel_dig_port->saved_port_bits |
Line 411... Line 378...
411
 
378
		DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
412
		intel_hdmi->set_infoframes(&encoder->base, adjusted_mode);
379
	intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
413
	}
380
 
Line 432... Line 399...
432
 
399
 
433
	BUG_ON(ret == NULL);
400
	BUG_ON(ret == NULL);
434
	return ret;
401
	return ret;
Line 435... Line -...
435
}
-
 
436
 
-
 
437
void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
-
 
438
{
-
 
439
	struct drm_i915_private *dev_priv = crtc->dev->dev_private;
-
 
440
	struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
-
 
441
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
442
	uint32_t val;
-
 
443
 
-
 
444
	switch (intel_crtc->ddi_pll_sel) {
-
 
445
	case PORT_CLK_SEL_SPLL:
-
 
446
		plls->spll_refcount--;
-
 
447
		if (plls->spll_refcount == 0) {
-
 
448
			DRM_DEBUG_KMS("Disabling SPLL\n");
-
 
449
			val = I915_READ(SPLL_CTL);
-
 
450
			WARN_ON(!(val & SPLL_PLL_ENABLE));
-
 
451
			I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
-
 
452
			POSTING_READ(SPLL_CTL);
-
 
453
		}
-
 
454
		break;
-
 
455
	case PORT_CLK_SEL_WRPLL1:
-
 
456
		plls->wrpll1_refcount--;
-
 
457
		if (plls->wrpll1_refcount == 0) {
-
 
458
			DRM_DEBUG_KMS("Disabling WRPLL 1\n");
-
 
459
			val = I915_READ(WRPLL_CTL1);
-
 
460
			WARN_ON(!(val & WRPLL_PLL_ENABLE));
-
 
461
			I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
-
 
462
			POSTING_READ(WRPLL_CTL1);
-
 
463
		}
-
 
464
		break;
-
 
465
	case PORT_CLK_SEL_WRPLL2:
-
 
466
		plls->wrpll2_refcount--;
-
 
467
		if (plls->wrpll2_refcount == 0) {
-
 
468
			DRM_DEBUG_KMS("Disabling WRPLL 2\n");
-
 
469
			val = I915_READ(WRPLL_CTL2);
-
 
470
			WARN_ON(!(val & WRPLL_PLL_ENABLE));
-
 
471
			I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
-
 
472
			POSTING_READ(WRPLL_CTL2);
-
 
473
		}
-
 
474
		break;
-
 
475
	}
-
 
476
 
-
 
477
	WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
-
 
478
	WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
-
 
479
	WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
-
 
480
 
-
 
481
	intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
-
 
482
}
402
}
483
 
403
 
Line 484... Line 404...
484
#define LC_FREQ 2700
404
#define LC_FREQ 2700
485
#define LC_FREQ_2K (LC_FREQ * 2000)
405
#define LC_FREQ_2K (LC_FREQ * 2000)
Line 631... Line 551...
631
		}
551
		}
632
	}
552
	}
633
	/* Otherwise a < c && b >= d, do nothing */
553
	/* Otherwise a < c && b >= d, do nothing */
634
}
554
}
Line -... Line 555...
-
 
555
 
-
 
556
static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
-
 
557
				     int reg)
-
 
558
{
-
 
559
	int refclk = LC_FREQ;
-
 
560
	int n, p, r;
-
 
561
	u32 wrpll;
-
 
562
 
-
 
563
	wrpll = I915_READ(reg);
-
 
564
	switch (wrpll & WRPLL_PLL_REF_MASK) {
-
 
565
	case WRPLL_PLL_SSC:
-
 
566
	case WRPLL_PLL_NON_SSC:
-
 
567
		/*
-
 
568
		 * We could calculate spread here, but our checking
-
 
569
		 * code only cares about 5% accuracy, and spread is a max of
-
 
570
		 * 0.5% downspread.
-
 
571
		 */
-
 
572
		refclk = 135;
-
 
573
		break;
-
 
574
	case WRPLL_PLL_LCPLL:
-
 
575
		refclk = LC_FREQ;
-
 
576
		break;
-
 
577
	default:
-
 
578
		WARN(1, "bad wrpll refclk\n");
-
 
579
		return 0;
-
 
580
	}
-
 
581
 
-
 
582
	r = wrpll & WRPLL_DIVIDER_REF_MASK;
-
 
583
	p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
-
 
584
	n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
-
 
585
 
-
 
586
	/* Convert to KHz, p & r have a fixed point portion */
-
 
587
	return (refclk * n * 100) / (p * r);
-
 
588
}
-
 
589
 
-
 
590
void intel_ddi_clock_get(struct intel_encoder *encoder,
-
 
591
				struct intel_crtc_config *pipe_config)
-
 
592
{
-
 
593
	struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
-
 
594
	int link_clock = 0;
-
 
595
	u32 val, pll;
-
 
596
 
-
 
597
	val = pipe_config->ddi_pll_sel;
-
 
598
	switch (val & PORT_CLK_SEL_MASK) {
-
 
599
	case PORT_CLK_SEL_LCPLL_810:
-
 
600
		link_clock = 81000;
-
 
601
		break;
-
 
602
	case PORT_CLK_SEL_LCPLL_1350:
-
 
603
		link_clock = 135000;
-
 
604
		break;
-
 
605
	case PORT_CLK_SEL_LCPLL_2700:
-
 
606
		link_clock = 270000;
-
 
607
		break;
-
 
608
	case PORT_CLK_SEL_WRPLL1:
-
 
609
		link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
-
 
610
		break;
-
 
611
	case PORT_CLK_SEL_WRPLL2:
-
 
612
		link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
-
 
613
		break;
-
 
614
	case PORT_CLK_SEL_SPLL:
-
 
615
		pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
-
 
616
		if (pll == SPLL_PLL_FREQ_810MHz)
-
 
617
			link_clock = 81000;
-
 
618
		else if (pll == SPLL_PLL_FREQ_1350MHz)
-
 
619
			link_clock = 135000;
-
 
620
		else if (pll == SPLL_PLL_FREQ_2700MHz)
-
 
621
			link_clock = 270000;
-
 
622
		else {
-
 
623
			WARN(1, "bad spll freq\n");
-
 
624
			return;
-
 
625
		}
-
 
626
		break;
-
 
627
	default:
-
 
628
		WARN(1, "bad port clock sel\n");
-
 
629
		return;
-
 
630
	}
-
 
631
 
-
 
632
	pipe_config->port_clock = link_clock * 2;
-
 
633
 
-
 
634
	if (pipe_config->has_pch_encoder)
-
 
635
		pipe_config->adjusted_mode.crtc_clock =
-
 
636
			intel_dotclock_calculate(pipe_config->port_clock,
-
 
637
						 &pipe_config->fdi_m_n);
-
 
638
	else if (pipe_config->has_dp_encoder)
-
 
639
		pipe_config->adjusted_mode.crtc_clock =
-
 
640
			intel_dotclock_calculate(pipe_config->port_clock,
-
 
641
						 &pipe_config->dp_m_n);
-
 
642
	else
-
 
643
		pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
-
 
644
}
635
 
645
 
636
static void
646
static void
637
intel_ddi_calculate_wrpll(int clock /* in Hz */,
647
intel_ddi_calculate_wrpll(int clock /* in Hz */,
638
			  unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
648
			  unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
639
{
649
{
Line 706... Line 716...
706
 */
716
 */
707
bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
717
bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
708
{
718
{
709
	struct drm_crtc *crtc = &intel_crtc->base;
719
	struct drm_crtc *crtc = &intel_crtc->base;
710
	struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
720
	struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
711
	struct drm_encoder *encoder = &intel_encoder->base;
-
 
712
	struct drm_i915_private *dev_priv = crtc->dev->dev_private;
-
 
713
	struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
-
 
714
	int type = intel_encoder->type;
721
	int type = intel_encoder->type;
715
	enum pipe pipe = intel_crtc->pipe;
-
 
716
	int clock = intel_crtc->config.port_clock;
722
	int clock = intel_crtc->config.port_clock;
Line 717... Line 723...
717
 
723
 
Line 718... Line 724...
718
	intel_ddi_put_crtc_pll(crtc);
724
	intel_put_shared_dpll(intel_crtc);
719
 
-
 
720
	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
-
 
721
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
725
 
722
 
-
 
723
		switch (intel_dp->link_bw) {
-
 
724
		case DP_LINK_BW_1_62:
-
 
725
			intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
-
 
726
			break;
-
 
727
		case DP_LINK_BW_2_7:
-
 
728
			intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
-
 
729
			break;
-
 
730
		case DP_LINK_BW_5_4:
-
 
731
			intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
-
 
732
			break;
-
 
733
		default:
-
 
734
			DRM_ERROR("Link bandwidth %d unsupported\n",
-
 
735
				  intel_dp->link_bw);
-
 
736
			return false;
-
 
737
		}
-
 
738
 
726
	if (type == INTEL_OUTPUT_HDMI) {
739
	} else if (type == INTEL_OUTPUT_HDMI) {
727
		struct intel_shared_dpll *pll;
Line 740... Line 728...
740
		uint32_t reg, val;
728
		uint32_t val;
Line 741... Line 729...
741
		unsigned p, n2, r2;
729
		unsigned p, n2, r2;
742
 
730
 
743
		intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
731
		intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Line 744... Line -...
744
 
-
 
745
		val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
-
 
746
		      WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
-
 
747
		      WRPLL_DIVIDER_POST(p);
-
 
748
 
-
 
749
		if (val == I915_READ(WRPLL_CTL1)) {
-
 
750
			DRM_DEBUG_KMS("Reusing WRPLL 1 on pipe %c\n",
-
 
751
				      pipe_name(pipe));
-
 
752
			reg = WRPLL_CTL1;
-
 
753
		} else if (val == I915_READ(WRPLL_CTL2)) {
-
 
754
			DRM_DEBUG_KMS("Reusing WRPLL 2 on pipe %c\n",
-
 
755
				      pipe_name(pipe));
-
 
756
			reg = WRPLL_CTL2;
-
 
757
		} else if (plls->wrpll1_refcount == 0) {
-
 
758
			DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
-
 
759
				      pipe_name(pipe));
-
 
760
			reg = WRPLL_CTL1;
-
 
761
		} else if (plls->wrpll2_refcount == 0) {
-
 
762
			DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
-
 
763
				      pipe_name(pipe));
-
 
764
			reg = WRPLL_CTL2;
-
 
765
		} else {
-
 
766
			DRM_ERROR("No WRPLLs available!\n");
-
 
767
			return false;
-
 
768
		}
-
 
769
 
-
 
770
		DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
-
 
771
			      clock, p, n2, r2);
-
 
772
 
-
 
773
		if (reg == WRPLL_CTL1) {
732
 
774
			plls->wrpll1_refcount++;
-
 
Line 775... Line 733...
775
			intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
733
		val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
776
		} else {
734
		      WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
777
			plls->wrpll2_refcount++;
735
		      WRPLL_DIVIDER_POST(p);
778
			intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
736
 
779
		}
-
 
780
 
-
 
781
	} else if (type == INTEL_OUTPUT_ANALOG) {
-
 
782
		if (plls->spll_refcount == 0) {
-
 
783
			DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
737
		intel_crtc->config.dpll_hw_state.wrpll = val;
784
				      pipe_name(pipe));
738
 
Line 785... Line -...
785
			plls->spll_refcount++;
-
 
786
			intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
739
		pll = intel_get_shared_dpll(intel_crtc);
787
		} else {
-
 
788
			DRM_ERROR("SPLL already in use\n");
740
		if (pll == NULL) {
Line 789... Line 741...
789
			return false;
741
			DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
790
		}
742
					 pipe_name(intel_crtc->pipe));
Line 791... Line -...
791
 
-
 
792
	} else {
-
 
793
		WARN(1, "Invalid DDI encoder type %d\n", type);
-
 
794
		return false;
-
 
795
	}
-
 
796
 
-
 
797
	return true;
-
 
798
}
-
 
799
 
-
 
800
/*
-
 
801
 * To be called after intel_ddi_pll_select(). That one selects the PLL to be
-
 
802
 * used, this one actually enables the PLL.
-
 
803
 */
-
 
804
void intel_ddi_pll_enable(struct intel_crtc *crtc)
-
 
805
{
-
 
806
	struct drm_device *dev = crtc->base.dev;
-
 
807
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
808
	struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
-
 
809
	int clock = crtc->config.port_clock;
-
 
810
	uint32_t reg, cur_val, new_val;
-
 
811
	int refcount;
-
 
812
	const char *pll_name;
-
 
813
	uint32_t enable_bit = (1 << 31);
-
 
814
	unsigned int p, n2, r2;
-
 
815
 
-
 
816
	BUILD_BUG_ON(enable_bit != SPLL_PLL_ENABLE);
-
 
817
	BUILD_BUG_ON(enable_bit != WRPLL_PLL_ENABLE);
-
 
818
 
-
 
819
	switch (crtc->ddi_pll_sel) {
-
 
820
	case PORT_CLK_SEL_LCPLL_2700:
-
 
821
	case PORT_CLK_SEL_LCPLL_1350:
-
 
822
	case PORT_CLK_SEL_LCPLL_810:
-
 
823
		/*
-
 
824
		 * LCPLL should always be enabled at this point of the mode set
-
 
825
		 * sequence, so nothing to do.
-
 
826
		 */
-
 
827
		return;
-
 
828
 
-
 
829
	case PORT_CLK_SEL_SPLL:
-
 
830
		pll_name = "SPLL";
-
 
831
		reg = SPLL_CTL;
-
 
832
		refcount = plls->spll_refcount;
-
 
833
		new_val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz |
-
 
834
			  SPLL_PLL_SSC;
-
 
835
		break;
-
 
836
 
-
 
837
	case PORT_CLK_SEL_WRPLL1:
-
 
838
	case PORT_CLK_SEL_WRPLL2:
-
 
839
		if (crtc->ddi_pll_sel == PORT_CLK_SEL_WRPLL1) {
-
 
840
			pll_name = "WRPLL1";
-
 
841
			reg = WRPLL_CTL1;
-
 
842
			refcount = plls->wrpll1_refcount;
-
 
843
	} else {
-
 
844
			pll_name = "WRPLL2";
-
 
845
			reg = WRPLL_CTL2;
-
 
846
			refcount = plls->wrpll2_refcount;
-
 
847
		}
-
 
848
 
-
 
849
		intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
-
 
850
 
-
 
851
		new_val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
-
 
852
			  WRPLL_DIVIDER_REFERENCE(r2) |
-
 
853
			  WRPLL_DIVIDER_FEEDBACK(n2) | WRPLL_DIVIDER_POST(p);
-
 
854
 
-
 
855
		break;
-
 
856
 
-
 
857
	case PORT_CLK_SEL_NONE:
-
 
858
		WARN(1, "Bad selected pll: PORT_CLK_SEL_NONE\n");
-
 
859
		return;
-
 
860
	default:
-
 
861
		WARN(1, "Bad selected pll: 0x%08x\n", crtc->ddi_pll_sel);
-
 
862
		return;
-
 
863
	}
-
 
864
 
-
 
865
	cur_val = I915_READ(reg);
-
 
866
 
-
 
867
	WARN(refcount < 1, "Bad %s refcount: %d\n", pll_name, refcount);
-
 
868
	if (refcount == 1) {
-
 
869
		WARN(cur_val & enable_bit, "%s already enabled\n", pll_name);
743
			return false;
870
		I915_WRITE(reg, new_val);
744
		}
871
		POSTING_READ(reg);
745
 
872
	udelay(20);
746
		intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id);
873
	} else {
747
	}
874
		WARN((cur_val & enable_bit) == 0, "%s disabled\n", pll_name);
748
 
875
	}
749
	return true;
876
}
750
}
Line 877... Line 751...
877
 
751
 
878
void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
-
 
879
{
752
void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
880
	struct drm_i915_private *dev_priv = crtc->dev->dev_private;
753
{
881
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
754
	struct drm_i915_private *dev_priv = crtc->dev->dev_private;
882
	struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
755
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
883
	enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
756
	struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Line 905... Line 778...
905
	}
778
	}
906
		I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
779
		I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
907
	}
780
	}
908
}
781
}
Line -... Line 782...
-
 
782
 
-
 
783
void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
-
 
784
{
-
 
785
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
 
786
	struct drm_device *dev = crtc->dev;
-
 
787
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
788
	enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
-
 
789
	uint32_t temp;
-
 
790
	temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
-
 
791
	if (state == true)
-
 
792
		temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
-
 
793
	else
-
 
794
		temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
-
 
795
	I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
-
 
796
}
909
 
797
 
910
void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
798
void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
911
{
799
{
912
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
800
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
913
	struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
801
	struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Line 951... Line 839...
951
		case PIPE_A:
839
		case PIPE_A:
952
			/* On Haswell, can only use the always-on power well for
840
			/* On Haswell, can only use the always-on power well for
953
			 * eDP when not using the panel fitter, and when not
841
			 * eDP when not using the panel fitter, and when not
954
			 * using motion blur mitigation (which we don't
842
			 * using motion blur mitigation (which we don't
955
			 * support). */
843
			 * support). */
-
 
844
			if (IS_HASWELL(dev) &&
956
			if (IS_HASWELL(dev) && intel_crtc->config.pch_pfit.enabled)
845
			    (intel_crtc->config.pch_pfit.enabled ||
-
 
846
			     intel_crtc->config.pch_pfit.force_thru))
957
			temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
847
			temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
958
			else
848
			else
959
				temp |= TRANS_DDI_EDP_INPUT_A_ON;
849
				temp |= TRANS_DDI_EDP_INPUT_A_ON;
960
			break;
850
			break;
961
		case PIPE_B:
851
		case PIPE_B:
Line 969... Line 859...
969
			break;
859
			break;
970
		}
860
		}
971
	}
861
	}
Line 972... Line 862...
972
 
862
 
973
	if (type == INTEL_OUTPUT_HDMI) {
-
 
974
		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
-
 
975
 
863
	if (type == INTEL_OUTPUT_HDMI) {
976
	if (intel_hdmi->has_hdmi_sink)
864
		if (intel_crtc->config.has_hdmi_sink)
977
			temp |= TRANS_DDI_MODE_SELECT_HDMI;
865
			temp |= TRANS_DDI_MODE_SELECT_HDMI;
978
	else
866
	else
Line 979... Line 867...
979
			temp |= TRANS_DDI_MODE_SELECT_DVI;
867
			temp |= TRANS_DDI_MODE_SELECT_DVI;
Line 984... Line 872...
984
 
872
 
985
	} else if (type == INTEL_OUTPUT_DISPLAYPORT ||
873
	} else if (type == INTEL_OUTPUT_DISPLAYPORT ||
986
		   type == INTEL_OUTPUT_EDP) {
874
		   type == INTEL_OUTPUT_EDP) {
Line -... Line 875...
-
 
875
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
-
 
876
 
-
 
877
		if (intel_dp->is_mst) {
-
 
878
			temp |= TRANS_DDI_MODE_SELECT_DP_MST;
-
 
879
		} else
-
 
880
			temp |= TRANS_DDI_MODE_SELECT_DP_SST;
-
 
881
 
-
 
882
		temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
-
 
883
	} else if (type == INTEL_OUTPUT_DP_MST) {
-
 
884
		struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp;
-
 
885
 
-
 
886
		if (intel_dp->is_mst) {
987
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
887
			temp |= TRANS_DDI_MODE_SELECT_DP_MST;
Line 988... Line 888...
988
 
888
		} else
989
		temp |= TRANS_DDI_MODE_SELECT_DP_SST;
889
		temp |= TRANS_DDI_MODE_SELECT_DP_SST;
990
 
890
 
Line 1001... Line 901...
1001
				       enum transcoder cpu_transcoder)
901
				       enum transcoder cpu_transcoder)
1002
{
902
{
1003
	uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
903
	uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
1004
	uint32_t val = I915_READ(reg);
904
	uint32_t val = I915_READ(reg);
Line 1005... Line 905...
1005
 
905
 
1006
	val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
906
	val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
1007
	val |= TRANS_DDI_PORT_NONE;
907
	val |= TRANS_DDI_PORT_NONE;
1008
	I915_WRITE(reg, val);
908
	I915_WRITE(reg, val);
Line 1009... Line 909...
1009
}
909
}
Line 1015... Line 915...
1015
	struct intel_encoder *intel_encoder = intel_connector->encoder;
915
	struct intel_encoder *intel_encoder = intel_connector->encoder;
1016
	int type = intel_connector->base.connector_type;
916
	int type = intel_connector->base.connector_type;
1017
	enum port port = intel_ddi_get_encoder_port(intel_encoder);
917
	enum port port = intel_ddi_get_encoder_port(intel_encoder);
1018
	enum pipe pipe = 0;
918
	enum pipe pipe = 0;
1019
	enum transcoder cpu_transcoder;
919
	enum transcoder cpu_transcoder;
-
 
920
	enum intel_display_power_domain power_domain;
1020
	uint32_t tmp;
921
	uint32_t tmp;
Line -... Line 922...
-
 
922
 
-
 
923
	power_domain = intel_display_port_power_domain(intel_encoder);
-
 
924
	if (!intel_display_power_enabled(dev_priv, power_domain))
-
 
925
		return false;
1021
 
926
 
1022
	if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
927
	if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
Line 1023... Line 928...
1023
		return false;
928
		return false;
1024
 
929
 
Line 1035... Line 940...
1035
		return (type == DRM_MODE_CONNECTOR_HDMIA);
940
		return (type == DRM_MODE_CONNECTOR_HDMIA);
Line 1036... Line 941...
1036
 
941
 
1037
	case TRANS_DDI_MODE_SELECT_DP_SST:
942
	case TRANS_DDI_MODE_SELECT_DP_SST:
1038
		if (type == DRM_MODE_CONNECTOR_eDP)
943
		if (type == DRM_MODE_CONNECTOR_eDP)
1039
			return true;
-
 
1040
	case TRANS_DDI_MODE_SELECT_DP_MST:
944
			return true;
-
 
945
		return (type == DRM_MODE_CONNECTOR_DisplayPort);
-
 
946
	case TRANS_DDI_MODE_SELECT_DP_MST:
-
 
947
		/* if the transcoder is in MST state then
-
 
948
		 * connector isn't connected */
Line 1041... Line 949...
1041
		return (type == DRM_MODE_CONNECTOR_DisplayPort);
949
		return false;
1042
 
950
 
Line 1043... Line 951...
1043
	case TRANS_DDI_MODE_SELECT_FDI:
951
	case TRANS_DDI_MODE_SELECT_FDI:
Line 1052... Line 960...
1052
			    enum pipe *pipe)
960
			    enum pipe *pipe)
1053
{
961
{
1054
	struct drm_device *dev = encoder->base.dev;
962
	struct drm_device *dev = encoder->base.dev;
1055
	struct drm_i915_private *dev_priv = dev->dev_private;
963
	struct drm_i915_private *dev_priv = dev->dev_private;
1056
	enum port port = intel_ddi_get_encoder_port(encoder);
964
	enum port port = intel_ddi_get_encoder_port(encoder);
-
 
965
	enum intel_display_power_domain power_domain;
1057
	u32 tmp;
966
	u32 tmp;
1058
	int i;
967
	int i;
Line -... Line 968...
-
 
968
 
-
 
969
	power_domain = intel_display_port_power_domain(encoder);
-
 
970
	if (!intel_display_power_enabled(dev_priv, power_domain))
-
 
971
		return false;
1059
 
972
 
Line 1060... Line 973...
1060
	tmp = I915_READ(DDI_BUF_CTL(port));
973
	tmp = I915_READ(DDI_BUF_CTL(port));
1061
 
974
 
Line 1083... Line 996...
1083
		for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
996
		for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1084
			tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
997
			tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
Line 1085... Line 998...
1085
 
998
 
1086
			if ((tmp & TRANS_DDI_PORT_MASK)
999
			if ((tmp & TRANS_DDI_PORT_MASK)
-
 
1000
			    == TRANS_DDI_SELECT_PORT(port)) {
-
 
1001
				if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST)
-
 
1002
					return false;
1087
			    == TRANS_DDI_SELECT_PORT(port)) {
1003
 
1088
			*pipe = i;
1004
			*pipe = i;
1089
			return true;
1005
			return true;
1090
		}
1006
		}
1091
	}
1007
	}
Line 1094... Line 1010...
1094
	DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
1010
	DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Line 1095... Line 1011...
1095
 
1011
 
1096
	return false;
1012
	return false;
Line 1097... Line -...
1097
}
-
 
1098
 
-
 
1099
static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
-
 
1100
				       enum pipe pipe)
-
 
1101
{
-
 
1102
	uint32_t temp, ret;
-
 
1103
	enum port port = I915_MAX_PORTS;
-
 
1104
	enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
-
 
1105
								      pipe);
-
 
1106
	int i;
-
 
1107
 
-
 
1108
	if (cpu_transcoder == TRANSCODER_EDP) {
-
 
1109
		port = PORT_A;
-
 
1110
	} else {
-
 
1111
		temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
-
 
1112
		temp &= TRANS_DDI_PORT_MASK;
-
 
1113
 
-
 
1114
		for (i = PORT_B; i <= PORT_E; i++)
-
 
1115
			if (temp == TRANS_DDI_SELECT_PORT(i))
-
 
1116
				port = i;
-
 
1117
	}
-
 
1118
 
-
 
1119
	if (port == I915_MAX_PORTS) {
-
 
1120
		WARN(1, "Pipe %c enabled on an unknown port\n",
-
 
1121
		     pipe_name(pipe));
-
 
1122
		ret = PORT_CLK_SEL_NONE;
-
 
1123
	} else {
-
 
1124
	ret = I915_READ(PORT_CLK_SEL(port));
-
 
1125
		DRM_DEBUG_KMS("Pipe %c connected to port %c using clock "
-
 
1126
			      "0x%08x\n", pipe_name(pipe), port_name(port),
-
 
1127
			      ret);
-
 
1128
	}
-
 
1129
 
-
 
1130
	return ret;
-
 
1131
}
-
 
1132
 
-
 
1133
void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
-
 
1134
{
-
 
1135
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
1136
	enum pipe pipe;
-
 
1137
	struct intel_crtc *intel_crtc;
-
 
1138
 
-
 
1139
	dev_priv->ddi_plls.spll_refcount = 0;
-
 
1140
	dev_priv->ddi_plls.wrpll1_refcount = 0;
-
 
1141
	dev_priv->ddi_plls.wrpll2_refcount = 0;
-
 
1142
 
-
 
1143
	for_each_pipe(pipe) {
-
 
1144
		intel_crtc =
-
 
1145
			to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
-
 
1146
 
-
 
1147
		if (!intel_crtc->active) {
-
 
1148
			intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
-
 
1149
			continue;
-
 
1150
		}
-
 
1151
 
-
 
1152
		intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
-
 
1153
								 pipe);
-
 
1154
 
-
 
1155
		switch (intel_crtc->ddi_pll_sel) {
-
 
1156
		case PORT_CLK_SEL_SPLL:
-
 
1157
			dev_priv->ddi_plls.spll_refcount++;
-
 
1158
			break;
-
 
1159
		case PORT_CLK_SEL_WRPLL1:
-
 
1160
			dev_priv->ddi_plls.wrpll1_refcount++;
-
 
1161
			break;
-
 
1162
		case PORT_CLK_SEL_WRPLL2:
-
 
1163
			dev_priv->ddi_plls.wrpll2_refcount++;
-
 
1164
			break;
-
 
1165
		}
-
 
1166
	}
-
 
1167
}
1013
}
1168
 
1014
 
1169
void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1015
void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1170
{
1016
{
1171
	struct drm_crtc *crtc = &intel_crtc->base;
1017
	struct drm_crtc *crtc = &intel_crtc->base;
Line 1190... Line 1036...
1190
}
1036
}
Line 1191... Line 1037...
1191
 
1037
 
1192
static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
1038
static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
1193
{
1039
{
1194
	struct drm_encoder *encoder = &intel_encoder->base;
-
 
1195
	struct drm_crtc *crtc = encoder->crtc;
1040
	struct drm_encoder *encoder = &intel_encoder->base;
1196
	struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1041
	struct drm_i915_private *dev_priv = encoder->dev->dev_private;
1197
	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1042
	struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
1198
	enum port port = intel_ddi_get_encoder_port(intel_encoder);
1043
	enum port port = intel_ddi_get_encoder_port(intel_encoder);
Line -... Line 1044...
-
 
1044
	int type = intel_encoder->type;
-
 
1045
 
-
 
1046
	if (crtc->config.has_audio) {
-
 
1047
		DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n",
-
 
1048
				 pipe_name(crtc->pipe));
-
 
1049
 
-
 
1050
		/* write eld */
-
 
1051
		DRM_DEBUG_DRIVER("DDI audio: write eld information\n");
-
 
1052
		intel_write_eld(encoder, &crtc->config.adjusted_mode);
1199
	int type = intel_encoder->type;
1053
	}
1200
 
1054
 
1201
	if (type == INTEL_OUTPUT_EDP) {
1055
	if (type == INTEL_OUTPUT_EDP) {
1202
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1056
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Line 1203... Line 1057...
1203
		ironlake_edp_panel_on(intel_dp);
1057
		intel_edp_panel_on(intel_dp);
1204
	}
1058
	}
Line 1205... Line 1059...
1205
 
1059
 
1206
	WARN_ON(intel_crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
1060
	WARN_ON(crtc->config.ddi_pll_sel == PORT_CLK_SEL_NONE);
Line -... Line 1061...
-
 
1061
	I915_WRITE(PORT_CLK_SEL(port), crtc->config.ddi_pll_sel);
-
 
1062
 
1207
	I915_WRITE(PORT_CLK_SEL(port), intel_crtc->ddi_pll_sel);
1063
	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
1208
 
1064
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1209
	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
1065
 
1210
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1066
		intel_ddi_init_dp_buf_reg(intel_encoder);
1211
 
1067
 
-
 
1068
		intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
-
 
1069
		intel_dp_start_link_train(intel_dp);
-
 
1070
		intel_dp_complete_link_train(intel_dp);
-
 
1071
		if (port != PORT_A)
-
 
1072
			intel_dp_stop_link_train(intel_dp);
-
 
1073
	} else if (type == INTEL_OUTPUT_HDMI) {
1212
		intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1074
		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1213
		intel_dp_start_link_train(intel_dp);
1075
 
Line 1214... Line 1076...
1214
		intel_dp_complete_link_train(intel_dp);
1076
		intel_hdmi->set_infoframes(encoder,
1215
		if (port != PORT_A)
1077
					   crtc->config.has_hdmi_sink,
Line 1242... Line 1104...
1242
		intel_wait_ddi_buf_idle(dev_priv, port);
1104
		intel_wait_ddi_buf_idle(dev_priv, port);
Line 1243... Line 1105...
1243
 
1105
 
1244
	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
1106
	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
1245
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1107
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
-
 
1108
		intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1246
		intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1109
		intel_edp_panel_vdd_on(intel_dp);
1247
		ironlake_edp_panel_off(intel_dp);
1110
		intel_edp_panel_off(intel_dp);
Line 1248... Line 1111...
1248
	}
1111
	}
1249
 
1112
 
Line 1277... Line 1140...
1277
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1140
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Line 1278... Line 1141...
1278
 
1141
 
1279
		if (port == PORT_A)
1142
		if (port == PORT_A)
Line 1280... Line 1143...
1280
			intel_dp_stop_link_train(intel_dp);
1143
			intel_dp_stop_link_train(intel_dp);
1281
 
1144
 
1282
		ironlake_edp_backlight_on(intel_dp);
1145
		intel_edp_backlight_on(intel_dp);
Line 1283... Line 1146...
1283
		intel_edp_psr_enable(intel_dp);
1146
		intel_edp_psr_enable(intel_dp);
-
 
1147
	}
1284
	}
1148
 
1285
 
1149
	if (intel_crtc->config.has_audio) {
1286
	if (intel_crtc->eld_vld && type != INTEL_OUTPUT_EDP) {
1150
		intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
1287
		tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1151
		tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1288
		tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
1152
		tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
Line 1299... Line 1163...
1299
	int type = intel_encoder->type;
1163
	int type = intel_encoder->type;
1300
	struct drm_device *dev = encoder->dev;
1164
	struct drm_device *dev = encoder->dev;
1301
	struct drm_i915_private *dev_priv = dev->dev_private;
1165
	struct drm_i915_private *dev_priv = dev->dev_private;
1302
	uint32_t tmp;
1166
	uint32_t tmp;
Line -... Line 1167...
-
 
1167
 
-
 
1168
	/* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this
1303
 
1169
	 * register is part of the power well on Haswell. */
1304
	if (intel_crtc->eld_vld && type != INTEL_OUTPUT_EDP) {
1170
	if (intel_crtc->config.has_audio) {
1305
	tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1171
	tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
1306
		tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1172
		tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
1307
			 (pipe * 4));
1173
			 (pipe * 4));
-
 
1174
	I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1308
	I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
1175
		intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
Line 1309... Line 1176...
1309
	}
1176
	}
1310
 
1177
 
Line 1311... Line 1178...
1311
	if (type == INTEL_OUTPUT_EDP) {
1178
	if (type == INTEL_OUTPUT_EDP) {
1312
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1179
		struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1313
 
1180
 
1314
		intel_edp_psr_disable(intel_dp);
1181
		intel_edp_psr_disable(intel_dp);
Line 1315... Line 1182...
1315
		ironlake_edp_backlight_off(intel_dp);
1182
		intel_edp_backlight_off(intel_dp);
1316
	}
1183
	}
Line 1322... Line 1189...
1322
	uint32_t lcpll = I915_READ(LCPLL_CTL);
1189
	uint32_t lcpll = I915_READ(LCPLL_CTL);
1323
	uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
1190
	uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
Line 1324... Line 1191...
1324
 
1191
 
1325
	if (lcpll & LCPLL_CD_SOURCE_FCLK) {
1192
	if (lcpll & LCPLL_CD_SOURCE_FCLK) {
1326
		return 800000;
1193
		return 800000;
1327
	} else if (I915_READ(HSW_FUSE_STRAP) & HSW_CDCLK_LIMIT) {
1194
	} else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) {
1328
		return 450000;
1195
		return 450000;
1329
	} else if (freq == LCPLL_CLK_FREQ_450) {
1196
	} else if (freq == LCPLL_CLK_FREQ_450) {
1330
		return 450000;
1197
		return 450000;
1331
	} else if (IS_HASWELL(dev)) {
1198
	} else if (IS_HASWELL(dev)) {
Line 1341... Line 1208...
1341
		else
1208
		else
1342
			return 675000;
1209
			return 675000;
1343
	}
1210
	}
1344
}
1211
}
Line -... Line 1212...
-
 
1212
 
-
 
1213
static void hsw_ddi_pll_enable(struct drm_i915_private *dev_priv,
-
 
1214
			       struct intel_shared_dpll *pll)
-
 
1215
{
-
 
1216
	I915_WRITE(WRPLL_CTL(pll->id), pll->hw_state.wrpll);
-
 
1217
	POSTING_READ(WRPLL_CTL(pll->id));
-
 
1218
	udelay(20);
-
 
1219
}
-
 
1220
 
-
 
1221
static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv,
-
 
1222
				struct intel_shared_dpll *pll)
-
 
1223
{
-
 
1224
	uint32_t val;
-
 
1225
 
-
 
1226
	val = I915_READ(WRPLL_CTL(pll->id));
-
 
1227
	I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE);
-
 
1228
	POSTING_READ(WRPLL_CTL(pll->id));
-
 
1229
}
-
 
1230
 
-
 
1231
static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
-
 
1232
				     struct intel_shared_dpll *pll,
-
 
1233
				     struct intel_dpll_hw_state *hw_state)
-
 
1234
{
-
 
1235
	uint32_t val;
-
 
1236
 
-
 
1237
	if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
-
 
1238
		return false;
-
 
1239
 
-
 
1240
	val = I915_READ(WRPLL_CTL(pll->id));
-
 
1241
	hw_state->wrpll = val;
-
 
1242
 
-
 
1243
	return val & WRPLL_PLL_ENABLE;
-
 
1244
}
-
 
1245
 
-
 
1246
static const char * const hsw_ddi_pll_names[] = {
-
 
1247
	"WRPLL 1",
-
 
1248
	"WRPLL 2",
-
 
1249
};
1345
 
1250
 
1346
void intel_ddi_pll_init(struct drm_device *dev)
1251
void intel_ddi_pll_init(struct drm_device *dev)
1347
{
1252
{
1348
	struct drm_i915_private *dev_priv = dev->dev_private;
1253
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
1254
	uint32_t val = I915_READ(LCPLL_CTL);
-
 
1255
	int i;
-
 
1256
 
-
 
1257
	dev_priv->num_shared_dpll = 2;
-
 
1258
 
-
 
1259
	for (i = 0; i < dev_priv->num_shared_dpll; i++) {
-
 
1260
		dev_priv->shared_dplls[i].id = i;
-
 
1261
		dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
-
 
1262
		dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable;
-
 
1263
		dev_priv->shared_dplls[i].enable = hsw_ddi_pll_enable;
-
 
1264
		dev_priv->shared_dplls[i].get_hw_state =
-
 
1265
			hsw_ddi_pll_get_hw_state;
Line 1349... Line 1266...
1349
	uint32_t val = I915_READ(LCPLL_CTL);
1266
	}
1350
 
1267
 
1351
	/* The LCPLL register should be turned on by the BIOS. For now let's
1268
	/* The LCPLL register should be turned on by the BIOS. For now let's
1352
	 * just check its state and print errors in case something is wrong.
1269
	 * just check its state and print errors in case something is wrong.
Line 1388... Line 1305...
1388
 
1305
 
1389
		if (wait)
1306
		if (wait)
1390
			intel_wait_ddi_buf_idle(dev_priv, port);
1307
			intel_wait_ddi_buf_idle(dev_priv, port);
Line 1391... Line 1308...
1391
	}
1308
	}
1392
 
1309
 
-
 
1310
	val = DP_TP_CTL_ENABLE |
-
 
1311
	      DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
-
 
1312
	if (intel_dp->is_mst)
-
 
1313
		val |= DP_TP_CTL_MODE_MST;
1393
	val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
1314
	else {
1394
	      DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
1315
		val |= DP_TP_CTL_MODE_SST;
-
 
1316
	if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1395
	if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1317
		val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1396
		val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
1318
	}
Line 1397... Line 1319...
1397
	I915_WRITE(DP_TP_CTL(port), val);
1319
	I915_WRITE(DP_TP_CTL(port), val);
1398
	POSTING_READ(DP_TP_CTL(port));
1320
	POSTING_READ(DP_TP_CTL(port));
Line 1430... Line 1352...
1430
	I915_WRITE(_FDI_RXA_CTL, val);
1352
	I915_WRITE(_FDI_RXA_CTL, val);
1431
}
1353
}
Line 1432... Line 1354...
1432
 
1354
 
1433
static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1355
static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1434
{
1356
{
1435
	struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
1357
	struct intel_digital_port *intel_dig_port = enc_to_dig_port(&intel_encoder->base);
-
 
1358
	int type = intel_dig_port->base.type;
-
 
1359
 
-
 
1360
	if (type != INTEL_OUTPUT_DISPLAYPORT &&
-
 
1361
	    type != INTEL_OUTPUT_EDP &&
-
 
1362
	    type != INTEL_OUTPUT_UNKNOWN) {
-
 
1363
		return;
Line 1436... Line -...
1436
	int type = intel_encoder->type;
-
 
1437
 
1364
	}
1438
	if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP)
1365
 
Line 1439... Line 1366...
1439
		intel_dp_check_link_status(intel_dp);
1366
	intel_dp_hot_plug(intel_encoder);
1440
}
1367
}
1441
 
1368
 
Line 1476... Line 1403...
1476
		break;
1403
		break;
1477
	}
1404
	}
Line 1478... Line 1405...
1478
 
1405
 
1479
	switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
1406
	switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
-
 
1407
	case TRANS_DDI_MODE_SELECT_HDMI:
1480
	case TRANS_DDI_MODE_SELECT_HDMI:
1408
		pipe_config->has_hdmi_sink = true;
1481
	case TRANS_DDI_MODE_SELECT_DVI:
1409
	case TRANS_DDI_MODE_SELECT_DVI:
1482
	case TRANS_DDI_MODE_SELECT_FDI:
1410
	case TRANS_DDI_MODE_SELECT_FDI:
1483
		break;
1411
		break;
1484
	case TRANS_DDI_MODE_SELECT_DP_SST:
1412
	case TRANS_DDI_MODE_SELECT_DP_SST:
Line 1488... Line 1416...
1488
		break;
1416
		break;
1489
	default:
1417
	default:
1490
		break;
1418
		break;
1491
	}
1419
	}
Line -... Line 1420...
-
 
1420
 
-
 
1421
	if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
-
 
1422
		temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
-
 
1423
		if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4)))
-
 
1424
			pipe_config->has_audio = true;
-
 
1425
	}
1492
 
1426
 
1493
	if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1427
	if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
1494
	    pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1428
	    pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1495
		/*
1429
		/*
1496
		 * This is a big fat ugly hack.
1430
		 * This is a big fat ugly hack.
Line 1507... Line 1441...
1507
		 */
1441
		 */
1508
		DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1442
		DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1509
			      pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1443
			      pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1510
		dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1444
		dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1511
	}
1445
	}
-
 
1446
 
-
 
1447
	intel_ddi_clock_get(encoder, pipe_config);
1512
}
1448
}
Line 1513... Line 1449...
1513
 
1449
 
1514
static void intel_ddi_destroy(struct drm_encoder *encoder)
1450
static void intel_ddi_destroy(struct drm_encoder *encoder)
1515
{
1451
{
Line 1577... Line 1513...
1577
{
1513
{
1578
	struct drm_i915_private *dev_priv = dev->dev_private;
1514
	struct drm_i915_private *dev_priv = dev->dev_private;
1579
	struct intel_digital_port *intel_dig_port;
1515
	struct intel_digital_port *intel_dig_port;
1580
	struct intel_encoder *intel_encoder;
1516
	struct intel_encoder *intel_encoder;
1581
	struct drm_encoder *encoder;
1517
	struct drm_encoder *encoder;
1582
	struct intel_connector *hdmi_connector = NULL;
-
 
1583
	struct intel_connector *dp_connector = NULL;
-
 
1584
	bool init_hdmi, init_dp;
1518
	bool init_hdmi, init_dp;
Line 1585... Line 1519...
1585
 
1519
 
1586
	init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1520
	init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
1587
		     dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1521
		     dev_priv->vbt.ddi_port_info[port].supports_hdmi);
1588
	init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1522
	init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
1589
	if (!init_dp && !init_hdmi) {
1523
	if (!init_dp && !init_hdmi) {
1590
		DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible\n",
1524
		DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, assuming it is\n",
1591
			      port_name(port));
1525
			      port_name(port));
1592
		init_hdmi = true;
1526
		init_hdmi = true;
1593
		init_dp = true;
1527
		init_dp = true;
Line 1602... Line 1536...
1602
 
1536
 
1603
	drm_encoder_init(dev, encoder, &intel_ddi_funcs,
1537
	drm_encoder_init(dev, encoder, &intel_ddi_funcs,
Line 1604... Line 1538...
1604
			 DRM_MODE_ENCODER_TMDS);
1538
			 DRM_MODE_ENCODER_TMDS);
1605
 
-
 
1606
	intel_encoder->compute_config = intel_ddi_compute_config;
1539
 
1607
	intel_encoder->mode_set = intel_ddi_mode_set;
1540
	intel_encoder->compute_config = intel_ddi_compute_config;
1608
	intel_encoder->enable = intel_enable_ddi;
1541
	intel_encoder->enable = intel_enable_ddi;
1609
	intel_encoder->pre_enable = intel_ddi_pre_enable;
1542
	intel_encoder->pre_enable = intel_ddi_pre_enable;
1610
	intel_encoder->disable = intel_disable_ddi;
1543
	intel_encoder->disable = intel_disable_ddi;
Line 1617... Line 1550...
1617
					  (DDI_BUF_PORT_REVERSAL |
1550
					  (DDI_BUF_PORT_REVERSAL |
1618
					   DDI_A_4_LANES);
1551
					   DDI_A_4_LANES);
Line 1619... Line 1552...
1619
 
1552
 
1620
	intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
1553
	intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
1621
	intel_encoder->crtc_mask =  (1 << 0) | (1 << 1) | (1 << 2);
1554
	intel_encoder->crtc_mask =  (1 << 0) | (1 << 1) | (1 << 2);
1622
	intel_encoder->cloneable = false;
1555
	intel_encoder->cloneable = 0;
Line 1623... Line 1556...
1623
	intel_encoder->hot_plug = intel_ddi_hot_plug;
1556
	intel_encoder->hot_plug = intel_ddi_hot_plug;
1624
 
1557
 
-
 
1558
	if (init_dp) {
-
 
1559
		if (!intel_ddi_init_dp_connector(intel_dig_port))
-
 
1560
			goto err;
-
 
1561
 
-
 
1562
		intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
Line 1625... Line 1563...
1625
	if (init_dp)
1563
		dev_priv->hpd_irq_port[port] = intel_dig_port;
1626
		dp_connector = intel_ddi_init_dp_connector(intel_dig_port);
1564
	}
1627
 
1565
 
1628
	/* In theory we don't need the encoder->type check, but leave it just in
1566
	/* In theory we don't need the encoder->type check, but leave it just in
-
 
1567
	 * case we have some really bad VBTs... */
-
 
1568
	if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
Line 1629... Line 1569...
1629
	 * case we have some really bad VBTs... */
1569
		if (!intel_ddi_init_hdmi_connector(intel_dig_port))
-
 
1570
			goto err;
-
 
1571
	}
1630
	if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi)
1572
 
1631
		hdmi_connector = intel_ddi_init_hdmi_connector(intel_dig_port);
1573
	return;
1632
 
1574
 
1633
	if (!dp_connector && !hdmi_connector) {
-