]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/gpu/drm/i915/intel_display.c
drm/i915: don't intel_crt_init on any ULT machines
[karo-tx-linux.git] / drivers / gpu / drm / i915 / intel_display.c
index 0e172ced8f0e2203714261318a173da3714b5392..6a8262867b0bcb0bd63412260fe007ef36baf5a9 100644 (file)
@@ -1227,8 +1227,8 @@ void assert_pipe(struct drm_i915_private *dev_priv,
        if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
                state = true;
 
-       if (IS_HASWELL(dev_priv->dev) && cpu_transcoder != TRANSCODER_EDP &&
-           !(I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_ENABLE)) {
+       if (!intel_using_power_well(dev_priv->dev) &&
+           cpu_transcoder != TRANSCODER_EDP) {
                cur_state = false;
        } else {
                reg = PIPECONF(cpu_transcoder);
@@ -1288,6 +1288,25 @@ static void assert_planes_disabled(struct drm_i915_private *dev_priv,
        }
 }
 
+static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
+                                   enum pipe pipe)
+{
+       int reg, i;
+       u32 val;
+
+       if (!IS_VALLEYVIEW(dev_priv->dev))
+               return;
+
+       /* Need to check both planes against the pipe */
+       for (i = 0; i < dev_priv->num_plane; i++) {
+               reg = SPCNTR(pipe, i);
+               val = I915_READ(reg);
+               WARN((val & SP_ENABLE),
+                    "sprite %d assertion failure, should be off on pipe %c but is still active\n",
+                    pipe * 2 + i, pipe_name(pipe));
+       }
+}
+
 static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
 {
        u32 val;
@@ -1872,6 +1891,7 @@ static void intel_disable_pipe(struct drm_i915_private *dev_priv,
         * or we might hang the display.
         */
        assert_planes_disabled(dev_priv, pipe);
+       assert_sprites_disabled(dev_priv, pipe);
 
        /* Don't disable pipe A or pipe A PLLs if needed */
        if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
@@ -1982,8 +2002,10 @@ intel_pin_and_fence_fb_obj(struct drm_device *dev,
                alignment = 0;
                break;
        case I915_TILING_Y:
-               /* FIXME: Is this true? */
-               DRM_ERROR("Y tiled not allowed for scan out buffers\n");
+               /* Despite that we check this in framebuffer_init userspace can
+                * screw us over and change the tiling after the fact. Only
+                * pinned buffers can't change their tiling. */
+               DRM_DEBUG_DRIVER("Y tiled not allowed for scan out buffers\n");
                return -EINVAL;
        default:
                BUG();
@@ -2975,11 +2997,6 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
        mutex_unlock(&dev->struct_mutex);
 }
 
-static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
-{
-       return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
-}
-
 /* Program iCLKIP clock to the desired frequency */
 static void lpt_program_iclkip(struct drm_crtc *crtc)
 {
@@ -3562,13 +3579,10 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
        enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
-       bool is_pch_port;
 
        if (!intel_crtc->active)
                return;
 
-       is_pch_port = haswell_crtc_driving_pch(crtc);
-
        for_each_encoder_on_crtc(dev, crtc, encoder)
                encoder->disable(encoder);
 
@@ -3585,9 +3599,13 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
 
        intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
 
-       /* Disable PF */
-       I915_WRITE(PF_CTL(pipe), 0);
-       I915_WRITE(PF_WIN_SZ(pipe), 0);
+       /* XXX: Once we have proper panel fitter state tracking implemented with
+        * hardware state read/check support we should switch to only disable
+        * the panel fitter when we know it's used. */
+       if (intel_using_power_well(dev)) {
+               I915_WRITE(PF_CTL(pipe), 0);
+               I915_WRITE(PF_WIN_SZ(pipe), 0);
+       }
 
        intel_ddi_disable_pipe_clock(intel_crtc);
 
@@ -3595,7 +3613,7 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
                if (encoder->post_disable)
                        encoder->post_disable(encoder);
 
-       if (is_pch_port) {
+       if (intel_crtc->config.has_pch_encoder) {
                lpt_disable_pch_transcoder(dev_priv);
                intel_ddi_fdi_disable(crtc);
        }
@@ -3706,6 +3724,26 @@ static void i9xx_crtc_enable(struct drm_crtc *crtc)
                encoder->enable(encoder);
 }
 
+static void i9xx_pfit_disable(struct intel_crtc *crtc)
+{
+       struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       enum pipe pipe;
+       uint32_t pctl = I915_READ(PFIT_CONTROL);
+
+       assert_pipe_disabled(dev_priv, crtc->pipe);
+
+       if (INTEL_INFO(dev)->gen >= 4)
+               pipe = (pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT;
+       else
+               pipe = PIPE_B;
+
+       if (pipe == crtc->pipe) {
+               DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", pctl);
+               I915_WRITE(PFIT_CONTROL, 0);
+       }
+}
+
 static void i9xx_crtc_disable(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
@@ -3714,8 +3752,6 @@ static void i9xx_crtc_disable(struct drm_crtc *crtc)
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
-       u32 pctl;
-
 
        if (!intel_crtc->active)
                return;
@@ -3735,11 +3771,7 @@ static void i9xx_crtc_disable(struct drm_crtc *crtc)
        intel_disable_plane(dev_priv, plane, pipe);
        intel_disable_pipe(dev_priv, pipe);
 
-       /* Disable pannel fitter if it is on this pipe. */
-       pctl = I915_READ(PFIT_CONTROL);
-       if ((pctl & PFIT_ENABLE) &&
-           ((pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT) == pipe)
-               I915_WRITE(PFIT_CONTROL, 0);
+       i9xx_pfit_disable(intel_crtc);
 
        intel_disable_pll(dev_priv, pipe);
 
@@ -4126,37 +4158,38 @@ static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
        return refclk;
 }
 
-static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
-                                     intel_clock_t *clock)
+static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc *crtc)
 {
+       unsigned dotclock = crtc->config.adjusted_mode.clock;
+       struct dpll *clock = &crtc->config.dpll;
+
        /* SDVO TV has fixed PLL values depend on its clock range,
           this mirrors vbios setting. */
-       if (adjusted_mode->clock >= 100000
-           && adjusted_mode->clock < 140500) {
+       if (dotclock >= 100000 && dotclock < 140500) {
                clock->p1 = 2;
                clock->p2 = 10;
                clock->n = 3;
                clock->m1 = 16;
                clock->m2 = 8;
-       } else if (adjusted_mode->clock >= 140500
-                  && adjusted_mode->clock <= 200000) {
+       } else if (dotclock >= 140500 && dotclock <= 200000) {
                clock->p1 = 1;
                clock->p2 = 10;
                clock->n = 6;
                clock->m1 = 12;
                clock->m2 = 8;
        }
+
+       crtc->config.clock_set = true;
 }
 
-static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
-                                    intel_clock_t *clock,
+static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
                                     intel_clock_t *reduced_clock)
 {
-       struct drm_device *dev = crtc->dev;
+       struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       int pipe = intel_crtc->pipe;
+       int pipe = crtc->pipe;
        u32 fp, fp2 = 0;
+       struct dpll *clock = &crtc->config.dpll;
 
        if (IS_PINEVIEW(dev)) {
                fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
@@ -4172,27 +4205,29 @@ static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
 
        I915_WRITE(FP0(pipe), fp);
 
-       intel_crtc->lowfreq_avail = false;
-       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
+       crtc->lowfreq_avail = false;
+       if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
            reduced_clock && i915_powersave) {
                I915_WRITE(FP1(pipe), fp2);
-               intel_crtc->lowfreq_avail = true;
+               crtc->lowfreq_avail = true;
        } else {
                I915_WRITE(FP1(pipe), fp);
        }
 }
 
-static void vlv_update_pll(struct drm_crtc *crtc,
-                          intel_clock_t *clock, intel_clock_t *reduced_clock,
-                          int num_connectors)
+static void intel_dp_set_m_n(struct intel_crtc *crtc)
 {
-       struct drm_device *dev = crtc->dev;
+       if (crtc->config.has_pch_encoder)
+               intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
+       else
+               intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
+}
+
+static void vlv_update_pll(struct intel_crtc *crtc)
+{
+       struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       struct drm_display_mode *adjusted_mode =
-               &intel_crtc->config.adjusted_mode;
-       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
-       int pipe = intel_crtc->pipe;
+       int pipe = crtc->pipe;
        u32 dpll, mdiv, pdiv;
        u32 bestn, bestm1, bestm2, bestp1, bestp2;
        bool is_sdvo;
@@ -4200,8 +4235,8 @@ static void vlv_update_pll(struct drm_crtc *crtc,
 
        mutex_lock(&dev_priv->dpio_lock);
 
-       is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
-               intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
+       is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
+               intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
 
        dpll = DPLL_VGA_MODE_DIS;
        dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
@@ -4211,11 +4246,11 @@ static void vlv_update_pll(struct drm_crtc *crtc,
        I915_WRITE(DPLL(pipe), dpll);
        POSTING_READ(DPLL(pipe));
 
-       bestn = clock->n;
-       bestm1 = clock->m1;
-       bestm2 = clock->m2;
-       bestp1 = clock->p1;
-       bestp2 = clock->p2;
+       bestn = crtc->config.dpll.n;
+       bestm1 = crtc->config.dpll.m1;
+       bestm2 = crtc->config.dpll.m2;
+       bestp1 = crtc->config.dpll.p1;
+       bestp2 = crtc->config.dpll.p2;
 
        /*
         * In Valleyview PLL and program lane counter registers are exposed
@@ -4247,8 +4282,8 @@ static void vlv_update_pll(struct drm_crtc *crtc,
 
        intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
 
-       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
-               intel_dp_set_m_n(crtc, mode, adjusted_mode);
+       if (crtc->config.has_dp_encoder)
+               intel_dp_set_m_n(crtc);
 
        I915_WRITE(DPLL(pipe), dpll);
 
@@ -4259,8 +4294,8 @@ static void vlv_update_pll(struct drm_crtc *crtc,
        temp = 0;
        if (is_sdvo) {
                temp = 0;
-               if (intel_crtc->config.pixel_multiplier > 1) {
-                       temp = (intel_crtc->config.pixel_multiplier - 1)
+               if (crtc->config.pixel_multiplier > 1) {
+                       temp = (crtc->config.pixel_multiplier - 1)
                                << DPLL_MD_UDI_MULTIPLIER_SHIFT;
                }
        }
@@ -4268,16 +4303,15 @@ static void vlv_update_pll(struct drm_crtc *crtc,
        POSTING_READ(DPLL_MD(pipe));
 
        /* Now program lane control registers */
-       if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
-                       || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
-       {
+       if(intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)
+          || intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
                temp = 0x1000C4;
                if(pipe == 1)
                        temp |= (1 << 21);
                intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
        }
-       if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
-       {
+
+       if(intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP)) {
                temp = 0x1000C4;
                if(pipe == 1)
                        temp |= (1 << 21);
@@ -4287,42 +4321,39 @@ static void vlv_update_pll(struct drm_crtc *crtc,
        mutex_unlock(&dev_priv->dpio_lock);
 }
 
-static void i9xx_update_pll(struct drm_crtc *crtc,
-                           intel_clock_t *clock, intel_clock_t *reduced_clock,
+static void i9xx_update_pll(struct intel_crtc *crtc,
+                           intel_clock_t *reduced_clock,
                            int num_connectors)
 {
-       struct drm_device *dev = crtc->dev;
+       struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       struct drm_display_mode *adjusted_mode =
-               &intel_crtc->config.adjusted_mode;
-       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
        struct intel_encoder *encoder;
-       int pipe = intel_crtc->pipe;
+       int pipe = crtc->pipe;
        u32 dpll;
        bool is_sdvo;
+       struct dpll *clock = &crtc->config.dpll;
 
-       i9xx_update_pll_dividers(crtc, clock, reduced_clock);
+       i9xx_update_pll_dividers(crtc, reduced_clock);
 
-       is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
-               intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
+       is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
+               intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
 
        dpll = DPLL_VGA_MODE_DIS;
 
-       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
+       if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
                dpll |= DPLLB_MODE_LVDS;
        else
                dpll |= DPLLB_MODE_DAC_SERIAL;
 
        if (is_sdvo) {
-               if ((intel_crtc->config.pixel_multiplier > 1) &&
+               if ((crtc->config.pixel_multiplier > 1) &&
                    (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))) {
-                       dpll |= (intel_crtc->config.pixel_multiplier - 1)
+                       dpll |= (crtc->config.pixel_multiplier - 1)
                                << SDVO_MULTIPLIER_SHIFT_HIRES;
                }
                dpll |= DPLL_DVO_HIGH_SPEED;
        }
-       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
+       if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
                dpll |= DPLL_DVO_HIGH_SPEED;
 
        /* compute bitmask from p1 value */
@@ -4350,13 +4381,13 @@ static void i9xx_update_pll(struct drm_crtc *crtc,
        if (INTEL_INFO(dev)->gen >= 4)
                dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
 
-       if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
+       if (is_sdvo && intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_TVOUT))
                dpll |= PLL_REF_INPUT_TVCLKINBC;
-       else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
+       else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_TVOUT))
                /* XXX: just matching BIOS for now */
                /*      dpll |= PLL_REF_INPUT_TVCLKINBC; */
                dpll |= 3;
-       else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
+       else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
                 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
                dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
        else
@@ -4367,12 +4398,12 @@ static void i9xx_update_pll(struct drm_crtc *crtc,
        POSTING_READ(DPLL(pipe));
        udelay(150);
 
-       for_each_encoder_on_crtc(dev, crtc, encoder)
+       for_each_encoder_on_crtc(dev, &crtc->base, encoder)
                if (encoder->pre_pll_enable)
                        encoder->pre_pll_enable(encoder);
 
-       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
-               intel_dp_set_m_n(crtc, mode, adjusted_mode);
+       if (crtc->config.has_dp_encoder)
+               intel_dp_set_m_n(crtc);
 
        I915_WRITE(DPLL(pipe), dpll);
 
@@ -4384,8 +4415,8 @@ static void i9xx_update_pll(struct drm_crtc *crtc,
                u32 temp = 0;
                if (is_sdvo) {
                        temp = 0;
-                       if (intel_crtc->config.pixel_multiplier > 1) {
-                               temp = (intel_crtc->config.pixel_multiplier - 1)
+                       if (crtc->config.pixel_multiplier > 1) {
+                               temp = (crtc->config.pixel_multiplier - 1)
                                        << DPLL_MD_UDI_MULTIPLIER_SHIFT;
                        }
                }
@@ -4400,23 +4431,23 @@ static void i9xx_update_pll(struct drm_crtc *crtc,
        }
 }
 
-static void i8xx_update_pll(struct drm_crtc *crtc,
+static void i8xx_update_pll(struct intel_crtc *crtc,
                            struct drm_display_mode *adjusted_mode,
-                           intel_clock_t *clock, intel_clock_t *reduced_clock,
+                           intel_clock_t *reduced_clock,
                            int num_connectors)
 {
-       struct drm_device *dev = crtc->dev;
+       struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        struct intel_encoder *encoder;
-       int pipe = intel_crtc->pipe;
+       int pipe = crtc->pipe;
        u32 dpll;
+       struct dpll *clock = &crtc->config.dpll;
 
-       i9xx_update_pll_dividers(crtc, clock, reduced_clock);
+       i9xx_update_pll_dividers(crtc, reduced_clock);
 
        dpll = DPLL_VGA_MODE_DIS;
 
-       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
+       if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
                dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
        } else {
                if (clock->p1 == 2)
@@ -4427,7 +4458,7 @@ static void i8xx_update_pll(struct drm_crtc *crtc,
                        dpll |= PLL_P2_DIVIDE_BY_4;
        }
 
-       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
+       if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
                 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
                dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
        else
@@ -4438,7 +4469,7 @@ static void i8xx_update_pll(struct drm_crtc *crtc,
        POSTING_READ(DPLL(pipe));
        udelay(150);
 
-       for_each_encoder_on_crtc(dev, crtc, encoder)
+       for_each_encoder_on_crtc(dev, &crtc->base, encoder)
                if (encoder->pre_pll_enable)
                        encoder->pre_pll_enable(encoder);
 
@@ -4514,6 +4545,75 @@ static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
                   ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
 }
 
+static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
+{
+       struct drm_device *dev = intel_crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       uint32_t pipeconf;
+
+       pipeconf = I915_READ(PIPECONF(intel_crtc->pipe));
+
+       if (intel_crtc->pipe == 0 && INTEL_INFO(dev)->gen < 4) {
+               /* Enable pixel doubling when the dot clock is > 90% of the (display)
+                * core speed.
+                *
+                * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
+                * pipe == 0 check?
+                */
+               if (intel_crtc->config.requested_mode.clock >
+                   dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
+                       pipeconf |= PIPECONF_DOUBLE_WIDE;
+               else
+                       pipeconf &= ~PIPECONF_DOUBLE_WIDE;
+       }
+
+       /* default to 8bpc */
+       pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
+       if (intel_crtc->config.has_dp_encoder) {
+               if (intel_crtc->config.dither) {
+                       pipeconf |= PIPECONF_6BPC |
+                                   PIPECONF_DITHER_EN |
+                                   PIPECONF_DITHER_TYPE_SP;
+               }
+       }
+
+       if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(&intel_crtc->base,
+                                                     INTEL_OUTPUT_EDP)) {
+               if (intel_crtc->config.dither) {
+                       pipeconf |= PIPECONF_6BPC |
+                                       PIPECONF_ENABLE |
+                                       I965_PIPECONF_ACTIVE;
+               }
+       }
+
+       if (HAS_PIPE_CXSR(dev)) {
+               if (intel_crtc->lowfreq_avail) {
+                       DRM_DEBUG_KMS("enabling CxSR downclocking\n");
+                       pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
+               } else {
+                       DRM_DEBUG_KMS("disabling CxSR downclocking\n");
+                       pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
+               }
+       }
+
+       pipeconf &= ~PIPECONF_INTERLACE_MASK;
+       if (!IS_GEN2(dev) &&
+           intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
+               pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
+       else
+               pipeconf |= PIPECONF_PROGRESSIVE;
+
+       if (IS_VALLEYVIEW(dev)) {
+               if (intel_crtc->config.limited_color_range)
+                       pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
+               else
+                       pipeconf &= ~PIPECONF_COLOR_RANGE_SELECT;
+       }
+
+       I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
+       POSTING_READ(PIPECONF(intel_crtc->pipe));
+}
+
 static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
                              int x, int y,
                              struct drm_framebuffer *fb)
@@ -4528,9 +4628,9 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
        int plane = intel_crtc->plane;
        int refclk, num_connectors = 0;
        intel_clock_t clock, reduced_clock;
-       u32 dspcntr, pipeconf;
+       u32 dspcntr;
        bool ok, has_reduced_clock = false, is_sdvo = false;
-       bool is_lvds = false, is_tv = false, is_dp = false;
+       bool is_lvds = false, is_tv = false;
        struct intel_encoder *encoder;
        const intel_limit_t *limit;
        int ret;
@@ -4549,9 +4649,6 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
                case INTEL_OUTPUT_TVOUT:
                        is_tv = true;
                        break;
-               case INTEL_OUTPUT_DISPLAYPORT:
-                       is_dp = true;
-                       break;
                }
 
                num_connectors++;
@@ -4588,26 +4685,29 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
                                                    &clock,
                                                    &reduced_clock);
        }
+       /* Compat-code for transition, will disappear. */
+       if (!intel_crtc->config.clock_set) {
+               intel_crtc->config.dpll.n = clock.n;
+               intel_crtc->config.dpll.m1 = clock.m1;
+               intel_crtc->config.dpll.m2 = clock.m2;
+               intel_crtc->config.dpll.p1 = clock.p1;
+               intel_crtc->config.dpll.p2 = clock.p2;
+       }
 
        if (is_sdvo && is_tv)
-               i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
+               i9xx_adjust_sdvo_tv_clock(intel_crtc);
 
        if (IS_GEN2(dev))
-               i8xx_update_pll(crtc, adjusted_mode, &clock,
+               i8xx_update_pll(intel_crtc, adjusted_mode,
                                has_reduced_clock ? &reduced_clock : NULL,
                                num_connectors);
        else if (IS_VALLEYVIEW(dev))
-               vlv_update_pll(crtc, &clock,
-                               has_reduced_clock ? &reduced_clock : NULL,
-                               num_connectors);
+               vlv_update_pll(intel_crtc);
        else
-               i9xx_update_pll(crtc, &clock,
+               i9xx_update_pll(intel_crtc,
                                has_reduced_clock ? &reduced_clock : NULL,
                                num_connectors);
 
-       /* setup pipeconf */
-       pipeconf = I915_READ(PIPECONF(pipe));
-
        /* Set up the display plane register */
        dspcntr = DISPPLANE_GAMMA_ENABLE;
 
@@ -4618,58 +4718,9 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
                        dspcntr |= DISPPLANE_SEL_PIPE_B;
        }
 
-       if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
-               /* Enable pixel doubling when the dot clock is > 90% of the (display)
-                * core speed.
-                *
-                * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
-                * pipe == 0 check?
-                */
-               if (mode->clock >
-                   dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
-                       pipeconf |= PIPECONF_DOUBLE_WIDE;
-               else
-                       pipeconf &= ~PIPECONF_DOUBLE_WIDE;
-       }
-
-       /* default to 8bpc */
-       pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
-       if (is_dp) {
-               if (intel_crtc->config.dither) {
-                       pipeconf |= PIPECONF_6BPC |
-                                   PIPECONF_DITHER_EN |
-                                   PIPECONF_DITHER_TYPE_SP;
-               }
-       }
-
-       if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
-               if (intel_crtc->config.dither) {
-                       pipeconf |= PIPECONF_6BPC |
-                                       PIPECONF_ENABLE |
-                                       I965_PIPECONF_ACTIVE;
-               }
-       }
-
        DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
        drm_mode_debug_printmodeline(mode);
 
-       if (HAS_PIPE_CXSR(dev)) {
-               if (intel_crtc->lowfreq_avail) {
-                       DRM_DEBUG_KMS("enabling CxSR downclocking\n");
-                       pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
-               } else {
-                       DRM_DEBUG_KMS("disabling CxSR downclocking\n");
-                       pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
-               }
-       }
-
-       pipeconf &= ~PIPECONF_INTERLACE_MASK;
-       if (!IS_GEN2(dev) &&
-           adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
-               pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
-       else
-               pipeconf |= PIPECONF_PROGRESSIVE;
-
        intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
 
        /* pipesrc and dspsize control the size that is scaled from,
@@ -4680,8 +4731,8 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
                   (mode->hdisplay - 1));
        I915_WRITE(DSPPOS(plane), 0);
 
-       I915_WRITE(PIPECONF(pipe), pipeconf);
-       POSTING_READ(PIPECONF(pipe));
+       i9xx_set_pipeconf(intel_crtc);
+
        intel_enable_pipe(dev_priv, pipe, false);
 
        intel_wait_for_vblank(dev, pipe);
@@ -4696,6 +4747,20 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
        return ret;
 }
 
+static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
+                                struct intel_crtc_config *pipe_config)
+{
+       struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       uint32_t tmp;
+
+       tmp = I915_READ(PIPECONF(crtc->pipe));
+       if (!(tmp & PIPECONF_ENABLE))
+               return false;
+
+       return true;
+}
+
 static void ironlake_init_pch_refclk(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -4911,13 +4976,6 @@ static void lpt_init_pch_refclk(struct drm_device *dev)
        tmp |= (0x12 << 24);
        intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
 
-       if (!is_sdv) {
-               tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
-               tmp &= ~(0x3 << 6);
-               tmp |= (1 << 6) | (1 << 0);
-               intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
-       }
-
        if (is_sdv) {
                tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
                tmp |= 0x7FFF;
@@ -5255,7 +5313,7 @@ static bool ironlake_compute_clocks(struct drm_crtc *crtc,
        }
 
        if (is_sdvo && is_tv)
-               i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
+               i9xx_adjust_sdvo_tv_clock(to_intel_crtc(crtc));
 
        return true;
 }
@@ -5353,62 +5411,65 @@ int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
        return bps / (link_bw * 8) + 1;
 }
 
-static void ironlake_set_m_n(struct drm_crtc *crtc)
+void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
+                                 struct intel_link_m_n *m_n)
 {
-       struct drm_device *dev = crtc->dev;
+       struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       int pipe = crtc->pipe;
+
+       I915_WRITE(TRANSDATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
+       I915_WRITE(TRANSDATA_N1(pipe), m_n->gmch_n);
+       I915_WRITE(TRANSDPLINK_M1(pipe), m_n->link_m);
+       I915_WRITE(TRANSDPLINK_N1(pipe), m_n->link_n);
+}
+
+void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
+                                 struct intel_link_m_n *m_n)
+{
+       struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
+       int pipe = crtc->pipe;
+       enum transcoder transcoder = crtc->cpu_transcoder;
+
+       if (INTEL_INFO(dev)->gen >= 5) {
+               I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
+               I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
+               I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
+               I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
+       } else {
+               I915_WRITE(PIPE_GMCH_DATA_M(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
+               I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n->gmch_n);
+               I915_WRITE(PIPE_DP_LINK_M(pipe), m_n->link_m);
+               I915_WRITE(PIPE_DP_LINK_N(pipe), m_n->link_n);
+       }
+}
+
+static void ironlake_fdi_set_m_n(struct drm_crtc *crtc)
+{
+       struct drm_device *dev = crtc->dev;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        struct drm_display_mode *adjusted_mode =
                &intel_crtc->config.adjusted_mode;
-       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
-       enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
-       struct intel_encoder *intel_encoder, *edp_encoder = NULL;
        struct intel_link_m_n m_n = {0};
        int target_clock, lane, link_bw;
-       bool is_dp = false, is_cpu_edp = false;
 
-       for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-               switch (intel_encoder->type) {
-               case INTEL_OUTPUT_DISPLAYPORT:
-                       is_dp = true;
-                       break;
-               case INTEL_OUTPUT_EDP:
-                       is_dp = true;
-                       if (!intel_encoder_is_pch_edp(&intel_encoder->base))
-                               is_cpu_edp = true;
-                       edp_encoder = intel_encoder;
-                       break;
-               }
-       }
-
-       /* FDI link */
-       lane = 0;
-       /* CPU eDP doesn't require FDI link, so just set DP M/N
-          according to current link config */
-       if (is_cpu_edp) {
-               intel_edp_link_config(edp_encoder, &lane, &link_bw);
-       } else {
-               /* FDI is a binary signal running at ~2.7GHz, encoding
-                * each output octet as 10 bits. The actual frequency
-                * is stored as a divider into a 100MHz clock, and the
-                * mode pixel clock is stored in units of 1KHz.
-                * Hence the bw of each lane in terms of the mode signal
-                * is:
-                */
-               link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
-       }
+       /* FDI is a binary signal running at ~2.7GHz, encoding
+        * each output octet as 10 bits. The actual frequency
+        * is stored as a divider into a 100MHz clock, and the
+        * mode pixel clock is stored in units of 1KHz.
+        * Hence the bw of each lane in terms of the mode signal
+        * is:
+        */
+       link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
 
-       /* [e]DP over FDI requires target mode clock instead of link clock. */
-       if (edp_encoder)
-               target_clock = intel_edp_target_clock(edp_encoder, mode);
-       else if (is_dp)
-               target_clock = mode->clock;
+       if (intel_crtc->config.pixel_target_clock)
+               target_clock = intel_crtc->config.pixel_target_clock;
        else
                target_clock = adjusted_mode->clock;
 
-       if (!lane)
-               lane = ironlake_get_lanes_required(target_clock, link_bw,
-                                                  intel_crtc->config.pipe_bpp);
+       lane = ironlake_get_lanes_required(target_clock, link_bw,
+                                          intel_crtc->config.pipe_bpp);
 
        intel_crtc->fdi_lanes = lane;
 
@@ -5417,14 +5478,12 @@ static void ironlake_set_m_n(struct drm_crtc *crtc)
        intel_link_compute_m_n(intel_crtc->config.pipe_bpp, lane, target_clock,
                               link_bw, &m_n);
 
-       I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
-       I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
-       I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
-       I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
+       intel_cpu_transcoder_set_m_n(intel_crtc, &m_n);
 }
 
 static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
-                                     intel_clock_t *clock, u32 fp)
+                                     intel_clock_t *clock, u32 *fp,
+                                     intel_clock_t *reduced_clock, u32 *fp2)
 {
        struct drm_crtc *crtc = &intel_crtc->base;
        struct drm_device *dev = crtc->dev;
@@ -5433,7 +5492,6 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
        uint32_t dpll;
        int factor, num_connectors = 0;
        bool is_lvds = false, is_sdvo = false, is_tv = false;
-       bool is_dp = false, is_cpu_edp = false;
 
        for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
                switch (intel_encoder->type) {
@@ -5449,14 +5507,6 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
                case INTEL_OUTPUT_TVOUT:
                        is_tv = true;
                        break;
-               case INTEL_OUTPUT_DISPLAYPORT:
-                       is_dp = true;
-                       break;
-               case INTEL_OUTPUT_EDP:
-                       is_dp = true;
-                       if (!intel_encoder_is_pch_edp(&intel_encoder->base))
-                               is_cpu_edp = true;
-                       break;
                }
 
                num_connectors++;
@@ -5467,13 +5517,16 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
        if (is_lvds) {
                if ((intel_panel_use_ssc(dev_priv) &&
                     dev_priv->lvds_ssc_freq == 100) ||
-                   intel_is_dual_link_lvds(dev))
+                   (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
                        factor = 25;
        } else if (is_sdvo && is_tv)
                factor = 20;
 
        if (clock->m < factor * clock->n)
-               fp |= FP_CB_TUNE;
+               *fp |= FP_CB_TUNE;
+
+       if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
+               *fp2 |= FP_CB_TUNE;
 
        dpll = 0;
 
@@ -5488,7 +5541,8 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
                }
                dpll |= DPLL_DVO_HIGH_SPEED;
        }
-       if (is_dp && !is_cpu_edp)
+       if (intel_crtc->config.has_dp_encoder &&
+           intel_crtc->config.has_pch_encoder)
                dpll |= DPLL_DVO_HIGH_SPEED;
 
        /* compute bitmask from p1 value */
@@ -5541,7 +5595,7 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
        intel_clock_t clock, reduced_clock;
        u32 dpll, fp = 0, fp2 = 0;
        bool ok, has_reduced_clock = false;
-       bool is_lvds = false, is_dp = false, is_cpu_edp = false;
+       bool is_lvds = false;
        struct intel_encoder *encoder;
        int ret;
        bool dither, fdi_config_ok;
@@ -5551,14 +5605,6 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
                case INTEL_OUTPUT_LVDS:
                        is_lvds = true;
                        break;
-               case INTEL_OUTPUT_DISPLAYPORT:
-                       is_dp = true;
-                       break;
-               case INTEL_OUTPUT_EDP:
-                       is_dp = true;
-                       if (!intel_encoder_is_pch_edp(&encoder->base))
-                               is_cpu_edp = true;
-                       break;
                }
 
                num_connectors++;
@@ -5567,12 +5613,22 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
        WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
             "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
 
+       intel_crtc->cpu_transcoder = pipe;
+
        ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
                                     &has_reduced_clock, &reduced_clock);
        if (!ok) {
                DRM_ERROR("Couldn't find PLL settings for mode!\n");
                return -EINVAL;
        }
+       /* Compat-code for transition, will disappear. */
+       if (!intel_crtc->config.clock_set) {
+               intel_crtc->config.dpll.n = clock.n;
+               intel_crtc->config.dpll.m1 = clock.m1;
+               intel_crtc->config.dpll.m2 = clock.m2;
+               intel_crtc->config.dpll.p1 = clock.p1;
+               intel_crtc->config.dpll.p2 = clock.p2;
+       }
 
        /* Ensure that the cursor is valid for the new mode before changing... */
        intel_crtc_update_cursor(crtc, true);
@@ -5587,13 +5643,14 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
                fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
                        reduced_clock.m2;
 
-       dpll = ironlake_compute_dpll(intel_crtc, &clock, fp);
+       dpll = ironlake_compute_dpll(intel_crtc, &clock, &fp, &reduced_clock,
+                                    has_reduced_clock ? &fp2 : NULL);
 
        DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
        drm_mode_debug_printmodeline(mode);
 
        /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
-       if (!is_cpu_edp) {
+       if (intel_crtc->config.has_pch_encoder) {
                struct intel_pch_pll *pll;
 
                pll = intel_get_pch_pll(intel_crtc, dpll, fp);
@@ -5605,8 +5662,8 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
        } else
                intel_put_pch_pll(intel_crtc);
 
-       if (is_dp && !is_cpu_edp)
-               intel_dp_set_m_n(crtc, mode, adjusted_mode);
+       if (intel_crtc->config.has_dp_encoder)
+               intel_dp_set_m_n(intel_crtc);
 
        for_each_encoder_on_crtc(dev, crtc, encoder)
                if (encoder->pre_pll_enable)
@@ -5641,7 +5698,9 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
 
        /* Note, this also computes intel_crtc->fdi_lanes which is used below in
         * ironlake_check_fdi_lanes. */
-       ironlake_set_m_n(crtc);
+       intel_crtc->fdi_lanes = 0;
+       if (intel_crtc->config.has_pch_encoder)
+               ironlake_fdi_set_m_n(crtc);
 
        fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
 
@@ -5662,6 +5721,23 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
        return fdi_config_ok ? ret : -EINVAL;
 }
 
+static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
+                                    struct intel_crtc_config *pipe_config)
+{
+       struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       uint32_t tmp;
+
+       tmp = I915_READ(PIPECONF(crtc->pipe));
+       if (!(tmp & PIPECONF_ENABLE))
+               return false;
+
+       if (I915_READ(TRANSCONF(crtc->pipe)) & TRANS_ENABLE)
+               pipe_config->has_pch_encoder = true;
+
+       return true;
+}
+
 static void haswell_modeset_global_resources(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -5704,18 +5780,14 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
        int num_connectors = 0;
-       bool is_dp = false, is_cpu_edp = false;
+       bool is_cpu_edp = false;
        struct intel_encoder *encoder;
        int ret;
        bool dither;
 
        for_each_encoder_on_crtc(dev, crtc, encoder) {
                switch (encoder->type) {
-               case INTEL_OUTPUT_DISPLAYPORT:
-                       is_dp = true;
-                       break;
                case INTEL_OUTPUT_EDP:
-                       is_dp = true;
                        if (!intel_encoder_is_pch_edp(&encoder->base))
                                is_cpu_edp = true;
                        break;
@@ -5724,6 +5796,11 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
                num_connectors++;
        }
 
+       if (is_cpu_edp)
+               intel_crtc->cpu_transcoder = TRANSCODER_EDP;
+       else
+               intel_crtc->cpu_transcoder = pipe;
+
        /* We are not sure yet this won't happen. */
        WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
             INTEL_PCH_TYPE(dev));
@@ -5748,15 +5825,15 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
        DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
        drm_mode_debug_printmodeline(mode);
 
-       if (is_dp && !is_cpu_edp)
-               intel_dp_set_m_n(crtc, mode, adjusted_mode);
+       if (intel_crtc->config.has_dp_encoder)
+               intel_dp_set_m_n(intel_crtc);
 
        intel_crtc->lowfreq_avail = false;
 
        intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
 
-       if (!is_dp || is_cpu_edp)
-               ironlake_set_m_n(crtc);
+       if (intel_crtc->config.has_pch_encoder)
+               ironlake_fdi_set_m_n(crtc);
 
        haswell_set_pipeconf(crtc, adjusted_mode, dither);
 
@@ -5775,6 +5852,31 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
        return ret;
 }
 
+static bool haswell_get_pipe_config(struct intel_crtc *crtc,
+                                   struct intel_crtc_config *pipe_config)
+{
+       struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       uint32_t tmp;
+
+       tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
+       if (!(tmp & PIPECONF_ENABLE))
+               return false;
+
+       /*
+        * aswell has only FDI/PCH transcoder A. It is which is connected to
+        * DDI E. So just check whether this pipe is wired to DDI E and whether
+        * the PCH transcoder is on.
+        */
+       tmp = I915_READ(TRANS_DDI_FUNC_CTL(crtc->pipe));
+       if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(PORT_E) &&
+           I915_READ(TRANSCONF(PIPE_A)) & TRANS_ENABLE)
+               pipe_config->has_pch_encoder = true;
+
+
+       return true;
+}
+
 static int intel_crtc_mode_set(struct drm_crtc *crtc,
                               int x, int y,
                               struct drm_framebuffer *fb)
@@ -5790,11 +5892,6 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
        int pipe = intel_crtc->pipe;
        int ret;
 
-       if (IS_HASWELL(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
-               intel_crtc->cpu_transcoder = TRANSCODER_EDP;
-       else
-               intel_crtc->cpu_transcoder = pipe;
-
        drm_vblank_pre_modeset(dev, pipe);
 
        ret = dev_priv->display.crtc_mode_set(crtc, x, y, fb);
@@ -7629,22 +7726,25 @@ intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
        if (crtc->enabled)
                *prepare_pipes |= 1 << intel_crtc->pipe;
 
-       /* We only support modeset on one single crtc, hence we need to do that
-        * only for the passed in crtc iff we change anything else than just
-        * disable crtcs.
-        *
-        * This is actually not true, to be fully compatible with the old crtc
-        * helper we automatically disable _any_ output (i.e. doesn't need to be
-        * connected to the crtc we're modesetting on) if it's disconnected.
-        * Which is a rather nutty api (since changed the output configuration
-        * without userspace's explicit request can lead to confusion), but
-        * alas. Hence we currently need to modeset on all pipes we prepare. */
+       /*
+        * For simplicity do a full modeset on any pipe where the output routing
+        * changed. We could be more clever, but that would require us to be
+        * more careful with calling the relevant encoder->mode_set functions.
+        */
        if (*prepare_pipes)
                *modeset_pipes = *prepare_pipes;
 
        /* ... and mask these out. */
        *modeset_pipes &= ~(*disable_pipes);
        *prepare_pipes &= ~(*disable_pipes);
+
+       /*
+        * HACK: We don't (yet) fully support global modesets. intel_set_config
+        * obies this rule, but the modeset restore mode of
+        * intel_modeset_setup_hw_state does not.
+        */
+       *modeset_pipes &= 1 << intel_crtc->pipe;
+       *prepare_pipes &= 1 << intel_crtc->pipe;
 }
 
 static bool intel_crtc_in_use(struct drm_crtc *crtc)
@@ -7713,12 +7813,29 @@ intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
                            base.head) \
                if (mask & (1 <<(intel_crtc)->pipe)) \
 
+static bool
+intel_pipe_config_compare(struct intel_crtc_config *current_config,
+                         struct intel_crtc_config *pipe_config)
+{
+       if (current_config->has_pch_encoder != pipe_config->has_pch_encoder) {
+               DRM_ERROR("mismatch in has_pch_encoder "
+                         "(expected %i, found %i)\n",
+                         current_config->has_pch_encoder,
+                         pipe_config->has_pch_encoder);
+               return false;
+       }
+
+       return true;
+}
+
 void
 intel_modeset_check_state(struct drm_device *dev)
 {
+       drm_i915_private_t *dev_priv = dev->dev_private;
        struct intel_crtc *crtc;
        struct intel_encoder *encoder;
        struct intel_connector *connector;
+       struct intel_crtc_config pipe_config;
 
        list_for_each_entry(connector, &dev->mode_config.connector_list,
                            base.head) {
@@ -7807,13 +7924,22 @@ intel_modeset_check_state(struct drm_device *dev)
                     "crtc's computed enabled state doesn't match tracked enabled state "
                     "(expected %i, found %i)\n", enabled, crtc->base.enabled);
 
-               assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
+               memset(&pipe_config, 0, sizeof(pipe_config));
+               active = dev_priv->display.get_pipe_config(crtc,
+                                                          &pipe_config);
+               WARN(crtc->active != active,
+                    "crtc active state doesn't match with hw state "
+                    "(expected %i, found %i)\n", crtc->active, active);
+
+               WARN(active &&
+                    !intel_pipe_config_compare(&crtc->config, &pipe_config),
+                    "pipe state doesn't match!\n");
        }
 }
 
-int intel_set_mode(struct drm_crtc *crtc,
-                  struct drm_display_mode *mode,
-                  int x, int y, struct drm_framebuffer *fb)
+static int __intel_set_mode(struct drm_crtc *crtc,
+                           struct drm_display_mode *mode,
+                           int x, int y, struct drm_framebuffer *fb)
 {
        struct drm_device *dev = crtc->dev;
        drm_i915_private_t *dev_priv = dev->dev_private;
@@ -7907,8 +8033,6 @@ done:
        if (ret && crtc->enabled) {
                crtc->hwmode = *saved_hwmode;
                crtc->mode = *saved_mode;
-       } else {
-               intel_modeset_check_state(dev);
        }
 
 out:
@@ -7917,6 +8041,20 @@ out:
        return ret;
 }
 
+int intel_set_mode(struct drm_crtc *crtc,
+                    struct drm_display_mode *mode,
+                    int x, int y, struct drm_framebuffer *fb)
+{
+       int ret;
+
+       ret = __intel_set_mode(crtc, mode, x, y, fb);
+
+       if (ret == 0)
+               intel_modeset_check_state(crtc->dev);
+
+       return ret;
+}
+
 void intel_crtc_restore_mode(struct drm_crtc *crtc)
 {
        intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
@@ -8357,7 +8495,7 @@ static void intel_setup_outputs(struct drm_device *dev)
                I915_WRITE(PFIT_CONTROL, 0);
        }
 
-       if (!(HAS_DDI(dev) && (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)))
+       if (!IS_ULT(dev))
                intel_crt_init(dev);
 
        if (HAS_DDI(dev)) {
@@ -8613,18 +8751,21 @@ static void intel_init_display(struct drm_device *dev)
        struct drm_i915_private *dev_priv = dev->dev_private;
 
        if (HAS_DDI(dev)) {
+               dev_priv->display.get_pipe_config = haswell_get_pipe_config;
                dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
                dev_priv->display.crtc_enable = haswell_crtc_enable;
                dev_priv->display.crtc_disable = haswell_crtc_disable;
                dev_priv->display.off = haswell_crtc_off;
                dev_priv->display.update_plane = ironlake_update_plane;
        } else if (HAS_PCH_SPLIT(dev)) {
+               dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
                dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
                dev_priv->display.crtc_enable = ironlake_crtc_enable;
                dev_priv->display.crtc_disable = ironlake_crtc_disable;
                dev_priv->display.off = ironlake_crtc_off;
                dev_priv->display.update_plane = ironlake_update_plane;
        } else {
+               dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
                dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
                dev_priv->display.crtc_enable = i9xx_crtc_enable;
                dev_priv->display.crtc_disable = i9xx_crtc_disable;
@@ -8867,7 +9008,7 @@ void intel_modeset_init_hw(struct drm_device *dev)
 void intel_modeset_init(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
-       int i, ret;
+       int i, j, ret;
 
        drm_mode_config_init(dev);
 
@@ -8883,6 +9024,9 @@ void intel_modeset_init(struct drm_device *dev)
 
        intel_init_pm(dev);
 
+       if (INTEL_INFO(dev)->num_pipes == 0)
+               return;
+
        intel_init_display(dev);
 
        if (IS_GEN2(dev)) {
@@ -8903,9 +9047,12 @@ void intel_modeset_init(struct drm_device *dev)
 
        for (i = 0; i < INTEL_INFO(dev)->num_pipes; i++) {
                intel_crtc_init(dev, i);
-               ret = intel_plane_init(dev, i);
-               if (ret)
-                       DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
+               for (j = 0; j < dev_priv->num_plane; j++) {
+                       ret = intel_plane_init(dev, i, j);
+                       if (ret)
+                               DRM_DEBUG_KMS("pipe %d plane %d init failed: %d\n",
+                                             i, j, ret);
+               }
        }
 
        intel_cpu_pll_init(dev);
@@ -9156,14 +9303,11 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
        }
 
 setup_pipes:
-       for_each_pipe(pipe) {
-               crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
-
-               tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
-               if (tmp & PIPECONF_ENABLE)
-                       crtc->active = true;
-               else
-                       crtc->active = false;
+       list_for_each_entry(crtc, &dev->mode_config.crtc_list,
+                           base.head) {
+               memset(&crtc->config, 0, sizeof(crtc->config));
+               crtc->active = dev_priv->display.get_pipe_config(crtc,
+                                                                &crtc->config);
 
                crtc->base.enabled = crtc->active;
 
@@ -9222,10 +9366,16 @@ setup_pipes:
        }
 
        if (force_restore) {
+               /*
+                * We need to use raw interfaces for restoring state to avoid
+                * checking (bogus) intermediate states.
+                */
                for_each_pipe(pipe) {
                        struct drm_crtc *crtc =
                                dev_priv->pipe_to_crtc_mapping[pipe];
-                       intel_crtc_restore_mode(crtc);
+
+                       __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
+                                        crtc->fb);
                }
                list_for_each_entry(plane, &dev->mode_config.plane_list, head)
                        intel_plane_restore(plane);
@@ -9290,6 +9440,9 @@ void intel_modeset_cleanup(struct drm_device *dev)
        /* flush any delayed tasks or pending work */
        flush_scheduled_work();
 
+       /* destroy backlight, if any, before the connectors */
+       intel_panel_destroy_backlight(dev);
+
        drm_mode_config_cleanup(dev);
 
        intel_cleanup_overlay(dev);