aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i915/intel_dp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/i915/intel_dp.c')
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c513
1 files changed, 327 insertions, 186 deletions
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 152d94507b79..891f4f1d63b1 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -42,15 +42,13 @@
42 42
43#define DP_LINK_CONFIGURATION_SIZE 9 43#define DP_LINK_CONFIGURATION_SIZE 9
44 44
45#define IS_eDP(i) ((i)->base.type == INTEL_OUTPUT_EDP)
46#define IS_PCH_eDP(i) ((i)->is_pch_edp)
47
48struct intel_dp { 45struct intel_dp {
49 struct intel_encoder base; 46 struct intel_encoder base;
50 uint32_t output_reg; 47 uint32_t output_reg;
51 uint32_t DP; 48 uint32_t DP;
52 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]; 49 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE];
53 bool has_audio; 50 bool has_audio;
51 int force_audio;
54 int dpms_mode; 52 int dpms_mode;
55 uint8_t link_bw; 53 uint8_t link_bw;
56 uint8_t lane_count; 54 uint8_t lane_count;
@@ -60,8 +58,35 @@ struct intel_dp {
60 bool is_pch_edp; 58 bool is_pch_edp;
61 uint8_t train_set[4]; 59 uint8_t train_set[4];
62 uint8_t link_status[DP_LINK_STATUS_SIZE]; 60 uint8_t link_status[DP_LINK_STATUS_SIZE];
61
62 struct drm_property *force_audio_property;
63}; 63};
64 64
65/**
66 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
67 * @intel_dp: DP struct
68 *
69 * If a CPU or PCH DP output is attached to an eDP panel, this function
70 * will return true, and false otherwise.
71 */
72static bool is_edp(struct intel_dp *intel_dp)
73{
74 return intel_dp->base.type == INTEL_OUTPUT_EDP;
75}
76
77/**
78 * is_pch_edp - is the port on the PCH and attached to an eDP panel?
79 * @intel_dp: DP struct
80 *
81 * Returns true if the given DP struct corresponds to a PCH DP port attached
82 * to an eDP panel, false otherwise. Helpful for determining whether we
83 * may need FDI resources for a given DP output or not.
84 */
85static bool is_pch_edp(struct intel_dp *intel_dp)
86{
87 return intel_dp->is_pch_edp;
88}
89
65static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder) 90static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
66{ 91{
67 return container_of(encoder, struct intel_dp, base.base); 92 return container_of(encoder, struct intel_dp, base.base);
@@ -73,6 +98,25 @@ static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
73 struct intel_dp, base); 98 struct intel_dp, base);
74} 99}
75 100
101/**
102 * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
103 * @encoder: DRM encoder
104 *
105 * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
106 * by intel_display.c.
107 */
108bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
109{
110 struct intel_dp *intel_dp;
111
112 if (!encoder)
113 return false;
114
115 intel_dp = enc_to_intel_dp(encoder);
116
117 return is_pch_edp(intel_dp);
118}
119
76static void intel_dp_start_link_train(struct intel_dp *intel_dp); 120static void intel_dp_start_link_train(struct intel_dp *intel_dp);
77static void intel_dp_complete_link_train(struct intel_dp *intel_dp); 121static void intel_dp_complete_link_train(struct intel_dp *intel_dp);
78static void intel_dp_link_down(struct intel_dp *intel_dp); 122static void intel_dp_link_down(struct intel_dp *intel_dp);
@@ -138,7 +182,7 @@ intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pi
138{ 182{
139 struct drm_i915_private *dev_priv = dev->dev_private; 183 struct drm_i915_private *dev_priv = dev->dev_private;
140 184
141 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) 185 if (is_edp(intel_dp))
142 return (pixel_clock * dev_priv->edp.bpp + 7) / 8; 186 return (pixel_clock * dev_priv->edp.bpp + 7) / 8;
143 else 187 else
144 return pixel_clock * 3; 188 return pixel_clock * 3;
@@ -160,8 +204,7 @@ intel_dp_mode_valid(struct drm_connector *connector,
160 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp)); 204 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
161 int max_lanes = intel_dp_max_lane_count(intel_dp); 205 int max_lanes = intel_dp_max_lane_count(intel_dp);
162 206
163 if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) && 207 if (is_edp(intel_dp) && dev_priv->panel_fixed_mode) {
164 dev_priv->panel_fixed_mode) {
165 if (mode->hdisplay > dev_priv->panel_fixed_mode->hdisplay) 208 if (mode->hdisplay > dev_priv->panel_fixed_mode->hdisplay)
166 return MODE_PANEL; 209 return MODE_PANEL;
167 210
@@ -171,7 +214,7 @@ intel_dp_mode_valid(struct drm_connector *connector,
171 214
172 /* only refuse the mode on non eDP since we have seen some wierd eDP panels 215 /* only refuse the mode on non eDP since we have seen some wierd eDP panels
173 which are outside spec tolerances but somehow work by magic */ 216 which are outside spec tolerances but somehow work by magic */
174 if (!IS_eDP(intel_dp) && 217 if (!is_edp(intel_dp) &&
175 (intel_dp_link_required(connector->dev, intel_dp, mode->clock) 218 (intel_dp_link_required(connector->dev, intel_dp, mode->clock)
176 > intel_dp_max_data_rate(max_link_clock, max_lanes))) 219 > intel_dp_max_data_rate(max_link_clock, max_lanes)))
177 return MODE_CLOCK_HIGH; 220 return MODE_CLOCK_HIGH;
@@ -258,7 +301,7 @@ intel_dp_aux_ch(struct intel_dp *intel_dp,
258 * Note that PCH attached eDP panels should use a 125MHz input 301 * Note that PCH attached eDP panels should use a 125MHz input
259 * clock divider. 302 * clock divider.
260 */ 303 */
261 if (IS_eDP(intel_dp) && !IS_PCH_eDP(intel_dp)) { 304 if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
262 if (IS_GEN6(dev)) 305 if (IS_GEN6(dev))
263 aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */ 306 aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */
264 else 307 else
@@ -530,8 +573,7 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
530 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0; 573 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
531 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 }; 574 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
532 575
533 if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) && 576 if (is_edp(intel_dp) && dev_priv->panel_fixed_mode) {
534 dev_priv->panel_fixed_mode) {
535 intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode); 577 intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode);
536 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN, 578 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
537 mode, adjusted_mode); 579 mode, adjusted_mode);
@@ -542,6 +584,17 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
542 mode->clock = dev_priv->panel_fixed_mode->clock; 584 mode->clock = dev_priv->panel_fixed_mode->clock;
543 } 585 }
544 586
587 /* Just use VBT values for eDP */
588 if (is_edp(intel_dp)) {
589 intel_dp->lane_count = dev_priv->edp.lanes;
590 intel_dp->link_bw = dev_priv->edp.rate;
591 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
592 DRM_DEBUG_KMS("eDP link bw %02x lane count %d clock %d\n",
593 intel_dp->link_bw, intel_dp->lane_count,
594 adjusted_mode->clock);
595 return true;
596 }
597
545 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { 598 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
546 for (clock = 0; clock <= max_clock; clock++) { 599 for (clock = 0; clock <= max_clock; clock++) {
547 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count); 600 int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
@@ -560,19 +613,6 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
560 } 613 }
561 } 614 }
562 615
563 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) {
564 /* okay we failed just pick the highest */
565 intel_dp->lane_count = max_lane_count;
566 intel_dp->link_bw = bws[max_clock];
567 adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
568 DRM_DEBUG_KMS("Force picking display port link bw %02x lane "
569 "count %d clock %d\n",
570 intel_dp->link_bw, intel_dp->lane_count,
571 adjusted_mode->clock);
572
573 return true;
574 }
575
576 return false; 616 return false;
577} 617}
578 618
@@ -609,25 +649,6 @@ intel_dp_compute_m_n(int bpp,
609 intel_reduce_ratio(&m_n->link_m, &m_n->link_n); 649 intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
610} 650}
611 651
612bool intel_pch_has_edp(struct drm_crtc *crtc)
613{
614 struct drm_device *dev = crtc->dev;
615 struct drm_mode_config *mode_config = &dev->mode_config;
616 struct drm_encoder *encoder;
617
618 list_for_each_entry(encoder, &mode_config->encoder_list, head) {
619 struct intel_dp *intel_dp;
620
621 if (encoder->crtc != crtc)
622 continue;
623
624 intel_dp = enc_to_intel_dp(encoder);
625 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT)
626 return intel_dp->is_pch_edp;
627 }
628 return false;
629}
630
631void 652void
632intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode, 653intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
633 struct drm_display_mode *adjusted_mode) 654 struct drm_display_mode *adjusted_mode)
@@ -652,8 +673,10 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
652 intel_dp = enc_to_intel_dp(encoder); 673 intel_dp = enc_to_intel_dp(encoder);
653 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) { 674 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) {
654 lane_count = intel_dp->lane_count; 675 lane_count = intel_dp->lane_count;
655 if (IS_PCH_eDP(intel_dp)) 676 break;
656 bpp = dev_priv->edp.bpp; 677 } else if (is_edp(intel_dp)) {
678 lane_count = dev_priv->edp.lanes;
679 bpp = dev_priv->edp.bpp;
657 break; 680 break;
658 } 681 }
659 } 682 }
@@ -720,7 +743,7 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
720 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) 743 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
721 intel_dp->DP |= DP_SYNC_VS_HIGH; 744 intel_dp->DP |= DP_SYNC_VS_HIGH;
722 745
723 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) 746 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
724 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; 747 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
725 else 748 else
726 intel_dp->DP |= DP_LINK_TRAIN_OFF; 749 intel_dp->DP |= DP_LINK_TRAIN_OFF;
@@ -755,7 +778,7 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
755 if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev)) 778 if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev))
756 intel_dp->DP |= DP_PIPEB_SELECT; 779 intel_dp->DP |= DP_PIPEB_SELECT;
757 780
758 if (IS_eDP(intel_dp)) { 781 if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
759 /* don't miss out required setting for eDP */ 782 /* don't miss out required setting for eDP */
760 intel_dp->DP |= DP_PLL_ENABLE; 783 intel_dp->DP |= DP_PLL_ENABLE;
761 if (adjusted_mode->clock < 200000) 784 if (adjusted_mode->clock < 200000)
@@ -766,10 +789,11 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
766} 789}
767 790
768/* Returns true if the panel was already on when called */ 791/* Returns true if the panel was already on when called */
769static bool ironlake_edp_panel_on (struct drm_device *dev) 792static bool ironlake_edp_panel_on (struct intel_dp *intel_dp)
770{ 793{
794 struct drm_device *dev = intel_dp->base.base.dev;
771 struct drm_i915_private *dev_priv = dev->dev_private; 795 struct drm_i915_private *dev_priv = dev->dev_private;
772 u32 pp; 796 u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE;
773 797
774 if (I915_READ(PCH_PP_STATUS) & PP_ON) 798 if (I915_READ(PCH_PP_STATUS) & PP_ON)
775 return true; 799 return true;
@@ -781,19 +805,20 @@ static bool ironlake_edp_panel_on (struct drm_device *dev)
781 I915_WRITE(PCH_PP_CONTROL, pp); 805 I915_WRITE(PCH_PP_CONTROL, pp);
782 POSTING_READ(PCH_PP_CONTROL); 806 POSTING_READ(PCH_PP_CONTROL);
783 807
784 pp |= POWER_TARGET_ON; 808 pp |= PANEL_UNLOCK_REGS | POWER_TARGET_ON;
785 I915_WRITE(PCH_PP_CONTROL, pp); 809 I915_WRITE(PCH_PP_CONTROL, pp);
810 POSTING_READ(PCH_PP_CONTROL);
786 811
787 /* Ouch. We need to wait here for some panels, like Dell e6510 812 /* Ouch. We need to wait here for some panels, like Dell e6510
788 * https://bugs.freedesktop.org/show_bug.cgi?id=29278i 813 * https://bugs.freedesktop.org/show_bug.cgi?id=29278i
789 */ 814 */
790 msleep(300); 815 msleep(300);
791 816
792 if (wait_for(I915_READ(PCH_PP_STATUS) & PP_ON, 5000)) 817 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_on_mask) == idle_on_mask,
818 5000))
793 DRM_ERROR("panel on wait timed out: 0x%08x\n", 819 DRM_ERROR("panel on wait timed out: 0x%08x\n",
794 I915_READ(PCH_PP_STATUS)); 820 I915_READ(PCH_PP_STATUS));
795 821
796 pp &= ~(PANEL_UNLOCK_REGS);
797 pp |= PANEL_POWER_RESET; /* restore panel reset bit */ 822 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
798 I915_WRITE(PCH_PP_CONTROL, pp); 823 I915_WRITE(PCH_PP_CONTROL, pp);
799 POSTING_READ(PCH_PP_CONTROL); 824 POSTING_READ(PCH_PP_CONTROL);
@@ -804,7 +829,8 @@ static bool ironlake_edp_panel_on (struct drm_device *dev)
804static void ironlake_edp_panel_off (struct drm_device *dev) 829static void ironlake_edp_panel_off (struct drm_device *dev)
805{ 830{
806 struct drm_i915_private *dev_priv = dev->dev_private; 831 struct drm_i915_private *dev_priv = dev->dev_private;
807 u32 pp; 832 u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK |
833 PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK;
808 834
809 pp = I915_READ(PCH_PP_CONTROL); 835 pp = I915_READ(PCH_PP_CONTROL);
810 836
@@ -815,12 +841,12 @@ static void ironlake_edp_panel_off (struct drm_device *dev)
815 841
816 pp &= ~POWER_TARGET_ON; 842 pp &= ~POWER_TARGET_ON;
817 I915_WRITE(PCH_PP_CONTROL, pp); 843 I915_WRITE(PCH_PP_CONTROL, pp);
844 POSTING_READ(PCH_PP_CONTROL);
818 845
819 if (wait_for((I915_READ(PCH_PP_STATUS) & PP_ON) == 0, 5000)) 846 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000))
820 DRM_ERROR("panel off wait timed out: 0x%08x\n", 847 DRM_ERROR("panel off wait timed out: 0x%08x\n",
821 I915_READ(PCH_PP_STATUS)); 848 I915_READ(PCH_PP_STATUS));
822 849
823 /* Make sure VDD is enabled so DP AUX will work */
824 pp |= PANEL_POWER_RESET; /* restore panel reset bit */ 850 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
825 I915_WRITE(PCH_PP_CONTROL, pp); 851 I915_WRITE(PCH_PP_CONTROL, pp);
826 POSTING_READ(PCH_PP_CONTROL); 852 POSTING_READ(PCH_PP_CONTROL);
@@ -831,36 +857,19 @@ static void ironlake_edp_panel_off (struct drm_device *dev)
831 msleep(300); 857 msleep(300);
832} 858}
833 859
834static void ironlake_edp_panel_vdd_on(struct drm_device *dev)
835{
836 struct drm_i915_private *dev_priv = dev->dev_private;
837 u32 pp;
838
839 pp = I915_READ(PCH_PP_CONTROL);
840 pp |= EDP_FORCE_VDD;
841 I915_WRITE(PCH_PP_CONTROL, pp);
842 POSTING_READ(PCH_PP_CONTROL);
843 msleep(300);
844}
845
846static void ironlake_edp_panel_vdd_off(struct drm_device *dev)
847{
848 struct drm_i915_private *dev_priv = dev->dev_private;
849 u32 pp;
850
851 pp = I915_READ(PCH_PP_CONTROL);
852 pp &= ~EDP_FORCE_VDD;
853 I915_WRITE(PCH_PP_CONTROL, pp);
854 POSTING_READ(PCH_PP_CONTROL);
855 msleep(300);
856}
857
858static void ironlake_edp_backlight_on (struct drm_device *dev) 860static void ironlake_edp_backlight_on (struct drm_device *dev)
859{ 861{
860 struct drm_i915_private *dev_priv = dev->dev_private; 862 struct drm_i915_private *dev_priv = dev->dev_private;
861 u32 pp; 863 u32 pp;
862 864
863 DRM_DEBUG_KMS("\n"); 865 DRM_DEBUG_KMS("\n");
866 /*
867 * If we enable the backlight right away following a panel power
868 * on, we may see slight flicker as the panel syncs with the eDP
869 * link. So delay a bit to make sure the image is solid before
870 * allowing it to appear.
871 */
872 msleep(300);
864 pp = I915_READ(PCH_PP_CONTROL); 873 pp = I915_READ(PCH_PP_CONTROL);
865 pp |= EDP_BLC_ENABLE; 874 pp |= EDP_BLC_ENABLE;
866 I915_WRITE(PCH_PP_CONTROL, pp); 875 I915_WRITE(PCH_PP_CONTROL, pp);
@@ -885,8 +894,10 @@ static void ironlake_edp_pll_on(struct drm_encoder *encoder)
885 894
886 DRM_DEBUG_KMS("\n"); 895 DRM_DEBUG_KMS("\n");
887 dpa_ctl = I915_READ(DP_A); 896 dpa_ctl = I915_READ(DP_A);
888 dpa_ctl &= ~DP_PLL_ENABLE; 897 dpa_ctl |= DP_PLL_ENABLE;
889 I915_WRITE(DP_A, dpa_ctl); 898 I915_WRITE(DP_A, dpa_ctl);
899 POSTING_READ(DP_A);
900 udelay(200);
890} 901}
891 902
892static void ironlake_edp_pll_off(struct drm_encoder *encoder) 903static void ironlake_edp_pll_off(struct drm_encoder *encoder)
@@ -896,7 +907,7 @@ static void ironlake_edp_pll_off(struct drm_encoder *encoder)
896 u32 dpa_ctl; 907 u32 dpa_ctl;
897 908
898 dpa_ctl = I915_READ(DP_A); 909 dpa_ctl = I915_READ(DP_A);
899 dpa_ctl |= DP_PLL_ENABLE; 910 dpa_ctl &= ~DP_PLL_ENABLE;
900 I915_WRITE(DP_A, dpa_ctl); 911 I915_WRITE(DP_A, dpa_ctl);
901 POSTING_READ(DP_A); 912 POSTING_READ(DP_A);
902 udelay(200); 913 udelay(200);
@@ -906,17 +917,16 @@ static void intel_dp_prepare(struct drm_encoder *encoder)
906{ 917{
907 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 918 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
908 struct drm_device *dev = encoder->dev; 919 struct drm_device *dev = encoder->dev;
909 struct drm_i915_private *dev_priv = dev->dev_private;
910 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
911 920
912 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) { 921 if (is_edp(intel_dp)) {
913 ironlake_edp_panel_off(dev);
914 ironlake_edp_backlight_off(dev); 922 ironlake_edp_backlight_off(dev);
915 ironlake_edp_panel_vdd_on(dev); 923 ironlake_edp_panel_on(intel_dp);
916 ironlake_edp_pll_on(encoder); 924 if (!is_pch_edp(intel_dp))
925 ironlake_edp_pll_on(encoder);
926 else
927 ironlake_edp_pll_off(encoder);
917 } 928 }
918 if (dp_reg & DP_PORT_EN) 929 intel_dp_link_down(intel_dp);
919 intel_dp_link_down(intel_dp);
920} 930}
921 931
922static void intel_dp_commit(struct drm_encoder *encoder) 932static void intel_dp_commit(struct drm_encoder *encoder)
@@ -926,14 +936,13 @@ static void intel_dp_commit(struct drm_encoder *encoder)
926 936
927 intel_dp_start_link_train(intel_dp); 937 intel_dp_start_link_train(intel_dp);
928 938
929 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) 939 if (is_edp(intel_dp))
930 ironlake_edp_panel_on(dev); 940 ironlake_edp_panel_on(intel_dp);
931 941
932 intel_dp_complete_link_train(intel_dp); 942 intel_dp_complete_link_train(intel_dp);
933 943
934 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) 944 if (is_edp(intel_dp))
935 ironlake_edp_backlight_on(dev); 945 ironlake_edp_backlight_on(dev);
936 intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
937} 946}
938 947
939static void 948static void
@@ -945,23 +954,22 @@ intel_dp_dpms(struct drm_encoder *encoder, int mode)
945 uint32_t dp_reg = I915_READ(intel_dp->output_reg); 954 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
946 955
947 if (mode != DRM_MODE_DPMS_ON) { 956 if (mode != DRM_MODE_DPMS_ON) {
948 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) { 957 if (is_edp(intel_dp))
949 ironlake_edp_backlight_off(dev); 958 ironlake_edp_backlight_off(dev);
959 intel_dp_link_down(intel_dp);
960 if (is_edp(intel_dp))
950 ironlake_edp_panel_off(dev); 961 ironlake_edp_panel_off(dev);
951 } 962 if (is_edp(intel_dp) && !is_pch_edp(intel_dp))
952 if (dp_reg & DP_PORT_EN)
953 intel_dp_link_down(intel_dp);
954 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp))
955 ironlake_edp_pll_off(encoder); 963 ironlake_edp_pll_off(encoder);
956 } else { 964 } else {
965 if (is_edp(intel_dp))
966 ironlake_edp_panel_on(intel_dp);
957 if (!(dp_reg & DP_PORT_EN)) { 967 if (!(dp_reg & DP_PORT_EN)) {
958 intel_dp_start_link_train(intel_dp); 968 intel_dp_start_link_train(intel_dp);
959 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp))
960 ironlake_edp_panel_on(dev);
961 intel_dp_complete_link_train(intel_dp); 969 intel_dp_complete_link_train(intel_dp);
962 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp))
963 ironlake_edp_backlight_on(dev);
964 } 970 }
971 if (is_edp(intel_dp))
972 ironlake_edp_backlight_on(dev);
965 } 973 }
966 intel_dp->dpms_mode = mode; 974 intel_dp->dpms_mode = mode;
967} 975}
@@ -1079,11 +1087,21 @@ intel_get_adjust_train(struct intel_dp *intel_dp)
1079} 1087}
1080 1088
1081static uint32_t 1089static uint32_t
1082intel_dp_signal_levels(uint8_t train_set, int lane_count) 1090intel_dp_signal_levels(struct intel_dp *intel_dp)
1083{ 1091{
1084 uint32_t signal_levels = 0; 1092 struct drm_device *dev = intel_dp->base.base.dev;
1093 struct drm_i915_private *dev_priv = dev->dev_private;
1094 uint32_t signal_levels = 0;
1095 u8 train_set = intel_dp->train_set[0];
1096 u32 vswing = train_set & DP_TRAIN_VOLTAGE_SWING_MASK;
1097 u32 preemphasis = train_set & DP_TRAIN_PRE_EMPHASIS_MASK;
1098
1099 if (is_edp(intel_dp)) {
1100 vswing = dev_priv->edp.vswing;
1101 preemphasis = dev_priv->edp.preemphasis;
1102 }
1085 1103
1086 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 1104 switch (vswing) {
1087 case DP_TRAIN_VOLTAGE_SWING_400: 1105 case DP_TRAIN_VOLTAGE_SWING_400:
1088 default: 1106 default:
1089 signal_levels |= DP_VOLTAGE_0_4; 1107 signal_levels |= DP_VOLTAGE_0_4;
@@ -1098,7 +1116,7 @@ intel_dp_signal_levels(uint8_t train_set, int lane_count)
1098 signal_levels |= DP_VOLTAGE_1_2; 1116 signal_levels |= DP_VOLTAGE_1_2;
1099 break; 1117 break;
1100 } 1118 }
1101 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { 1119 switch (preemphasis) {
1102 case DP_TRAIN_PRE_EMPHASIS_0: 1120 case DP_TRAIN_PRE_EMPHASIS_0:
1103 default: 1121 default:
1104 signal_levels |= DP_PRE_EMPHASIS_0; 1122 signal_levels |= DP_PRE_EMPHASIS_0;
@@ -1185,6 +1203,18 @@ intel_channel_eq_ok(struct intel_dp *intel_dp)
1185} 1203}
1186 1204
1187static bool 1205static bool
1206intel_dp_aux_handshake_required(struct intel_dp *intel_dp)
1207{
1208 struct drm_device *dev = intel_dp->base.base.dev;
1209 struct drm_i915_private *dev_priv = dev->dev_private;
1210
1211 if (is_edp(intel_dp) && dev_priv->no_aux_handshake)
1212 return false;
1213
1214 return true;
1215}
1216
1217static bool
1188intel_dp_set_link_train(struct intel_dp *intel_dp, 1218intel_dp_set_link_train(struct intel_dp *intel_dp,
1189 uint32_t dp_reg_value, 1219 uint32_t dp_reg_value,
1190 uint8_t dp_train_pat) 1220 uint8_t dp_train_pat)
@@ -1196,6 +1226,9 @@ intel_dp_set_link_train(struct intel_dp *intel_dp,
1196 I915_WRITE(intel_dp->output_reg, dp_reg_value); 1226 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1197 POSTING_READ(intel_dp->output_reg); 1227 POSTING_READ(intel_dp->output_reg);
1198 1228
1229 if (!intel_dp_aux_handshake_required(intel_dp))
1230 return true;
1231
1199 intel_dp_aux_native_write_1(intel_dp, 1232 intel_dp_aux_native_write_1(intel_dp,
1200 DP_TRAINING_PATTERN_SET, 1233 DP_TRAINING_PATTERN_SET,
1201 dp_train_pat); 1234 dp_train_pat);
@@ -1228,13 +1261,14 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1228 POSTING_READ(intel_dp->output_reg); 1261 POSTING_READ(intel_dp->output_reg);
1229 intel_wait_for_vblank(dev, intel_crtc->pipe); 1262 intel_wait_for_vblank(dev, intel_crtc->pipe);
1230 1263
1231 /* Write the link configuration data */ 1264 if (intel_dp_aux_handshake_required(intel_dp))
1232 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET, 1265 /* Write the link configuration data */
1233 intel_dp->link_configuration, 1266 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1234 DP_LINK_CONFIGURATION_SIZE); 1267 intel_dp->link_configuration,
1268 DP_LINK_CONFIGURATION_SIZE);
1235 1269
1236 DP |= DP_PORT_EN; 1270 DP |= DP_PORT_EN;
1237 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) 1271 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
1238 DP &= ~DP_LINK_TRAIN_MASK_CPT; 1272 DP &= ~DP_LINK_TRAIN_MASK_CPT;
1239 else 1273 else
1240 DP &= ~DP_LINK_TRAIN_MASK; 1274 DP &= ~DP_LINK_TRAIN_MASK;
@@ -1245,15 +1279,15 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1245 for (;;) { 1279 for (;;) {
1246 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */ 1280 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
1247 uint32_t signal_levels; 1281 uint32_t signal_levels;
1248 if (IS_GEN6(dev) && IS_eDP(intel_dp)) { 1282 if (IS_GEN6(dev) && is_edp(intel_dp)) {
1249 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]); 1283 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
1250 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; 1284 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1251 } else { 1285 } else {
1252 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count); 1286 signal_levels = intel_dp_signal_levels(intel_dp);
1253 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; 1287 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1254 } 1288 }
1255 1289
1256 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) 1290 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
1257 reg = DP | DP_LINK_TRAIN_PAT_1_CPT; 1291 reg = DP | DP_LINK_TRAIN_PAT_1_CPT;
1258 else 1292 else
1259 reg = DP | DP_LINK_TRAIN_PAT_1; 1293 reg = DP | DP_LINK_TRAIN_PAT_1;
@@ -1263,33 +1297,37 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1263 break; 1297 break;
1264 /* Set training pattern 1 */ 1298 /* Set training pattern 1 */
1265 1299
1266 udelay(100); 1300 udelay(500);
1267 if (!intel_dp_get_link_status(intel_dp)) 1301 if (intel_dp_aux_handshake_required(intel_dp)) {
1268 break;
1269
1270 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1271 clock_recovery = true;
1272 break; 1302 break;
1273 } 1303 } else {
1304 if (!intel_dp_get_link_status(intel_dp))
1305 break;
1274 1306
1275 /* Check to see if we've tried the max voltage */ 1307 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
1276 for (i = 0; i < intel_dp->lane_count; i++) 1308 clock_recovery = true;
1277 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1278 break; 1309 break;
1279 if (i == intel_dp->lane_count) 1310 }
1280 break;
1281 1311
1282 /* Check to see if we've tried the same voltage 5 times */ 1312 /* Check to see if we've tried the max voltage */
1283 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) { 1313 for (i = 0; i < intel_dp->lane_count; i++)
1284 ++tries; 1314 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1285 if (tries == 5) 1315 break;
1316 if (i == intel_dp->lane_count)
1286 break; 1317 break;
1287 } else
1288 tries = 0;
1289 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1290 1318
1291 /* Compute new intel_dp->train_set as requested by target */ 1319 /* Check to see if we've tried the same voltage 5 times */
1292 intel_get_adjust_train(intel_dp); 1320 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
1321 ++tries;
1322 if (tries == 5)
1323 break;
1324 } else
1325 tries = 0;
1326 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1327
1328 /* Compute new intel_dp->train_set as requested by target */
1329 intel_get_adjust_train(intel_dp);
1330 }
1293 } 1331 }
1294 1332
1295 intel_dp->DP = DP; 1333 intel_dp->DP = DP;
@@ -1312,15 +1350,15 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1312 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */ 1350 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
1313 uint32_t signal_levels; 1351 uint32_t signal_levels;
1314 1352
1315 if (IS_GEN6(dev) && IS_eDP(intel_dp)) { 1353 if (IS_GEN6(dev) && is_edp(intel_dp)) {
1316 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]); 1354 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
1317 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; 1355 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1318 } else { 1356 } else {
1319 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count); 1357 signal_levels = intel_dp_signal_levels(intel_dp);
1320 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; 1358 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1321 } 1359 }
1322 1360
1323 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) 1361 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
1324 reg = DP | DP_LINK_TRAIN_PAT_2_CPT; 1362 reg = DP | DP_LINK_TRAIN_PAT_2_CPT;
1325 else 1363 else
1326 reg = DP | DP_LINK_TRAIN_PAT_2; 1364 reg = DP | DP_LINK_TRAIN_PAT_2;
@@ -1330,25 +1368,29 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1330 DP_TRAINING_PATTERN_2)) 1368 DP_TRAINING_PATTERN_2))
1331 break; 1369 break;
1332 1370
1333 udelay(400); 1371 udelay(500);
1334 if (!intel_dp_get_link_status(intel_dp))
1335 break;
1336 1372
1337 if (intel_channel_eq_ok(intel_dp)) { 1373 if (!intel_dp_aux_handshake_required(intel_dp)) {
1338 channel_eq = true;
1339 break; 1374 break;
1340 } 1375 } else {
1376 if (!intel_dp_get_link_status(intel_dp))
1377 break;
1341 1378
1342 /* Try 5 times */ 1379 if (intel_channel_eq_ok(intel_dp)) {
1343 if (tries > 5) 1380 channel_eq = true;
1344 break; 1381 break;
1382 }
1345 1383
1346 /* Compute new intel_dp->train_set as requested by target */ 1384 /* Try 5 times */
1347 intel_get_adjust_train(intel_dp); 1385 if (tries > 5)
1348 ++tries; 1386 break;
1349 }
1350 1387
1351 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) 1388 /* Compute new intel_dp->train_set as requested by target */
1389 intel_get_adjust_train(intel_dp);
1390 ++tries;
1391 }
1392 }
1393 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
1352 reg = DP | DP_LINK_TRAIN_OFF_CPT; 1394 reg = DP | DP_LINK_TRAIN_OFF_CPT;
1353 else 1395 else
1354 reg = DP | DP_LINK_TRAIN_OFF; 1396 reg = DP | DP_LINK_TRAIN_OFF;
@@ -1368,14 +1410,14 @@ intel_dp_link_down(struct intel_dp *intel_dp)
1368 1410
1369 DRM_DEBUG_KMS("\n"); 1411 DRM_DEBUG_KMS("\n");
1370 1412
1371 if (IS_eDP(intel_dp)) { 1413 if (is_edp(intel_dp)) {
1372 DP &= ~DP_PLL_ENABLE; 1414 DP &= ~DP_PLL_ENABLE;
1373 I915_WRITE(intel_dp->output_reg, DP); 1415 I915_WRITE(intel_dp->output_reg, DP);
1374 POSTING_READ(intel_dp->output_reg); 1416 POSTING_READ(intel_dp->output_reg);
1375 udelay(100); 1417 udelay(100);
1376 } 1418 }
1377 1419
1378 if (HAS_PCH_CPT(dev) && !IS_eDP(intel_dp)) { 1420 if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) {
1379 DP &= ~DP_LINK_TRAIN_MASK_CPT; 1421 DP &= ~DP_LINK_TRAIN_MASK_CPT;
1380 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT); 1422 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
1381 } else { 1423 } else {
@@ -1386,7 +1428,7 @@ intel_dp_link_down(struct intel_dp *intel_dp)
1386 1428
1387 msleep(17); 1429 msleep(17);
1388 1430
1389 if (IS_eDP(intel_dp)) 1431 if (is_edp(intel_dp))
1390 DP |= DP_LINK_TRAIN_OFF; 1432 DP |= DP_LINK_TRAIN_OFF;
1391 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); 1433 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
1392 POSTING_READ(intel_dp->output_reg); 1434 POSTING_READ(intel_dp->output_reg);
@@ -1419,48 +1461,34 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
1419} 1461}
1420 1462
1421static enum drm_connector_status 1463static enum drm_connector_status
1422ironlake_dp_detect(struct drm_connector *connector) 1464ironlake_dp_detect(struct intel_dp *intel_dp)
1423{ 1465{
1424 struct intel_dp *intel_dp = intel_attached_dp(connector);
1425 enum drm_connector_status status; 1466 enum drm_connector_status status;
1426 1467
1427 /* Panel needs power for AUX to work */ 1468 /* Can't disconnect eDP */
1428 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) 1469 if (is_edp(intel_dp))
1429 ironlake_edp_panel_vdd_on(connector->dev); 1470 return connector_status_connected;
1471
1430 status = connector_status_disconnected; 1472 status = connector_status_disconnected;
1431 if (intel_dp_aux_native_read(intel_dp, 1473 if (intel_dp_aux_native_read(intel_dp,
1432 0x000, intel_dp->dpcd, 1474 0x000, intel_dp->dpcd,
1433 sizeof (intel_dp->dpcd)) == sizeof (intel_dp->dpcd)) 1475 sizeof (intel_dp->dpcd))
1434 { 1476 == sizeof(intel_dp->dpcd)) {
1435 if (intel_dp->dpcd[0] != 0) 1477 if (intel_dp->dpcd[0] != 0)
1436 status = connector_status_connected; 1478 status = connector_status_connected;
1437 } 1479 }
1438 DRM_DEBUG_KMS("DPCD: %hx%hx%hx%hx\n", intel_dp->dpcd[0], 1480 DRM_DEBUG_KMS("DPCD: %hx%hx%hx%hx\n", intel_dp->dpcd[0],
1439 intel_dp->dpcd[1], intel_dp->dpcd[2], intel_dp->dpcd[3]); 1481 intel_dp->dpcd[1], intel_dp->dpcd[2], intel_dp->dpcd[3]);
1440 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp))
1441 ironlake_edp_panel_vdd_off(connector->dev);
1442 return status; 1482 return status;
1443} 1483}
1444 1484
1445/**
1446 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
1447 *
1448 * \return true if DP port is connected.
1449 * \return false if DP port is disconnected.
1450 */
1451static enum drm_connector_status 1485static enum drm_connector_status
1452intel_dp_detect(struct drm_connector *connector, bool force) 1486g4x_dp_detect(struct intel_dp *intel_dp)
1453{ 1487{
1454 struct intel_dp *intel_dp = intel_attached_dp(connector);
1455 struct drm_device *dev = intel_dp->base.base.dev; 1488 struct drm_device *dev = intel_dp->base.base.dev;
1456 struct drm_i915_private *dev_priv = dev->dev_private; 1489 struct drm_i915_private *dev_priv = dev->dev_private;
1457 uint32_t temp, bit;
1458 enum drm_connector_status status; 1490 enum drm_connector_status status;
1459 1491 uint32_t temp, bit;
1460 intel_dp->has_audio = false;
1461
1462 if (HAS_PCH_SPLIT(dev))
1463 return ironlake_dp_detect(connector);
1464 1492
1465 switch (intel_dp->output_reg) { 1493 switch (intel_dp->output_reg) {
1466 case DP_B: 1494 case DP_B:
@@ -1482,14 +1510,51 @@ intel_dp_detect(struct drm_connector *connector, bool force)
1482 return connector_status_disconnected; 1510 return connector_status_disconnected;
1483 1511
1484 status = connector_status_disconnected; 1512 status = connector_status_disconnected;
1485 if (intel_dp_aux_native_read(intel_dp, 1513 if (intel_dp_aux_native_read(intel_dp, 0x000, intel_dp->dpcd,
1486 0x000, intel_dp->dpcd,
1487 sizeof (intel_dp->dpcd)) == sizeof (intel_dp->dpcd)) 1514 sizeof (intel_dp->dpcd)) == sizeof (intel_dp->dpcd))
1488 { 1515 {
1489 if (intel_dp->dpcd[0] != 0) 1516 if (intel_dp->dpcd[0] != 0)
1490 status = connector_status_connected; 1517 status = connector_status_connected;
1491 } 1518 }
1492 return status; 1519
1520 return bit;
1521}
1522
1523/**
1524 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
1525 *
1526 * \return true if DP port is connected.
1527 * \return false if DP port is disconnected.
1528 */
1529static enum drm_connector_status
1530intel_dp_detect(struct drm_connector *connector, bool force)
1531{
1532 struct intel_dp *intel_dp = intel_attached_dp(connector);
1533 struct drm_device *dev = intel_dp->base.base.dev;
1534 enum drm_connector_status status;
1535 struct edid *edid = NULL;
1536
1537 intel_dp->has_audio = false;
1538
1539 if (HAS_PCH_SPLIT(dev))
1540 status = ironlake_dp_detect(intel_dp);
1541 else
1542 status = g4x_dp_detect(intel_dp);
1543 if (status != connector_status_connected)
1544 return status;
1545
1546 if (intel_dp->force_audio) {
1547 intel_dp->has_audio = intel_dp->force_audio > 0;
1548 } else {
1549 edid = drm_get_edid(connector, &intel_dp->adapter);
1550 if (edid) {
1551 intel_dp->has_audio = drm_detect_monitor_audio(edid);
1552 connector->display_info.raw_edid = NULL;
1553 kfree(edid);
1554 }
1555 }
1556
1557 return connector_status_connected;
1493} 1558}
1494 1559
1495static int intel_dp_get_modes(struct drm_connector *connector) 1560static int intel_dp_get_modes(struct drm_connector *connector)
@@ -1504,8 +1569,7 @@ static int intel_dp_get_modes(struct drm_connector *connector)
1504 1569
1505 ret = intel_ddc_get_modes(connector, &intel_dp->adapter); 1570 ret = intel_ddc_get_modes(connector, &intel_dp->adapter);
1506 if (ret) { 1571 if (ret) {
1507 if ((IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) && 1572 if (is_edp(intel_dp) && !dev_priv->panel_fixed_mode) {
1508 !dev_priv->panel_fixed_mode) {
1509 struct drm_display_mode *newmode; 1573 struct drm_display_mode *newmode;
1510 list_for_each_entry(newmode, &connector->probed_modes, 1574 list_for_each_entry(newmode, &connector->probed_modes,
1511 head) { 1575 head) {
@@ -1521,7 +1585,7 @@ static int intel_dp_get_modes(struct drm_connector *connector)
1521 } 1585 }
1522 1586
1523 /* if eDP has no EDID, try to use fixed panel mode from VBT */ 1587 /* if eDP has no EDID, try to use fixed panel mode from VBT */
1524 if (IS_eDP(intel_dp) || IS_PCH_eDP(intel_dp)) { 1588 if (is_edp(intel_dp)) {
1525 if (dev_priv->panel_fixed_mode != NULL) { 1589 if (dev_priv->panel_fixed_mode != NULL) {
1526 struct drm_display_mode *mode; 1590 struct drm_display_mode *mode;
1527 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode); 1591 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
@@ -1532,6 +1596,46 @@ static int intel_dp_get_modes(struct drm_connector *connector)
1532 return 0; 1596 return 0;
1533} 1597}
1534 1598
1599static int
1600intel_dp_set_property(struct drm_connector *connector,
1601 struct drm_property *property,
1602 uint64_t val)
1603{
1604 struct intel_dp *intel_dp = intel_attached_dp(connector);
1605 int ret;
1606
1607 ret = drm_connector_property_set_value(connector, property, val);
1608 if (ret)
1609 return ret;
1610
1611 if (property == intel_dp->force_audio_property) {
1612 if (val == intel_dp->force_audio)
1613 return 0;
1614
1615 intel_dp->force_audio = val;
1616
1617 if (val > 0 && intel_dp->has_audio)
1618 return 0;
1619 if (val < 0 && !intel_dp->has_audio)
1620 return 0;
1621
1622 intel_dp->has_audio = val > 0;
1623 goto done;
1624 }
1625
1626 return -EINVAL;
1627
1628done:
1629 if (intel_dp->base.base.crtc) {
1630 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1631 drm_crtc_helper_set_mode(crtc, &crtc->mode,
1632 crtc->x, crtc->y,
1633 crtc->fb);
1634 }
1635
1636 return 0;
1637}
1638
1535static void 1639static void
1536intel_dp_destroy (struct drm_connector *connector) 1640intel_dp_destroy (struct drm_connector *connector)
1537{ 1641{
@@ -1561,6 +1665,7 @@ static const struct drm_connector_funcs intel_dp_connector_funcs = {
1561 .dpms = drm_helper_connector_dpms, 1665 .dpms = drm_helper_connector_dpms,
1562 .detect = intel_dp_detect, 1666 .detect = intel_dp_detect,
1563 .fill_modes = drm_helper_probe_single_connector_modes, 1667 .fill_modes = drm_helper_probe_single_connector_modes,
1668 .set_property = intel_dp_set_property,
1564 .destroy = intel_dp_destroy, 1669 .destroy = intel_dp_destroy,
1565}; 1670};
1566 1671
@@ -1625,6 +1730,20 @@ bool intel_dpd_is_edp(struct drm_device *dev)
1625 return false; 1730 return false;
1626} 1731}
1627 1732
1733static void
1734intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
1735{
1736 struct drm_device *dev = connector->dev;
1737
1738 intel_dp->force_audio_property =
1739 drm_property_create(dev, DRM_MODE_PROP_RANGE, "force_audio", 2);
1740 if (intel_dp->force_audio_property) {
1741 intel_dp->force_audio_property->values[0] = -1;
1742 intel_dp->force_audio_property->values[1] = 1;
1743 drm_connector_attach_property(connector, intel_dp->force_audio_property, 0);
1744 }
1745}
1746
1628void 1747void
1629intel_dp_init(struct drm_device *dev, int output_reg) 1748intel_dp_init(struct drm_device *dev, int output_reg)
1630{ 1749{
@@ -1651,7 +1770,7 @@ intel_dp_init(struct drm_device *dev, int output_reg)
1651 if (intel_dpd_is_edp(dev)) 1770 if (intel_dpd_is_edp(dev))
1652 intel_dp->is_pch_edp = true; 1771 intel_dp->is_pch_edp = true;
1653 1772
1654 if (output_reg == DP_A || IS_PCH_eDP(intel_dp)) { 1773 if (output_reg == DP_A || is_pch_edp(intel_dp)) {
1655 type = DRM_MODE_CONNECTOR_eDP; 1774 type = DRM_MODE_CONNECTOR_eDP;
1656 intel_encoder->type = INTEL_OUTPUT_EDP; 1775 intel_encoder->type = INTEL_OUTPUT_EDP;
1657 } else { 1776 } else {
@@ -1672,7 +1791,7 @@ intel_dp_init(struct drm_device *dev, int output_reg)
1672 else if (output_reg == DP_D || output_reg == PCH_DP_D) 1791 else if (output_reg == DP_D || output_reg == PCH_DP_D)
1673 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT); 1792 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
1674 1793
1675 if (IS_eDP(intel_dp)) 1794 if (is_edp(intel_dp))
1676 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT); 1795 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT);
1677 1796
1678 intel_encoder->crtc_mask = (1 << 0) | (1 << 1); 1797 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
@@ -1717,9 +1836,29 @@ intel_dp_init(struct drm_device *dev, int output_reg)
1717 1836
1718 intel_dp_i2c_init(intel_dp, intel_connector, name); 1837 intel_dp_i2c_init(intel_dp, intel_connector, name);
1719 1838
1839 /* Cache some DPCD data in the eDP case */
1840 if (is_edp(intel_dp)) {
1841 int ret;
1842 bool was_on;
1843
1844 was_on = ironlake_edp_panel_on(intel_dp);
1845 ret = intel_dp_aux_native_read(intel_dp, DP_DPCD_REV,
1846 intel_dp->dpcd,
1847 sizeof(intel_dp->dpcd));
1848 if (ret == sizeof(intel_dp->dpcd)) {
1849 if (intel_dp->dpcd[0] >= 0x11)
1850 dev_priv->no_aux_handshake = intel_dp->dpcd[3] &
1851 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
1852 } else {
1853 DRM_ERROR("failed to retrieve link info\n");
1854 }
1855 if (!was_on)
1856 ironlake_edp_panel_off(dev);
1857 }
1858
1720 intel_encoder->hot_plug = intel_dp_hot_plug; 1859 intel_encoder->hot_plug = intel_dp_hot_plug;
1721 1860
1722 if (output_reg == DP_A || IS_PCH_eDP(intel_dp)) { 1861 if (is_edp(intel_dp)) {
1723 /* initialize panel mode from VBT if available for eDP */ 1862 /* initialize panel mode from VBT if available for eDP */
1724 if (dev_priv->lfp_lvds_vbt_mode) { 1863 if (dev_priv->lfp_lvds_vbt_mode) {
1725 dev_priv->panel_fixed_mode = 1864 dev_priv->panel_fixed_mode =
@@ -1731,6 +1870,8 @@ intel_dp_init(struct drm_device *dev, int output_reg)
1731 } 1870 }
1732 } 1871 }
1733 1872
1873 intel_dp_add_properties(intel_dp, connector);
1874
1734 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written 1875 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
1735 * 0xd. Failure to do so will result in spurious interrupts being 1876 * 0xd. Failure to do so will result in spurious interrupts being
1736 * generated on the port when a cable is not attached. 1877 * generated on the port when a cable is not attached.