aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i915/intel_dp.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-10-20 16:40:33 -0400
committerKeith Packard <keithp@keithp.com>2011-10-20 17:10:07 -0400
commit86a3073e480c522f12e5291a462f68f6ee30aee3 (patch)
tree5804f9d944084ff5245d07e8340779a4ecd52f9b /drivers/gpu/drm/i915/intel_dp.c
parent0ac225e56997ef89f46eb51b02799a685b78f214 (diff)
parent32ce697c53f41290c3a2d3807b521b0fe4f42d2a (diff)
Merge branch 'edp-training-fixes' into drm-intel-next
Conflicts: drivers/gpu/drm/i915/intel_dp.c Just whitespace change conflicts
Diffstat (limited to 'drivers/gpu/drm/i915/intel_dp.c')
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c473
1 files changed, 358 insertions, 115 deletions
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 6cbde9ff1ec6..3d73374c20d1 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -59,6 +59,15 @@ struct intel_dp {
59 bool is_pch_edp; 59 bool is_pch_edp;
60 uint8_t train_set[4]; 60 uint8_t train_set[4];
61 uint8_t link_status[DP_LINK_STATUS_SIZE]; 61 uint8_t link_status[DP_LINK_STATUS_SIZE];
62 int panel_power_up_delay;
63 int panel_power_down_delay;
64 int panel_power_cycle_delay;
65 int backlight_on_delay;
66 int backlight_off_delay;
67 struct drm_display_mode *panel_fixed_mode; /* for eDP */
68 struct delayed_work panel_vdd_work;
69 bool want_panel_vdd;
70 unsigned long panel_off_jiffies;
62}; 71};
63 72
64/** 73/**
@@ -200,16 +209,14 @@ intel_dp_mode_valid(struct drm_connector *connector,
200 struct drm_display_mode *mode) 209 struct drm_display_mode *mode)
201{ 210{
202 struct intel_dp *intel_dp = intel_attached_dp(connector); 211 struct intel_dp *intel_dp = intel_attached_dp(connector);
203 struct drm_device *dev = connector->dev;
204 struct drm_i915_private *dev_priv = dev->dev_private;
205 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp)); 212 int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
206 int max_lanes = intel_dp_max_lane_count(intel_dp); 213 int max_lanes = intel_dp_max_lane_count(intel_dp);
207 214
208 if (is_edp(intel_dp) && dev_priv->panel_fixed_mode) { 215 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
209 if (mode->hdisplay > dev_priv->panel_fixed_mode->hdisplay) 216 if (mode->hdisplay > intel_dp->panel_fixed_mode->hdisplay)
210 return MODE_PANEL; 217 return MODE_PANEL;
211 218
212 if (mode->vdisplay > dev_priv->panel_fixed_mode->vdisplay) 219 if (mode->vdisplay > intel_dp->panel_fixed_mode->vdisplay)
213 return MODE_PANEL; 220 return MODE_PANEL;
214 } 221 }
215 222
@@ -279,6 +286,38 @@ intel_hrawclk(struct drm_device *dev)
279 } 286 }
280} 287}
281 288
289static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
290{
291 struct drm_device *dev = intel_dp->base.base.dev;
292 struct drm_i915_private *dev_priv = dev->dev_private;
293
294 return (I915_READ(PCH_PP_STATUS) & PP_ON) != 0;
295}
296
297static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
298{
299 struct drm_device *dev = intel_dp->base.base.dev;
300 struct drm_i915_private *dev_priv = dev->dev_private;
301
302 return (I915_READ(PCH_PP_CONTROL) & EDP_FORCE_VDD) != 0;
303}
304
305static void
306intel_dp_check_edp(struct intel_dp *intel_dp)
307{
308 struct drm_device *dev = intel_dp->base.base.dev;
309 struct drm_i915_private *dev_priv = dev->dev_private;
310
311 if (!is_edp(intel_dp))
312 return;
313 if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
314 WARN(1, "eDP powered off while attempting aux channel communication.\n");
315 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
316 I915_READ(PCH_PP_STATUS),
317 I915_READ(PCH_PP_CONTROL));
318 }
319}
320
282static int 321static int
283intel_dp_aux_ch(struct intel_dp *intel_dp, 322intel_dp_aux_ch(struct intel_dp *intel_dp,
284 uint8_t *send, int send_bytes, 323 uint8_t *send, int send_bytes,
@@ -295,6 +334,7 @@ intel_dp_aux_ch(struct intel_dp *intel_dp,
295 uint32_t aux_clock_divider; 334 uint32_t aux_clock_divider;
296 int try, precharge; 335 int try, precharge;
297 336
337 intel_dp_check_edp(intel_dp);
298 /* The clock divider is based off the hrawclk, 338 /* The clock divider is based off the hrawclk,
299 * and would like to run at 2MHz. So, take the 339 * and would like to run at 2MHz. So, take the
300 * hrawclk value and divide by 2 and use that 340 * hrawclk value and divide by 2 and use that
@@ -408,6 +448,7 @@ intel_dp_aux_native_write(struct intel_dp *intel_dp,
408 int msg_bytes; 448 int msg_bytes;
409 uint8_t ack; 449 uint8_t ack;
410 450
451 intel_dp_check_edp(intel_dp);
411 if (send_bytes > 16) 452 if (send_bytes > 16)
412 return -1; 453 return -1;
413 msg[0] = AUX_NATIVE_WRITE << 4; 454 msg[0] = AUX_NATIVE_WRITE << 4;
@@ -450,6 +491,7 @@ intel_dp_aux_native_read(struct intel_dp *intel_dp,
450 uint8_t ack; 491 uint8_t ack;
451 int ret; 492 int ret;
452 493
494 intel_dp_check_edp(intel_dp);
453 msg[0] = AUX_NATIVE_READ << 4; 495 msg[0] = AUX_NATIVE_READ << 4;
454 msg[1] = address >> 8; 496 msg[1] = address >> 8;
455 msg[2] = address & 0xff; 497 msg[2] = address & 0xff;
@@ -493,6 +535,7 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
493 int reply_bytes; 535 int reply_bytes;
494 int ret; 536 int ret;
495 537
538 intel_dp_check_edp(intel_dp);
496 /* Set up the command byte */ 539 /* Set up the command byte */
497 if (mode & MODE_I2C_READ) 540 if (mode & MODE_I2C_READ)
498 msg[0] = AUX_I2C_READ << 4; 541 msg[0] = AUX_I2C_READ << 4;
@@ -573,10 +616,15 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
573 return -EREMOTEIO; 616 return -EREMOTEIO;
574} 617}
575 618
619static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp);
620static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
621
576static int 622static int
577intel_dp_i2c_init(struct intel_dp *intel_dp, 623intel_dp_i2c_init(struct intel_dp *intel_dp,
578 struct intel_connector *intel_connector, const char *name) 624 struct intel_connector *intel_connector, const char *name)
579{ 625{
626 int ret;
627
580 DRM_DEBUG_KMS("i2c_init %s\n", name); 628 DRM_DEBUG_KMS("i2c_init %s\n", name);
581 intel_dp->algo.running = false; 629 intel_dp->algo.running = false;
582 intel_dp->algo.address = 0; 630 intel_dp->algo.address = 0;
@@ -590,7 +638,10 @@ intel_dp_i2c_init(struct intel_dp *intel_dp,
590 intel_dp->adapter.algo_data = &intel_dp->algo; 638 intel_dp->adapter.algo_data = &intel_dp->algo;
591 intel_dp->adapter.dev.parent = &intel_connector->base.kdev; 639 intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
592 640
593 return i2c_dp_aux_add_bus(&intel_dp->adapter); 641 ironlake_edp_panel_vdd_on(intel_dp);
642 ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
643 ironlake_edp_panel_vdd_off(intel_dp, false);
644 return ret;
594} 645}
595 646
596static bool 647static bool
@@ -598,22 +649,21 @@ intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
598 struct drm_display_mode *adjusted_mode) 649 struct drm_display_mode *adjusted_mode)
599{ 650{
600 struct drm_device *dev = encoder->dev; 651 struct drm_device *dev = encoder->dev;
601 struct drm_i915_private *dev_priv = dev->dev_private;
602 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 652 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
603 int lane_count, clock; 653 int lane_count, clock;
604 int max_lane_count = intel_dp_max_lane_count(intel_dp); 654 int max_lane_count = intel_dp_max_lane_count(intel_dp);
605 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0; 655 int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
606 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 }; 656 static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
607 657
608 if (is_edp(intel_dp) && dev_priv->panel_fixed_mode) { 658 if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
609 intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode); 659 intel_fixed_panel_mode(intel_dp->panel_fixed_mode, adjusted_mode);
610 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN, 660 intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
611 mode, adjusted_mode); 661 mode, adjusted_mode);
612 /* 662 /*
613 * the mode->clock is used to calculate the Data&Link M/N 663 * the mode->clock is used to calculate the Data&Link M/N
614 * of the pipe. For the eDP the fixed clock should be used. 664 * of the pipe. For the eDP the fixed clock should be used.
615 */ 665 */
616 mode->clock = dev_priv->panel_fixed_mode->clock; 666 mode->clock = intel_dp->panel_fixed_mode->clock;
617 } 667 }
618 668
619 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { 669 for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
@@ -740,6 +790,9 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
740 } 790 }
741} 791}
742 792
793static void ironlake_edp_pll_on(struct drm_encoder *encoder);
794static void ironlake_edp_pll_off(struct drm_encoder *encoder);
795
743static void 796static void
744intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, 797intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
745 struct drm_display_mode *adjusted_mode) 798 struct drm_display_mode *adjusted_mode)
@@ -749,6 +802,14 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
749 struct drm_crtc *crtc = intel_dp->base.base.crtc; 802 struct drm_crtc *crtc = intel_dp->base.base.crtc;
750 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 803 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
751 804
805 /* Turn on the eDP PLL if needed */
806 if (is_edp(intel_dp)) {
807 if (!is_pch_edp(intel_dp))
808 ironlake_edp_pll_on(encoder);
809 else
810 ironlake_edp_pll_off(encoder);
811 }
812
752 intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; 813 intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
753 intel_dp->DP |= intel_dp->color_range; 814 intel_dp->DP |= intel_dp->color_range;
754 815
@@ -808,58 +869,150 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
808 } 869 }
809} 870}
810 871
872static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
873{
874 unsigned long off_time;
875 unsigned long delay;
876
877 DRM_DEBUG_KMS("Wait for panel power off time\n");
878
879 if (ironlake_edp_have_panel_power(intel_dp) ||
880 ironlake_edp_have_panel_vdd(intel_dp))
881 {
882 DRM_DEBUG_KMS("Panel still on, no delay needed\n");
883 return;
884 }
885
886 off_time = intel_dp->panel_off_jiffies + msecs_to_jiffies(intel_dp->panel_power_down_delay);
887 if (time_after(jiffies, off_time)) {
888 DRM_DEBUG_KMS("Time already passed");
889 return;
890 }
891 delay = jiffies_to_msecs(off_time - jiffies);
892 if (delay > intel_dp->panel_power_down_delay)
893 delay = intel_dp->panel_power_down_delay;
894 DRM_DEBUG_KMS("Waiting an additional %ld ms\n", delay);
895 msleep(delay);
896}
897
811static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp) 898static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
812{ 899{
813 struct drm_device *dev = intel_dp->base.base.dev; 900 struct drm_device *dev = intel_dp->base.base.dev;
814 struct drm_i915_private *dev_priv = dev->dev_private; 901 struct drm_i915_private *dev_priv = dev->dev_private;
815 u32 pp; 902 u32 pp;
816 903
817 /* 904 if (!is_edp(intel_dp))
818 * If the panel wasn't on, make sure there's not a currently 905 return;
819 * active PP sequence before enabling AUX VDD. 906 DRM_DEBUG_KMS("Turn eDP VDD on\n");
820 */
821 if (!(I915_READ(PCH_PP_STATUS) & PP_ON))
822 msleep(dev_priv->panel_t3);
823 907
908 WARN(intel_dp->want_panel_vdd,
909 "eDP VDD already requested on\n");
910
911 intel_dp->want_panel_vdd = true;
912 if (ironlake_edp_have_panel_vdd(intel_dp)) {
913 DRM_DEBUG_KMS("eDP VDD already on\n");
914 return;
915 }
916
917 ironlake_wait_panel_off(intel_dp);
824 pp = I915_READ(PCH_PP_CONTROL); 918 pp = I915_READ(PCH_PP_CONTROL);
919 pp &= ~PANEL_UNLOCK_MASK;
920 pp |= PANEL_UNLOCK_REGS;
825 pp |= EDP_FORCE_VDD; 921 pp |= EDP_FORCE_VDD;
826 I915_WRITE(PCH_PP_CONTROL, pp); 922 I915_WRITE(PCH_PP_CONTROL, pp);
827 POSTING_READ(PCH_PP_CONTROL); 923 POSTING_READ(PCH_PP_CONTROL);
924 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
925 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
926
927 /*
928 * If the panel wasn't on, delay before accessing aux channel
929 */
930 if (!ironlake_edp_have_panel_power(intel_dp)) {
931 DRM_DEBUG_KMS("eDP was not running\n");
932 msleep(intel_dp->panel_power_up_delay);
933 }
828} 934}
829 935
830static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp) 936static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
831{ 937{
832 struct drm_device *dev = intel_dp->base.base.dev; 938 struct drm_device *dev = intel_dp->base.base.dev;
833 struct drm_i915_private *dev_priv = dev->dev_private; 939 struct drm_i915_private *dev_priv = dev->dev_private;
834 u32 pp; 940 u32 pp;
835 941
836 pp = I915_READ(PCH_PP_CONTROL); 942 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
837 pp &= ~EDP_FORCE_VDD; 943 pp = I915_READ(PCH_PP_CONTROL);
838 I915_WRITE(PCH_PP_CONTROL, pp); 944 pp &= ~PANEL_UNLOCK_MASK;
839 POSTING_READ(PCH_PP_CONTROL); 945 pp |= PANEL_UNLOCK_REGS;
946 pp &= ~EDP_FORCE_VDD;
947 I915_WRITE(PCH_PP_CONTROL, pp);
948 POSTING_READ(PCH_PP_CONTROL);
949
950 /* Make sure sequencer is idle before allowing subsequent activity */
951 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
952 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
953 intel_dp->panel_off_jiffies = jiffies;
954 }
955}
840 956
841 /* Make sure sequencer is idle before allowing subsequent activity */ 957static void ironlake_panel_vdd_work(struct work_struct *__work)
842 msleep(dev_priv->panel_t12); 958{
959 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
960 struct intel_dp, panel_vdd_work);
961 struct drm_device *dev = intel_dp->base.base.dev;
962
963 mutex_lock(&dev->struct_mutex);
964 ironlake_panel_vdd_off_sync(intel_dp);
965 mutex_unlock(&dev->struct_mutex);
966}
967
968static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
969{
970 if (!is_edp(intel_dp))
971 return;
972
973 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
974 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
975
976 intel_dp->want_panel_vdd = false;
977
978 if (sync) {
979 ironlake_panel_vdd_off_sync(intel_dp);
980 } else {
981 /*
982 * Queue the timer to fire a long
983 * time from now (relative to the power down delay)
984 * to keep the panel power up across a sequence of operations
985 */
986 schedule_delayed_work(&intel_dp->panel_vdd_work,
987 msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
988 }
843} 989}
844 990
845/* Returns true if the panel was already on when called */ 991/* Returns true if the panel was already on when called */
846static bool ironlake_edp_panel_on(struct intel_dp *intel_dp) 992static void ironlake_edp_panel_on(struct intel_dp *intel_dp)
847{ 993{
848 struct drm_device *dev = intel_dp->base.base.dev; 994 struct drm_device *dev = intel_dp->base.base.dev;
849 struct drm_i915_private *dev_priv = dev->dev_private; 995 struct drm_i915_private *dev_priv = dev->dev_private;
850 u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE; 996 u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE;
851 997
852 if (I915_READ(PCH_PP_STATUS) & PP_ON) 998 if (!is_edp(intel_dp))
853 return true; 999 return;
1000 if (ironlake_edp_have_panel_power(intel_dp))
1001 return;
854 1002
1003 ironlake_wait_panel_off(intel_dp);
855 pp = I915_READ(PCH_PP_CONTROL); 1004 pp = I915_READ(PCH_PP_CONTROL);
1005 pp &= ~PANEL_UNLOCK_MASK;
1006 pp |= PANEL_UNLOCK_REGS;
1007
1008 if (IS_GEN5(dev)) {
1009 /* ILK workaround: disable reset around power sequence */
1010 pp &= ~PANEL_POWER_RESET;
1011 I915_WRITE(PCH_PP_CONTROL, pp);
1012 POSTING_READ(PCH_PP_CONTROL);
1013 }
856 1014
857 /* ILK workaround: disable reset around power sequence */ 1015 pp |= POWER_TARGET_ON;
858 pp &= ~PANEL_POWER_RESET;
859 I915_WRITE(PCH_PP_CONTROL, pp);
860 POSTING_READ(PCH_PP_CONTROL);
861
862 pp |= PANEL_UNLOCK_REGS | POWER_TARGET_ON;
863 I915_WRITE(PCH_PP_CONTROL, pp); 1016 I915_WRITE(PCH_PP_CONTROL, pp);
864 POSTING_READ(PCH_PP_CONTROL); 1017 POSTING_READ(PCH_PP_CONTROL);
865 1018
@@ -868,44 +1021,64 @@ static bool ironlake_edp_panel_on(struct intel_dp *intel_dp)
868 DRM_ERROR("panel on wait timed out: 0x%08x\n", 1021 DRM_ERROR("panel on wait timed out: 0x%08x\n",
869 I915_READ(PCH_PP_STATUS)); 1022 I915_READ(PCH_PP_STATUS));
870 1023
871 pp |= PANEL_POWER_RESET; /* restore panel reset bit */ 1024 if (IS_GEN5(dev)) {
872 I915_WRITE(PCH_PP_CONTROL, pp); 1025 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
873 POSTING_READ(PCH_PP_CONTROL); 1026 I915_WRITE(PCH_PP_CONTROL, pp);
874 1027 POSTING_READ(PCH_PP_CONTROL);
875 return false; 1028 }
876} 1029}
877 1030
878static void ironlake_edp_panel_off(struct drm_device *dev) 1031static void ironlake_edp_panel_off(struct drm_encoder *encoder)
879{ 1032{
1033 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1034 struct drm_device *dev = encoder->dev;
880 struct drm_i915_private *dev_priv = dev->dev_private; 1035 struct drm_i915_private *dev_priv = dev->dev_private;
881 u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK | 1036 u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK |
882 PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK; 1037 PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK;
883 1038
1039 if (!is_edp(intel_dp))
1040 return;
884 pp = I915_READ(PCH_PP_CONTROL); 1041 pp = I915_READ(PCH_PP_CONTROL);
1042 pp &= ~PANEL_UNLOCK_MASK;
1043 pp |= PANEL_UNLOCK_REGS;
1044
1045 if (IS_GEN5(dev)) {
1046 /* ILK workaround: disable reset around power sequence */
1047 pp &= ~PANEL_POWER_RESET;
1048 I915_WRITE(PCH_PP_CONTROL, pp);
1049 POSTING_READ(PCH_PP_CONTROL);
1050 }
885 1051
886 /* ILK workaround: disable reset around power sequence */ 1052 intel_dp->panel_off_jiffies = jiffies;
887 pp &= ~PANEL_POWER_RESET;
888 I915_WRITE(PCH_PP_CONTROL, pp);
889 POSTING_READ(PCH_PP_CONTROL);
890 1053
891 pp &= ~POWER_TARGET_ON; 1054 if (IS_GEN5(dev)) {
892 I915_WRITE(PCH_PP_CONTROL, pp); 1055 pp &= ~POWER_TARGET_ON;
893 POSTING_READ(PCH_PP_CONTROL); 1056 I915_WRITE(PCH_PP_CONTROL, pp);
1057 POSTING_READ(PCH_PP_CONTROL);
1058 pp &= ~POWER_TARGET_ON;
1059 I915_WRITE(PCH_PP_CONTROL, pp);
1060 POSTING_READ(PCH_PP_CONTROL);
1061 msleep(intel_dp->panel_power_cycle_delay);
894 1062
895 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000)) 1063 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000))
896 DRM_ERROR("panel off wait timed out: 0x%08x\n", 1064 DRM_ERROR("panel off wait timed out: 0x%08x\n",
897 I915_READ(PCH_PP_STATUS)); 1065 I915_READ(PCH_PP_STATUS));
898 1066
899 pp |= PANEL_POWER_RESET; /* restore panel reset bit */ 1067 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
900 I915_WRITE(PCH_PP_CONTROL, pp); 1068 I915_WRITE(PCH_PP_CONTROL, pp);
901 POSTING_READ(PCH_PP_CONTROL); 1069 POSTING_READ(PCH_PP_CONTROL);
1070 }
902} 1071}
903 1072
904static void ironlake_edp_backlight_on(struct drm_device *dev) 1073static void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
905{ 1074{
1075 struct drm_device *dev = intel_dp->base.base.dev;
906 struct drm_i915_private *dev_priv = dev->dev_private; 1076 struct drm_i915_private *dev_priv = dev->dev_private;
907 u32 pp; 1077 u32 pp;
908 1078
1079 if (!is_edp(intel_dp))
1080 return;
1081
909 DRM_DEBUG_KMS("\n"); 1082 DRM_DEBUG_KMS("\n");
910 /* 1083 /*
911 * If we enable the backlight right away following a panel power 1084 * If we enable the backlight right away following a panel power
@@ -913,21 +1086,32 @@ static void ironlake_edp_backlight_on(struct drm_device *dev)
913 * link. So delay a bit to make sure the image is solid before 1086 * link. So delay a bit to make sure the image is solid before
914 * allowing it to appear. 1087 * allowing it to appear.
915 */ 1088 */
916 msleep(300); 1089 msleep(intel_dp->backlight_on_delay);
917 pp = I915_READ(PCH_PP_CONTROL); 1090 pp = I915_READ(PCH_PP_CONTROL);
1091 pp &= ~PANEL_UNLOCK_MASK;
1092 pp |= PANEL_UNLOCK_REGS;
918 pp |= EDP_BLC_ENABLE; 1093 pp |= EDP_BLC_ENABLE;
919 I915_WRITE(PCH_PP_CONTROL, pp); 1094 I915_WRITE(PCH_PP_CONTROL, pp);
1095 POSTING_READ(PCH_PP_CONTROL);
920} 1096}
921 1097
922static void ironlake_edp_backlight_off(struct drm_device *dev) 1098static void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
923{ 1099{
1100 struct drm_device *dev = intel_dp->base.base.dev;
924 struct drm_i915_private *dev_priv = dev->dev_private; 1101 struct drm_i915_private *dev_priv = dev->dev_private;
925 u32 pp; 1102 u32 pp;
926 1103
1104 if (!is_edp(intel_dp))
1105 return;
1106
927 DRM_DEBUG_KMS("\n"); 1107 DRM_DEBUG_KMS("\n");
928 pp = I915_READ(PCH_PP_CONTROL); 1108 pp = I915_READ(PCH_PP_CONTROL);
1109 pp &= ~PANEL_UNLOCK_MASK;
1110 pp |= PANEL_UNLOCK_REGS;
929 pp &= ~EDP_BLC_ENABLE; 1111 pp &= ~EDP_BLC_ENABLE;
930 I915_WRITE(PCH_PP_CONTROL, pp); 1112 I915_WRITE(PCH_PP_CONTROL, pp);
1113 POSTING_READ(PCH_PP_CONTROL);
1114 msleep(intel_dp->backlight_off_delay);
931} 1115}
932 1116
933static void ironlake_edp_pll_on(struct drm_encoder *encoder) 1117static void ironlake_edp_pll_on(struct drm_encoder *encoder)
@@ -990,41 +1174,32 @@ static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
990static void intel_dp_prepare(struct drm_encoder *encoder) 1174static void intel_dp_prepare(struct drm_encoder *encoder)
991{ 1175{
992 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1176 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
993 struct drm_device *dev = encoder->dev;
994 1177
995 /* Wake up the sink first */ 1178 /* Wake up the sink first */
1179 ironlake_edp_panel_vdd_on(intel_dp);
996 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 1180 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1181 ironlake_edp_panel_vdd_off(intel_dp, false);
997 1182
998 if (is_edp(intel_dp)) { 1183 /* Make sure the panel is off before trying to
999 ironlake_edp_backlight_off(dev); 1184 * change the mode
1000 ironlake_edp_panel_off(dev); 1185 */
1001 if (!is_pch_edp(intel_dp)) 1186 ironlake_edp_backlight_off(intel_dp);
1002 ironlake_edp_pll_on(encoder);
1003 else
1004 ironlake_edp_pll_off(encoder);
1005 }
1006 intel_dp_link_down(intel_dp); 1187 intel_dp_link_down(intel_dp);
1188 ironlake_edp_panel_off(encoder);
1007} 1189}
1008 1190
1009static void intel_dp_commit(struct drm_encoder *encoder) 1191static void intel_dp_commit(struct drm_encoder *encoder)
1010{ 1192{
1011 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1193 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1012 struct drm_device *dev = encoder->dev;
1013
1014 if (is_edp(intel_dp))
1015 ironlake_edp_panel_vdd_on(intel_dp);
1016 1194
1195 ironlake_edp_panel_vdd_on(intel_dp);
1196 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1017 intel_dp_start_link_train(intel_dp); 1197 intel_dp_start_link_train(intel_dp);
1018 1198 ironlake_edp_panel_on(intel_dp);
1019 if (is_edp(intel_dp)) { 1199 ironlake_edp_panel_vdd_off(intel_dp, true);
1020 ironlake_edp_panel_on(intel_dp);
1021 ironlake_edp_panel_vdd_off(intel_dp);
1022 }
1023 1200
1024 intel_dp_complete_link_train(intel_dp); 1201 intel_dp_complete_link_train(intel_dp);
1025 1202 ironlake_edp_backlight_on(intel_dp);
1026 if (is_edp(intel_dp))
1027 ironlake_edp_backlight_on(dev);
1028 1203
1029 intel_dp->dpms_mode = DRM_MODE_DPMS_ON; 1204 intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
1030} 1205}
@@ -1038,28 +1213,27 @@ intel_dp_dpms(struct drm_encoder *encoder, int mode)
1038 uint32_t dp_reg = I915_READ(intel_dp->output_reg); 1213 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
1039 1214
1040 if (mode != DRM_MODE_DPMS_ON) { 1215 if (mode != DRM_MODE_DPMS_ON) {
1216 ironlake_edp_panel_vdd_on(intel_dp);
1041 if (is_edp(intel_dp)) 1217 if (is_edp(intel_dp))
1042 ironlake_edp_backlight_off(dev); 1218 ironlake_edp_backlight_off(intel_dp);
1043 intel_dp_sink_dpms(intel_dp, mode); 1219 intel_dp_sink_dpms(intel_dp, mode);
1044 intel_dp_link_down(intel_dp); 1220 intel_dp_link_down(intel_dp);
1045 if (is_edp(intel_dp)) 1221 ironlake_edp_panel_off(encoder);
1046 ironlake_edp_panel_off(dev);
1047 if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) 1222 if (is_edp(intel_dp) && !is_pch_edp(intel_dp))
1048 ironlake_edp_pll_off(encoder); 1223 ironlake_edp_pll_off(encoder);
1224 ironlake_edp_panel_vdd_off(intel_dp, false);
1049 } else { 1225 } else {
1050 if (is_edp(intel_dp)) 1226 ironlake_edp_panel_vdd_on(intel_dp);
1051 ironlake_edp_panel_vdd_on(intel_dp);
1052 intel_dp_sink_dpms(intel_dp, mode); 1227 intel_dp_sink_dpms(intel_dp, mode);
1053 if (!(dp_reg & DP_PORT_EN)) { 1228 if (!(dp_reg & DP_PORT_EN)) {
1054 intel_dp_start_link_train(intel_dp); 1229 intel_dp_start_link_train(intel_dp);
1055 if (is_edp(intel_dp)) { 1230 ironlake_edp_panel_on(intel_dp);
1056 ironlake_edp_panel_on(intel_dp); 1231 ironlake_edp_panel_vdd_off(intel_dp, true);
1057 ironlake_edp_panel_vdd_off(intel_dp);
1058 }
1059 intel_dp_complete_link_train(intel_dp); 1232 intel_dp_complete_link_train(intel_dp);
1060 } 1233 ironlake_edp_backlight_on(intel_dp);
1061 if (is_edp(intel_dp)) 1234 } else
1062 ironlake_edp_backlight_on(dev); 1235 ironlake_edp_panel_vdd_off(intel_dp, false);
1236 ironlake_edp_backlight_on(intel_dp);
1063 } 1237 }
1064 intel_dp->dpms_mode = mode; 1238 intel_dp->dpms_mode = mode;
1065} 1239}
@@ -1582,6 +1756,7 @@ intel_dp_link_down(struct intel_dp *intel_dp)
1582 1756
1583 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN); 1757 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
1584 POSTING_READ(intel_dp->output_reg); 1758 POSTING_READ(intel_dp->output_reg);
1759 msleep(intel_dp->panel_power_down_delay);
1585} 1760}
1586 1761
1587static bool 1762static bool
@@ -1687,6 +1862,31 @@ g4x_dp_detect(struct intel_dp *intel_dp)
1687 return intel_dp_detect_dpcd(intel_dp); 1862 return intel_dp_detect_dpcd(intel_dp);
1688} 1863}
1689 1864
1865static struct edid *
1866intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
1867{
1868 struct intel_dp *intel_dp = intel_attached_dp(connector);
1869 struct edid *edid;
1870
1871 ironlake_edp_panel_vdd_on(intel_dp);
1872 edid = drm_get_edid(connector, adapter);
1873 ironlake_edp_panel_vdd_off(intel_dp, false);
1874 return edid;
1875}
1876
1877static int
1878intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
1879{
1880 struct intel_dp *intel_dp = intel_attached_dp(connector);
1881 int ret;
1882
1883 ironlake_edp_panel_vdd_on(intel_dp);
1884 ret = intel_ddc_get_modes(connector, adapter);
1885 ironlake_edp_panel_vdd_off(intel_dp, false);
1886 return ret;
1887}
1888
1889
1690/** 1890/**
1691 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection. 1891 * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
1692 * 1892 *
@@ -1719,7 +1919,7 @@ intel_dp_detect(struct drm_connector *connector, bool force)
1719 if (intel_dp->force_audio) { 1919 if (intel_dp->force_audio) {
1720 intel_dp->has_audio = intel_dp->force_audio > 0; 1920 intel_dp->has_audio = intel_dp->force_audio > 0;
1721 } else { 1921 } else {
1722 edid = drm_get_edid(connector, &intel_dp->adapter); 1922 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
1723 if (edid) { 1923 if (edid) {
1724 intel_dp->has_audio = drm_detect_monitor_audio(edid); 1924 intel_dp->has_audio = drm_detect_monitor_audio(edid);
1725 connector->display_info.raw_edid = NULL; 1925 connector->display_info.raw_edid = NULL;
@@ -1740,28 +1940,36 @@ static int intel_dp_get_modes(struct drm_connector *connector)
1740 /* We should parse the EDID data and find out if it has an audio sink 1940 /* We should parse the EDID data and find out if it has an audio sink
1741 */ 1941 */
1742 1942
1743 ret = intel_ddc_get_modes(connector, &intel_dp->adapter); 1943 ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
1744 if (ret) { 1944 if (ret) {
1745 if (is_edp(intel_dp) && !dev_priv->panel_fixed_mode) { 1945 if (is_edp(intel_dp) && !intel_dp->panel_fixed_mode) {
1746 struct drm_display_mode *newmode; 1946 struct drm_display_mode *newmode;
1747 list_for_each_entry(newmode, &connector->probed_modes, 1947 list_for_each_entry(newmode, &connector->probed_modes,
1748 head) { 1948 head) {
1749 if (newmode->type & DRM_MODE_TYPE_PREFERRED) { 1949 if ((newmode->type & DRM_MODE_TYPE_PREFERRED)) {
1750 dev_priv->panel_fixed_mode = 1950 intel_dp->panel_fixed_mode =
1751 drm_mode_duplicate(dev, newmode); 1951 drm_mode_duplicate(dev, newmode);
1752 break; 1952 break;
1753 } 1953 }
1754 } 1954 }
1755 } 1955 }
1756
1757 return ret; 1956 return ret;
1758 } 1957 }
1759 1958
1760 /* if eDP has no EDID, try to use fixed panel mode from VBT */ 1959 /* if eDP has no EDID, try to use fixed panel mode from VBT */
1761 if (is_edp(intel_dp)) { 1960 if (is_edp(intel_dp)) {
1762 if (dev_priv->panel_fixed_mode != NULL) { 1961 /* initialize panel mode from VBT if available for eDP */
1962 if (intel_dp->panel_fixed_mode == NULL && dev_priv->lfp_lvds_vbt_mode != NULL) {
1963 intel_dp->panel_fixed_mode =
1964 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
1965 if (intel_dp->panel_fixed_mode) {
1966 intel_dp->panel_fixed_mode->type |=
1967 DRM_MODE_TYPE_PREFERRED;
1968 }
1969 }
1970 if (intel_dp->panel_fixed_mode) {
1763 struct drm_display_mode *mode; 1971 struct drm_display_mode *mode;
1764 mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode); 1972 mode = drm_mode_duplicate(dev, intel_dp->panel_fixed_mode);
1765 drm_mode_probed_add(connector, mode); 1973 drm_mode_probed_add(connector, mode);
1766 return 1; 1974 return 1;
1767 } 1975 }
@@ -1776,7 +1984,7 @@ intel_dp_detect_audio(struct drm_connector *connector)
1776 struct edid *edid; 1984 struct edid *edid;
1777 bool has_audio = false; 1985 bool has_audio = false;
1778 1986
1779 edid = drm_get_edid(connector, &intel_dp->adapter); 1987 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
1780 if (edid) { 1988 if (edid) {
1781 has_audio = drm_detect_monitor_audio(edid); 1989 has_audio = drm_detect_monitor_audio(edid);
1782 1990
@@ -1861,6 +2069,10 @@ static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
1861 2069
1862 i2c_del_adapter(&intel_dp->adapter); 2070 i2c_del_adapter(&intel_dp->adapter);
1863 drm_encoder_cleanup(encoder); 2071 drm_encoder_cleanup(encoder);
2072 if (is_edp(intel_dp)) {
2073 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
2074 ironlake_panel_vdd_off_sync(intel_dp);
2075 }
1864 kfree(intel_dp); 2076 kfree(intel_dp);
1865} 2077}
1866 2078
@@ -1997,8 +2209,11 @@ intel_dp_init(struct drm_device *dev, int output_reg)
1997 else if (output_reg == DP_D || output_reg == PCH_DP_D) 2209 else if (output_reg == DP_D || output_reg == PCH_DP_D)
1998 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT); 2210 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
1999 2211
2000 if (is_edp(intel_dp)) 2212 if (is_edp(intel_dp)) {
2001 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT); 2213 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT);
2214 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
2215 ironlake_panel_vdd_work);
2216 }
2002 2217
2003 intel_encoder->crtc_mask = (1 << 0) | (1 << 1); 2218 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
2004 connector->interlace_allowed = true; 2219 connector->interlace_allowed = true;
@@ -2036,25 +2251,60 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2036 break; 2251 break;
2037 } 2252 }
2038 2253
2039 intel_dp_i2c_init(intel_dp, intel_connector, name);
2040
2041 /* Cache some DPCD data in the eDP case */ 2254 /* Cache some DPCD data in the eDP case */
2042 if (is_edp(intel_dp)) { 2255 if (is_edp(intel_dp)) {
2043 bool ret; 2256 bool ret;
2044 u32 pp_on, pp_div; 2257 struct edp_power_seq cur, vbt;
2258 u32 pp_on, pp_off, pp_div;
2045 2259
2046 pp_on = I915_READ(PCH_PP_ON_DELAYS); 2260 pp_on = I915_READ(PCH_PP_ON_DELAYS);
2261 pp_off = I915_READ(PCH_PP_OFF_DELAYS);
2047 pp_div = I915_READ(PCH_PP_DIVISOR); 2262 pp_div = I915_READ(PCH_PP_DIVISOR);
2048 2263
2049 /* Get T3 & T12 values (note: VESA not bspec terminology) */ 2264 /* Pull timing values out of registers */
2050 dev_priv->panel_t3 = (pp_on & 0x1fff0000) >> 16; 2265 cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
2051 dev_priv->panel_t3 /= 10; /* t3 in 100us units */ 2266 PANEL_POWER_UP_DELAY_SHIFT;
2052 dev_priv->panel_t12 = pp_div & 0xf; 2267
2053 dev_priv->panel_t12 *= 100; /* t12 in 100ms units */ 2268 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
2269 PANEL_LIGHT_ON_DELAY_SHIFT;
2270
2271 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
2272 PANEL_LIGHT_OFF_DELAY_SHIFT;
2273
2274 cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
2275 PANEL_POWER_DOWN_DELAY_SHIFT;
2276
2277 cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
2278 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
2279
2280 DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2281 cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
2282
2283 vbt = dev_priv->edp.pps;
2284
2285 DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
2286 vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
2287
2288#define get_delay(field) ((max(cur.field, vbt.field) + 9) / 10)
2289
2290 intel_dp->panel_power_up_delay = get_delay(t1_t3);
2291 intel_dp->backlight_on_delay = get_delay(t8);
2292 intel_dp->backlight_off_delay = get_delay(t9);
2293 intel_dp->panel_power_down_delay = get_delay(t10);
2294 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
2295
2296 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
2297 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
2298 intel_dp->panel_power_cycle_delay);
2299
2300 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2301 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
2302
2303 intel_dp->panel_off_jiffies = jiffies - intel_dp->panel_power_down_delay;
2054 2304
2055 ironlake_edp_panel_vdd_on(intel_dp); 2305 ironlake_edp_panel_vdd_on(intel_dp);
2056 ret = intel_dp_get_dpcd(intel_dp); 2306 ret = intel_dp_get_dpcd(intel_dp);
2057 ironlake_edp_panel_vdd_off(intel_dp); 2307 ironlake_edp_panel_vdd_off(intel_dp, false);
2058 if (ret) { 2308 if (ret) {
2059 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) 2309 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
2060 dev_priv->no_aux_handshake = 2310 dev_priv->no_aux_handshake =
@@ -2069,18 +2319,11 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2069 } 2319 }
2070 } 2320 }
2071 2321
2322 intel_dp_i2c_init(intel_dp, intel_connector, name);
2323
2072 intel_encoder->hot_plug = intel_dp_hot_plug; 2324 intel_encoder->hot_plug = intel_dp_hot_plug;
2073 2325
2074 if (is_edp(intel_dp)) { 2326 if (is_edp(intel_dp)) {
2075 /* initialize panel mode from VBT if available for eDP */
2076 if (dev_priv->lfp_lvds_vbt_mode) {
2077 dev_priv->panel_fixed_mode =
2078 drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
2079 if (dev_priv->panel_fixed_mode) {
2080 dev_priv->panel_fixed_mode->type |=
2081 DRM_MODE_TYPE_PREFERRED;
2082 }
2083 }
2084 dev_priv->int_edp_connector = connector; 2327 dev_priv->int_edp_connector = connector;
2085 intel_panel_setup_backlight(dev); 2328 intel_panel_setup_backlight(dev);
2086 } 2329 }