]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - drivers/gpu/drm/i915/intel_display.c
drm/i915: fix VLV limits
[mirror_ubuntu-hirsute-kernel.git] / drivers / gpu / drm / i915 / intel_display.c
index 2db50e234c2c5acab710b5f469425c5822d4ae44..bdbad762134c6d12076563c277043c5137a1b972 100644 (file)
@@ -396,15 +396,15 @@ static const intel_limit_t intel_limits_vlv_dac = {
        .m1 = { .min = 2, .max = 3 },
        .m2 = { .min = 11, .max = 156 },
        .p = { .min = 10, .max = 30 },
-       .p1 = { .min = 2, .max = 3 },
+       .p1 = { .min = 1, .max = 3 },
        .p2 = { .dot_limit = 270000,
                .p2_slow = 2, .p2_fast = 20 },
        .find_pll = intel_vlv_find_best_pll,
 };
 
 static const intel_limit_t intel_limits_vlv_hdmi = {
-       .dot = { .min = 20000, .max = 165000 },
-       .vco = { .min = 4000000, .max = 5994000},
+       .dot = { .min = 25000, .max = 270000 },
+       .vco = { .min = 4000000, .max = 6000000 },
        .n = { .min = 1, .max = 7 },
        .m = { .min = 60, .max = 300 }, /* guess */
        .m1 = { .min = 2, .max = 3 },
@@ -424,7 +424,7 @@ static const intel_limit_t intel_limits_vlv_dp = {
        .m1 = { .min = 2, .max = 3 },
        .m2 = { .min = 11, .max = 156 },
        .p = { .min = 10, .max = 30 },
-       .p1 = { .min = 2, .max = 3 },
+       .p1 = { .min = 1, .max = 3 },
        .p2 = { .dot_limit = 270000,
                .p2_slow = 2, .p2_fast = 20 },
        .find_pll = intel_vlv_find_best_pll,
@@ -892,7 +892,7 @@ enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
        struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 
-       return intel_crtc->cpu_transcoder;
+       return intel_crtc->config.cpu_transcoder;
 }
 
 static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
@@ -1097,14 +1097,14 @@ static void assert_pch_pll(struct drm_i915_private *dev_priv,
                pch_dpll = I915_READ(PCH_DPLL_SEL);
                cur_state = pll->pll_reg == _PCH_DPLL_B;
                if (!WARN(((pch_dpll >> (4 * crtc->pipe)) & 1) != cur_state,
-                         "PLL[%d] not attached to this transcoder %d: %08x\n",
-                         cur_state, crtc->pipe, pch_dpll)) {
+                         "PLL[%d] not attached to this transcoder %c: %08x\n",
+                         cur_state, pipe_name(crtc->pipe), pch_dpll)) {
                        cur_state = !!(val >> (4*crtc->pipe + 3));
                        WARN(cur_state != state,
-                            "PLL[%d] not %s on this transcoder %d: %08x\n",
+                            "PLL[%d] not %s on this transcoder %c: %08x\n",
                             pll->pll_reg == _PCH_DPLL_B,
                             state_string(state),
-                            crtc->pipe,
+                            pipe_name(crtc->pipe),
                             val);
                }
        }
@@ -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 %c assertion failure, should be off on pipe %c but is still active\n",
+                    sprite_name(pipe, i), pipe_name(pipe));
+       }
+}
+
 static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
 {
        u32 val;
@@ -1455,6 +1474,8 @@ static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
        int reg;
        u32 val;
 
+       assert_pipe_disabled(dev_priv, pipe);
+
        /* No really, not for ILK+ */
        BUG_ON(!IS_VALLEYVIEW(dev_priv->dev) && dev_priv->info->gen >= 5);
 
@@ -1712,7 +1733,7 @@ static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
 
        I915_WRITE(reg, val | TRANS_ENABLE);
        if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
-               DRM_ERROR("failed to enable transcoder %d\n", pipe);
+               DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
 }
 
 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
@@ -1765,7 +1786,7 @@ static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
        I915_WRITE(reg, val);
        /* wait for PCH transcoder off, transcoder state */
        if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
-               DRM_ERROR("failed to disable transcoder %d\n", pipe);
+               DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
 
        if (!HAS_PCH_IBX(dev)) {
                /* Workaround: Clear the timing override chicken bit again. */
@@ -1816,6 +1837,9 @@ static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
        int reg;
        u32 val;
 
+       assert_planes_disabled(dev_priv, pipe);
+       assert_sprites_disabled(dev_priv, pipe);
+
        if (HAS_PCH_LPT(dev_priv->dev))
                pch_transcoder = TRANSCODER_A;
        else
@@ -1872,6 +1896,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 +2007,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();
@@ -2074,7 +2101,7 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
        case 1:
                break;
        default:
-               DRM_ERROR("Can't update plane %d in SAREA\n", plane);
+               DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane));
                return -EINVAL;
        }
 
@@ -2113,8 +2140,7 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
                dspcntr |= DISPPLANE_RGBX101010;
                break;
        default:
-               DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
-               return -EINVAL;
+               BUG();
        }
 
        if (INTEL_INFO(dev)->gen >= 4) {
@@ -2172,7 +2198,7 @@ static int ironlake_update_plane(struct drm_crtc *crtc,
        case 2:
                break;
        default:
-               DRM_ERROR("Can't update plane %d in SAREA\n", plane);
+               DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane));
                return -EINVAL;
        }
 
@@ -2207,8 +2233,7 @@ static int ironlake_update_plane(struct drm_crtc *crtc,
                dspcntr |= DISPPLANE_RGBX101010;
                break;
        default:
-               DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
-               return -EINVAL;
+               BUG();
        }
 
        if (obj->tiling_mode != I915_TILING_NONE)
@@ -2364,9 +2389,9 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
        }
 
        if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
-               DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
-                               intel_crtc->plane,
-                               INTEL_INFO(dev)->num_pipes);
+               DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
+                         plane_name(intel_crtc->plane),
+                         INTEL_INFO(dev)->num_pipes);
                return -EINVAL;
        }
 
@@ -2977,32 +3002,6 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
        mutex_unlock(&dev->struct_mutex);
 }
 
-static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
-{
-       struct drm_device *dev = crtc->dev;
-       struct intel_encoder *intel_encoder;
-
-       /*
-        * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
-        * must be driven by its own crtc; no sharing is possible.
-        */
-       for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-               switch (intel_encoder->type) {
-               case INTEL_OUTPUT_EDP:
-                       if (!intel_encoder_is_pch_edp(&intel_encoder->base))
-                               return false;
-                       continue;
-               }
-       }
-
-       return true;
-}
-
-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)
 {
@@ -3209,7 +3208,7 @@ static void lpt_pch_enable(struct drm_crtc *crtc)
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
+       enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
 
        assert_transcoder_disabled(dev_priv, TRANSCODER_A);
 
@@ -3300,7 +3299,7 @@ static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u3
 found:
        intel_crtc->pch_pll = pll;
        pll->refcount++;
-       DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
+       DRM_DEBUG_DRIVER("using pll %d for pipe %c\n", i, pipe_name(intel_crtc->pipe));
 prepare: /* separate function? */
        DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
 
@@ -3325,7 +3324,7 @@ void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
        udelay(500);
        if (wait_for(I915_READ(dslreg) != temp, 5)) {
                if (wait_for(I915_READ(dslreg) != temp, 5))
-                       DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
+                       DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
        }
 }
 
@@ -3338,7 +3337,6 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
        u32 temp;
-       bool is_pch_port;
 
        WARN_ON(!crtc->enabled);
 
@@ -3354,9 +3352,8 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
                        I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
        }
 
-       is_pch_port = ironlake_crtc_driving_pch(crtc);
 
-       if (is_pch_port) {
+       if (intel_crtc->config.has_pch_encoder) {
                /* Note: FDI PLL enabling _must_ be done before we enable the
                 * cpu pipes, hence this is separate from all the other fdi/pch
                 * enabling. */
@@ -3393,10 +3390,11 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
         */
        intel_crtc_load_lut(crtc);
 
-       intel_enable_pipe(dev_priv, pipe, is_pch_port);
+       intel_enable_pipe(dev_priv, pipe,
+                         intel_crtc->config.has_pch_encoder);
        intel_enable_plane(dev_priv, plane, pipe);
 
-       if (is_pch_port)
+       if (intel_crtc->config.has_pch_encoder)
                ironlake_pch_enable(crtc);
 
        mutex_lock(&dev->struct_mutex);
@@ -3430,7 +3428,6 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
-       bool is_pch_port;
 
        WARN_ON(!crtc->enabled);
 
@@ -3440,9 +3437,7 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        intel_crtc->active = true;
        intel_update_watermarks(dev);
 
-       is_pch_port = haswell_crtc_driving_pch(crtc);
-
-       if (is_pch_port)
+       if (intel_crtc->config.has_pch_encoder)
                dev_priv->display.fdi_link_train(crtc);
 
        for_each_encoder_on_crtc(dev, crtc, encoder)
@@ -3473,10 +3468,11 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        intel_ddi_set_pipe_settings(crtc);
        intel_ddi_enable_transcoder_func(crtc);
 
-       intel_enable_pipe(dev_priv, pipe, is_pch_port);
+       intel_enable_pipe(dev_priv, pipe,
+                         intel_crtc->config.has_pch_encoder);
        intel_enable_plane(dev_priv, plane, pipe);
 
-       if (is_pch_port)
+       if (intel_crtc->config.has_pch_encoder)
                lpt_pch_enable(crtc);
 
        mutex_lock(&dev->struct_mutex);
@@ -3587,14 +3583,11 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
-       enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
-       bool is_pch_port;
+       enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
 
        if (!intel_crtc->active)
                return;
 
-       is_pch_port = haswell_crtc_driving_pch(crtc);
-
        for_each_encoder_on_crtc(dev, crtc, encoder)
                encoder->disable(encoder);
 
@@ -3611,9 +3604,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);
 
@@ -3621,7 +3618,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);
        }
@@ -3646,7 +3643,7 @@ static void haswell_crtc_off(struct drm_crtc *crtc)
 
        /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
         * start using it. */
-       intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
+       intel_crtc->config.cpu_transcoder = (enum transcoder) intel_crtc->pipe;
 
        intel_ddi_put_crtc_pll(crtc);
 }
@@ -3732,6 +3729,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;
@@ -3740,8 +3757,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;
@@ -3761,11 +3776,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);
 
@@ -3971,22 +3982,23 @@ bool intel_connector_get_hw_state(struct intel_connector *connector)
        return encoder->get_hw_state(encoder, &pipe);
 }
 
-static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
-                                 const struct drm_display_mode *mode,
-                                 struct drm_display_mode *adjusted_mode)
+static bool intel_crtc_compute_config(struct drm_crtc *crtc,
+                                     struct intel_crtc_config *pipe_config)
 {
        struct drm_device *dev = crtc->dev;
+       struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
 
        if (HAS_PCH_SPLIT(dev)) {
                /* FDI link clock is fixed at 2.7G */
-               if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
+               if (pipe_config->requested_mode.clock * 3
+                   > IRONLAKE_FDI_FREQ * 4)
                        return false;
        }
 
        /* All interlaced capable intel hw wants timings in frames. Note though
         * that intel_lvds_mode_fixup does some funny tricks with the crtc
         * timings, so we need to be careful not to clobber these.*/
-       if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
+       if (!pipe_config->timings_set)
                drm_mode_set_crtcinfo(adjusted_mode, 0);
 
        /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
@@ -3996,6 +4008,14 @@ static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
                adjusted_mode->hsync_start == adjusted_mode->hdisplay)
                return false;
 
+       if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
+               pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
+       } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
+               /* only a 8bpc pipe, with 6bpc dither through the panel fitter
+                * for lvds. */
+               pipe_config->pipe_bpp = 8*3;
+       }
+
        return true;
 }
 
@@ -4099,142 +4119,6 @@ static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
                && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
 }
 
-/**
- * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
- * @crtc: CRTC structure
- * @mode: requested mode
- *
- * A pipe may be connected to one or more outputs.  Based on the depth of the
- * attached framebuffer, choose a good color depth to use on the pipe.
- *
- * If possible, match the pipe depth to the fb depth.  In some cases, this
- * isn't ideal, because the connected output supports a lesser or restricted
- * set of depths.  Resolve that here:
- *    LVDS typically supports only 6bpc, so clamp down in that case
- *    HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
- *    Displays may support a restricted set as well, check EDID and clamp as
- *      appropriate.
- *    DP may want to dither down to 6bpc to fit larger modes
- *
- * RETURNS:
- * Dithering requirement (i.e. false if display bpc and pipe bpc match,
- * true if they don't match).
- */
-static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
-                                        struct drm_framebuffer *fb,
-                                        unsigned int *pipe_bpp,
-                                        struct drm_display_mode *mode)
-{
-       struct drm_device *dev = crtc->dev;
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       struct drm_connector *connector;
-       struct intel_encoder *intel_encoder;
-       unsigned int display_bpc = UINT_MAX, bpc;
-
-       /* Walk the encoders & connectors on this crtc, get min bpc */
-       for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-
-               if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
-                       unsigned int lvds_bpc;
-
-                       if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
-                           LVDS_A3_POWER_UP)
-                               lvds_bpc = 8;
-                       else
-                               lvds_bpc = 6;
-
-                       if (lvds_bpc < display_bpc) {
-                               DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
-                               display_bpc = lvds_bpc;
-                       }
-                       continue;
-               }
-
-               /* Not one of the known troublemakers, check the EDID */
-               list_for_each_entry(connector, &dev->mode_config.connector_list,
-                                   head) {
-                       if (connector->encoder != &intel_encoder->base)
-                               continue;
-
-                       /* Don't use an invalid EDID bpc value */
-                       if (connector->display_info.bpc &&
-                           connector->display_info.bpc < display_bpc) {
-                               DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
-                               display_bpc = connector->display_info.bpc;
-                       }
-               }
-
-               if (intel_encoder->type == INTEL_OUTPUT_EDP) {
-                       /* Use VBT settings if we have an eDP panel */
-                       unsigned int edp_bpc = dev_priv->edp.bpp / 3;
-
-                       if (edp_bpc && edp_bpc < display_bpc) {
-                               DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
-                               display_bpc = edp_bpc;
-                       }
-                       continue;
-               }
-
-               /*
-                * HDMI is either 12 or 8, so if the display lets 10bpc sneak
-                * through, clamp it down.  (Note: >12bpc will be caught below.)
-                */
-               if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
-                       if (display_bpc > 8 && display_bpc < 12) {
-                               DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
-                               display_bpc = 12;
-                       } else {
-                               DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
-                               display_bpc = 8;
-                       }
-               }
-       }
-
-       if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
-               DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
-               display_bpc = 6;
-       }
-
-       /*
-        * We could just drive the pipe at the highest bpc all the time and
-        * enable dithering as needed, but that costs bandwidth.  So choose
-        * the minimum value that expresses the full color range of the fb but
-        * also stays within the max display bpc discovered above.
-        */
-
-       switch (fb->depth) {
-       case 8:
-               bpc = 8; /* since we go through a colormap */
-               break;
-       case 15:
-       case 16:
-               bpc = 6; /* min is 18bpp */
-               break;
-       case 24:
-               bpc = 8;
-               break;
-       case 30:
-               bpc = 10;
-               break;
-       case 48:
-               bpc = 12;
-               break;
-       default:
-               DRM_DEBUG("unsupported depth, assuming 24 bits\n");
-               bpc = min((unsigned int)8, display_bpc);
-               break;
-       }
-
-       display_bpc = min(display_bpc, bpc);
-
-       DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
-                     bpc, display_bpc);
-
-       *pipe_bpp = display_bpc * 3;
-
-       return display_bpc != bpc;
-}
-
 static int vlv_get_refclk(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
@@ -4279,37 +4163,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;
@@ -4325,26 +4210,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,
-                          struct drm_display_mode *mode,
-                          struct drm_display_mode *adjusted_mode,
-                          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);
-       int pipe = intel_crtc->pipe;
+       int pipe = crtc->pipe;
        u32 dpll, mdiv, pdiv;
        u32 bestn, bestm1, bestm2, bestp1, bestp2;
        bool is_sdvo;
@@ -4352,8 +4240,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;
@@ -4363,11 +4251,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
@@ -4399,8 +4287,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);
 
@@ -4410,26 +4298,25 @@ static void vlv_update_pll(struct drm_crtc *crtc,
 
        temp = 0;
        if (is_sdvo) {
-               temp = intel_mode_get_pixel_multiplier(adjusted_mode);
-               if (temp > 1)
-                       temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
-               else
-                       temp = 0;
+               temp = 0;
+               if (crtc->config.pixel_multiplier > 1) {
+                       temp = (crtc->config.pixel_multiplier - 1)
+                               << DPLL_MD_UDI_MULTIPLIER_SHIFT;
+               }
        }
        I915_WRITE(DPLL_MD(pipe), temp);
        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);
@@ -4439,40 +4326,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,
-                           struct drm_display_mode *mode,
-                           struct drm_display_mode *adjusted_mode,
-                           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 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) {
-               int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
-               if (pixel_multiplier > 1) {
-                       if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
-                               dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
+               if ((crtc->config.pixel_multiplier > 1) &&
+                   (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))) {
+                       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 */
@@ -4500,13 +4386,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
@@ -4517,12 +4403,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);
 
@@ -4533,11 +4419,11 @@ static void i9xx_update_pll(struct drm_crtc *crtc,
        if (INTEL_INFO(dev)->gen >= 4) {
                u32 temp = 0;
                if (is_sdvo) {
-                       temp = intel_mode_get_pixel_multiplier(adjusted_mode);
-                       if (temp > 1)
-                               temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
-                       else
-                               temp = 0;
+                       temp = 0;
+                       if (crtc->config.pixel_multiplier > 1) {
+                               temp = (crtc->config.pixel_multiplier - 1)
+                                       << DPLL_MD_UDI_MULTIPLIER_SHIFT;
+                       }
                }
                I915_WRITE(DPLL_MD(pipe), temp);
        } else {
@@ -4550,23 +4436,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)
@@ -4577,7 +4463,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
@@ -4588,7 +4474,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);
 
@@ -4613,7 +4499,7 @@ static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
        struct drm_device *dev = intel_crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        enum pipe pipe = intel_crtc->pipe;
-       enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
+       enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
        uint32_t vsyncshift;
 
        if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
@@ -4664,22 +4550,92 @@ 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,
-                             struct drm_display_mode *mode,
-                             struct drm_display_mode *adjusted_mode,
                              int x, int y,
                              struct drm_framebuffer *fb)
 {
        struct drm_device *dev = crtc->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 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;
@@ -4698,9 +4654,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++;
@@ -4737,26 +4690,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, mode, adjusted_mode, &clock,
-                               has_reduced_clock ? &reduced_clock : NULL,
-                               num_connectors);
+               vlv_update_pll(intel_crtc);
        else
-               i9xx_update_pll(crtc, mode, adjusted_mode, &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;
 
@@ -4767,58 +4723,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 (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
-                       pipeconf |= PIPECONF_6BPC |
-                                   PIPECONF_DITHER_EN |
-                                   PIPECONF_DITHER_TYPE_SP;
-               }
-       }
-
-       if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
-               if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
-                       pipeconf |= PIPECONF_6BPC |
-                                       PIPECONF_ENABLE |
-                                       I965_PIPECONF_ACTIVE;
-               }
-       }
-
-       DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
+       DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe_name(pipe));
        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,
@@ -4829,11 +4736,7 @@ 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));
-       intel_enable_pipe(dev_priv, pipe, false);
-
-       intel_wait_for_vblank(dev, pipe);
+       i9xx_set_pipeconf(intel_crtc);
 
        I915_WRITE(DSPCNTR(plane), dspcntr);
        POSTING_READ(DSPCNTR(plane));
@@ -4845,12 +4748,26 @@ 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;
        struct drm_mode_config *mode_config = &dev->mode_config;
        struct intel_encoder *encoder;
-       u32 temp;
+       u32 val, final;
        bool has_lvds = false;
        bool has_cpu_edp = false;
        bool has_pch_edp = false;
@@ -4893,70 +4810,109 @@ static void ironlake_init_pch_refclk(struct drm_device *dev)
         * PCH B stepping, previous chipset stepping should be
         * ignoring this setting.
         */
-       temp = I915_READ(PCH_DREF_CONTROL);
+       val = I915_READ(PCH_DREF_CONTROL);
+
+       /* As we must carefully and slowly disable/enable each source in turn,
+        * compute the final state we want first and check if we need to
+        * make any changes at all.
+        */
+       final = val;
+       final &= ~DREF_NONSPREAD_SOURCE_MASK;
+       if (has_ck505)
+               final |= DREF_NONSPREAD_CK505_ENABLE;
+       else
+               final |= DREF_NONSPREAD_SOURCE_ENABLE;
+
+       final &= ~DREF_SSC_SOURCE_MASK;
+       final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
+       final &= ~DREF_SSC1_ENABLE;
+
+       if (has_panel) {
+               final |= DREF_SSC_SOURCE_ENABLE;
+
+               if (intel_panel_use_ssc(dev_priv) && can_ssc)
+                       final |= DREF_SSC1_ENABLE;
+
+               if (has_cpu_edp) {
+                       if (intel_panel_use_ssc(dev_priv) && can_ssc)
+                               final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
+                       else
+                               final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
+               } else
+                       final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
+       } else {
+               final |= DREF_SSC_SOURCE_DISABLE;
+               final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
+       }
+
+       if (final == val)
+               return;
+
        /* Always enable nonspread source */
-       temp &= ~DREF_NONSPREAD_SOURCE_MASK;
+       val &= ~DREF_NONSPREAD_SOURCE_MASK;
 
        if (has_ck505)
-               temp |= DREF_NONSPREAD_CK505_ENABLE;
+               val |= DREF_NONSPREAD_CK505_ENABLE;
        else
-               temp |= DREF_NONSPREAD_SOURCE_ENABLE;
+               val |= DREF_NONSPREAD_SOURCE_ENABLE;
 
        if (has_panel) {
-               temp &= ~DREF_SSC_SOURCE_MASK;
-               temp |= DREF_SSC_SOURCE_ENABLE;
+               val &= ~DREF_SSC_SOURCE_MASK;
+               val |= DREF_SSC_SOURCE_ENABLE;
 
                /* SSC must be turned on before enabling the CPU output  */
                if (intel_panel_use_ssc(dev_priv) && can_ssc) {
                        DRM_DEBUG_KMS("Using SSC on panel\n");
-                       temp |= DREF_SSC1_ENABLE;
+                       val |= DREF_SSC1_ENABLE;
                } else
-                       temp &= ~DREF_SSC1_ENABLE;
+                       val &= ~DREF_SSC1_ENABLE;
 
                /* Get SSC going before enabling the outputs */
-               I915_WRITE(PCH_DREF_CONTROL, temp);
+               I915_WRITE(PCH_DREF_CONTROL, val);
                POSTING_READ(PCH_DREF_CONTROL);
                udelay(200);
 
-               temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
+               val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
 
                /* Enable CPU source on CPU attached eDP */
                if (has_cpu_edp) {
                        if (intel_panel_use_ssc(dev_priv) && can_ssc) {
                                DRM_DEBUG_KMS("Using SSC on eDP\n");
-                               temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
+                               val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
                        }
                        else
-                               temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
+                               val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
                } else
-                       temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
+                       val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
 
-               I915_WRITE(PCH_DREF_CONTROL, temp);
+               I915_WRITE(PCH_DREF_CONTROL, val);
                POSTING_READ(PCH_DREF_CONTROL);
                udelay(200);
        } else {
                DRM_DEBUG_KMS("Disabling SSC entirely\n");
 
-               temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
+               val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
 
                /* Turn off CPU output */
-               temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
+               val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
 
-               I915_WRITE(PCH_DREF_CONTROL, temp);
+               I915_WRITE(PCH_DREF_CONTROL, val);
                POSTING_READ(PCH_DREF_CONTROL);
                udelay(200);
 
                /* Turn off the SSC source */
-               temp &= ~DREF_SSC_SOURCE_MASK;
-               temp |= DREF_SSC_SOURCE_DISABLE;
+               val &= ~DREF_SSC_SOURCE_MASK;
+               val |= DREF_SSC_SOURCE_DISABLE;
 
                /* Turn off SSC1 */
-               temp &= ~ DREF_SSC1_ENABLE;
+               val &= ~DREF_SSC1_ENABLE;
 
-               I915_WRITE(PCH_DREF_CONTROL, temp);
+               I915_WRITE(PCH_DREF_CONTROL, val);
                POSTING_READ(PCH_DREF_CONTROL);
                udelay(200);
        }
+
+       BUG_ON(val != final);
 }
 
 /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
@@ -5021,13 +4977,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;
@@ -5181,7 +5130,7 @@ static void ironlake_set_pipeconf(struct drm_crtc *crtc,
        val = I915_READ(PIPECONF(pipe));
 
        val &= ~PIPECONF_BPC_MASK;
-       switch (intel_crtc->bpp) {
+       switch (intel_crtc->config.pipe_bpp) {
        case 18:
                val |= PIPECONF_6BPC;
                break;
@@ -5209,7 +5158,7 @@ static void ironlake_set_pipeconf(struct drm_crtc *crtc,
        else
                val |= PIPECONF_PROGRESSIVE;
 
-       if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
+       if (intel_crtc->config.limited_color_range)
                val |= PIPECONF_COLOR_RANGE_SELECT;
        else
                val &= ~PIPECONF_COLOR_RANGE_SELECT;
@@ -5225,8 +5174,7 @@ static void ironlake_set_pipeconf(struct drm_crtc *crtc,
  * is supported, but eventually this should handle various
  * RGB<->YCbCr scenarios as well.
  */
-static void intel_set_pipe_csc(struct drm_crtc *crtc,
-                              const struct drm_display_mode *adjusted_mode)
+static void intel_set_pipe_csc(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -5241,7 +5189,7 @@ static void intel_set_pipe_csc(struct drm_crtc *crtc,
         * consideration.
         */
 
-       if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
+       if (intel_crtc->config.limited_color_range)
                coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
 
        /*
@@ -5265,7 +5213,7 @@ static void intel_set_pipe_csc(struct drm_crtc *crtc,
        if (INTEL_INFO(dev)->gen > 6) {
                uint16_t postoff = 0;
 
-               if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
+               if (intel_crtc->config.limited_color_range)
                        postoff = (16 * (1 << 13) / 255) & 0x1fff;
 
                I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
@@ -5276,7 +5224,7 @@ static void intel_set_pipe_csc(struct drm_crtc *crtc,
        } else {
                uint32_t mode = CSC_MODE_YUV_TO_RGB;
 
-               if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
+               if (intel_crtc->config.limited_color_range)
                        mode |= CSC_BLACK_SCREEN_OFFSET;
 
                I915_WRITE(PIPE_CSC_MODE(pipe), mode);
@@ -5289,7 +5237,7 @@ static void haswell_set_pipeconf(struct drm_crtc *crtc,
 {
        struct drm_i915_private *dev_priv = crtc->dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
+       enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
        uint32_t val;
 
        val = I915_READ(PIPECONF(cpu_transcoder));
@@ -5366,7 +5314,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;
 }
@@ -5396,11 +5344,11 @@ static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
        struct intel_crtc *pipe_B_crtc =
                to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
 
-       DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
-                     intel_crtc->pipe, intel_crtc->fdi_lanes);
+       DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
+                     pipe_name(intel_crtc->pipe), intel_crtc->fdi_lanes);
        if (intel_crtc->fdi_lanes > 4) {
-               DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
-                             intel_crtc->pipe, intel_crtc->fdi_lanes);
+               DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
+                             pipe_name(intel_crtc->pipe), intel_crtc->fdi_lanes);
                /* Clamp lanes to avoid programming the hw with bogus values. */
                intel_crtc->fdi_lanes = 4;
 
@@ -5416,8 +5364,8 @@ static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
        case PIPE_B:
                if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
                    intel_crtc->fdi_lanes > 2) {
-                       DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
-                                     intel_crtc->pipe, intel_crtc->fdi_lanes);
+                       DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
+                                     pipe_name(intel_crtc->pipe), intel_crtc->fdi_lanes);
                        /* Clamp lanes to avoid programming the hw with bogus values. */
                        intel_crtc->fdi_lanes = 2;
 
@@ -5433,8 +5381,8 @@ static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
        case PIPE_C:
                if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
                        if (intel_crtc->fdi_lanes > 2) {
-                               DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
-                                             intel_crtc->pipe, intel_crtc->fdi_lanes);
+                               DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
+                                             pipe_name(intel_crtc->pipe), intel_crtc->fdi_lanes);
                                /* Clamp lanes to avoid programming the hw with bogus values. */
                                intel_crtc->fdi_lanes = 2;
 
@@ -5464,87 +5412,87 @@ 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,
-                            struct drm_display_mode *mode,
-                            struct drm_display_mode *adjusted_mode)
+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;
-       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       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, pixel_multiplier, lane, link_bw;
-       bool is_dp = false, is_cpu_edp = false;
+       int pipe = crtc->pipe;
 
-       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;
-               }
-       }
+       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->config.cpu_transcoder;
 
-       /* FDI link */
-       pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
-       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);
+       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 {
-               /* 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;
+               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);
        }
+}
 
-       /* [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;
+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 intel_link_m_n m_n = {0};
+       int target_clock, lane, link_bw;
+
+       /* 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;
+
+       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->bpp);
+       lane = ironlake_get_lanes_required(target_clock, link_bw,
+                                          intel_crtc->config.pipe_bpp);
 
        intel_crtc->fdi_lanes = lane;
 
-       if (pixel_multiplier > 1)
-               link_bw *= pixel_multiplier;
-       intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
+       if (intel_crtc->config.pixel_multiplier > 1)
+               link_bw *= intel_crtc->config.pixel_multiplier;
+       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,
-                                     struct drm_display_mode *adjusted_mode,
-                                     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;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_encoder *intel_encoder;
        uint32_t dpll;
-       int factor, pixel_multiplier, num_connectors = 0;
+       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) {
@@ -5560,14 +5508,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++;
@@ -5578,13 +5518,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;
 
@@ -5593,13 +5536,14 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
        else
                dpll |= DPLLB_MODE_DAC_SERIAL;
        if (is_sdvo) {
-               pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
-               if (pixel_multiplier > 1) {
-                       dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
+               if (intel_crtc->config.pixel_multiplier > 1) {
+                       dpll |= (intel_crtc->config.pixel_multiplier - 1)
+                               << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
                }
                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 */
@@ -5637,21 +5581,22 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
 }
 
 static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
-                                 struct drm_display_mode *mode,
-                                 struct drm_display_mode *adjusted_mode,
                                  int x, int y,
                                  struct drm_framebuffer *fb)
 {
        struct drm_device *dev = crtc->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 plane = intel_crtc->plane;
        int num_connectors = 0;
        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;
@@ -5661,14 +5606,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++;
@@ -5677,19 +5614,28 @@ 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->config.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);
 
        /* determine panel color depth */
-       dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
-                                             adjusted_mode);
+       dither = intel_crtc->config.dither;
        if (is_lvds && dev_priv->lvds_dither)
                dither = true;
 
@@ -5698,26 +5644,27 @@ 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, adjusted_mode, &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_DEBUG_KMS("Mode for pipe %c:\n", pipe_name(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);
                if (pll == NULL) {
-                       DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
-                                        pipe);
+                       DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
+                                        pipe_name(pipe));
                        return -EINVAL;
                }
        } 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)
@@ -5752,14 +5699,14 @@ 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, mode, adjusted_mode);
+       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);
 
        ironlake_set_pipeconf(crtc, adjusted_mode, dither);
 
-       intel_wait_for_vblank(dev, pipe);
-
        /* Set up the display plane register */
        I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
        POSTING_READ(DSPCNTR(plane));
@@ -5773,6 +5720,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;
@@ -5803,29 +5767,26 @@ static void haswell_modeset_global_resources(struct drm_device *dev)
 }
 
 static int haswell_crtc_mode_set(struct drm_crtc *crtc,
-                                struct drm_display_mode *mode,
-                                struct drm_display_mode *adjusted_mode,
                                 int x, int y,
                                 struct drm_framebuffer *fb)
 {
        struct drm_device *dev = crtc->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 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;
@@ -5834,6 +5795,11 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
                num_connectors++;
        }
 
+       if (is_cpu_edp)
+               intel_crtc->config.cpu_transcoder = TRANSCODER_EDP;
+       else
+               intel_crtc->config.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));
@@ -5841,7 +5807,7 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
        WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
             num_connectors, pipe_name(pipe));
 
-       WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
+       WARN_ON(I915_READ(PIPECONF(intel_crtc->config.cpu_transcoder)) &
                (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
 
        WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
@@ -5853,25 +5819,24 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
        intel_crtc_update_cursor(crtc, true);
 
        /* determine panel color depth */
-       dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
-                                             adjusted_mode);
+       dither = intel_crtc->config.dither;
 
-       DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
+       DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe_name(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, mode, adjusted_mode);
+       if (intel_crtc->config.has_pch_encoder)
+               ironlake_fdi_set_m_n(crtc);
 
        haswell_set_pipeconf(crtc, adjusted_mode, dither);
 
-       intel_set_pipe_csc(crtc, adjusted_mode);
+       intel_set_pipe_csc(crtc);
 
        /* Set up the display plane register */
        I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
@@ -5886,9 +5851,32 @@ 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->config.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,
-                              struct drm_display_mode *mode,
-                              struct drm_display_mode *adjusted_mode,
                               int x, int y,
                               struct drm_framebuffer *fb)
 {
@@ -5897,18 +5885,16 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
        struct drm_encoder_helper_funcs *encoder_funcs;
        struct intel_encoder *encoder;
        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 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, mode, adjusted_mode,
-                                             x, y, fb);
+       ret = dev_priv->display.crtc_mode_set(crtc, x, y, fb);
+
        drm_vblank_post_modeset(dev, pipe);
 
        if (ret != 0)
@@ -5919,8 +5905,12 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
                        encoder->base.base.id,
                        drm_get_encoder_name(&encoder->base),
                        mode->base.id, mode->name);
-               encoder_funcs = encoder->base.helper_private;
-               encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
+               if (encoder->mode_set) {
+                       encoder->mode_set(encoder);
+               } else {
+                       encoder_funcs = encoder->base.helper_private;
+                       encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
+               }
        }
 
        return 0;
@@ -6119,7 +6109,7 @@ static void ironlake_write_eld(struct drm_connector *connector,
                eldv |= IBX_ELD_VALIDB << 4;
                eldv |= IBX_ELD_VALIDB << 8;
        } else {
-               DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
+               DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
                eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
        }
 
@@ -6836,7 +6826,7 @@ struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
+       enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
        struct drm_display_mode *mode;
        int htot = I915_READ(HTOTAL(cpu_transcoder));
        int hsync = I915_READ(HSYNC(cpu_transcoder));
@@ -7530,19 +7520,93 @@ static void intel_modeset_commit_output_state(struct drm_device *dev)
        }
 }
 
-static struct drm_display_mode *
-intel_modeset_adjusted_mode(struct drm_crtc *crtc,
-                           struct drm_display_mode *mode)
+static int
+pipe_config_set_bpp(struct drm_crtc *crtc,
+                   struct drm_framebuffer *fb,
+                   struct intel_crtc_config *pipe_config)
+{
+       struct drm_device *dev = crtc->dev;
+       struct drm_connector *connector;
+       int bpp;
+
+       switch (fb->pixel_format) {
+       case DRM_FORMAT_C8:
+               bpp = 8*3; /* since we go through a colormap */
+               break;
+       case DRM_FORMAT_XRGB1555:
+       case DRM_FORMAT_ARGB1555:
+               /* checked in intel_framebuffer_init already */
+               if (WARN_ON(INTEL_INFO(dev)->gen > 3))
+                       return -EINVAL;
+       case DRM_FORMAT_RGB565:
+               bpp = 6*3; /* min is 18bpp */
+               break;
+       case DRM_FORMAT_XBGR8888:
+       case DRM_FORMAT_ABGR8888:
+               /* checked in intel_framebuffer_init already */
+               if (WARN_ON(INTEL_INFO(dev)->gen < 4))
+                       return -EINVAL;
+       case DRM_FORMAT_XRGB8888:
+       case DRM_FORMAT_ARGB8888:
+               bpp = 8*3;
+               break;
+       case DRM_FORMAT_XRGB2101010:
+       case DRM_FORMAT_ARGB2101010:
+       case DRM_FORMAT_XBGR2101010:
+       case DRM_FORMAT_ABGR2101010:
+               /* checked in intel_framebuffer_init already */
+               if (WARN_ON(INTEL_INFO(dev)->gen < 4))
+                       return -EINVAL;
+               bpp = 10*3;
+               break;
+       /* TODO: gen4+ supports 16 bpc floating point, too. */
+       default:
+               DRM_DEBUG_KMS("unsupported depth\n");
+               return -EINVAL;
+       }
+
+       pipe_config->pipe_bpp = bpp;
+
+       /* Clamp display bpp to EDID value */
+       list_for_each_entry(connector, &dev->mode_config.connector_list,
+                           head) {
+               if (connector->encoder && connector->encoder->crtc != crtc)
+                       continue;
+
+               /* Don't use an invalid EDID bpc value */
+               if (connector->display_info.bpc &&
+                   connector->display_info.bpc * 3 < bpp) {
+                       DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
+                                     bpp, connector->display_info.bpc*3);
+                       pipe_config->pipe_bpp = connector->display_info.bpc*3;
+               }
+       }
+
+       return bpp;
+}
+
+static struct intel_crtc_config *
+intel_modeset_pipe_config(struct drm_crtc *crtc,
+                         struct drm_framebuffer *fb,
+                         struct drm_display_mode *mode)
 {
        struct drm_device *dev = crtc->dev;
-       struct drm_display_mode *adjusted_mode;
        struct drm_encoder_helper_funcs *encoder_funcs;
        struct intel_encoder *encoder;
+       struct intel_crtc_config *pipe_config;
+       int plane_bpp;
 
-       adjusted_mode = drm_mode_duplicate(dev, mode);
-       if (!adjusted_mode)
+       pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
+       if (!pipe_config)
                return ERR_PTR(-ENOMEM);
 
+       drm_mode_copy(&pipe_config->adjusted_mode, mode);
+       drm_mode_copy(&pipe_config->requested_mode, mode);
+
+       plane_bpp = pipe_config_set_bpp(crtc, fb, pipe_config);
+       if (plane_bpp < 0)
+               goto fail;
+
        /* Pass our mode to the connectors and the CRTC to give them a chance to
         * adjust it according to limitations or connector properties, and also
         * a chance to reject the mode entirely.
@@ -7552,23 +7616,38 @@ intel_modeset_adjusted_mode(struct drm_crtc *crtc,
 
                if (&encoder->new_crtc->base != crtc)
                        continue;
+
+               if (encoder->compute_config) {
+                       if (!(encoder->compute_config(encoder, pipe_config))) {
+                               DRM_DEBUG_KMS("Encoder config failure\n");
+                               goto fail;
+                       }
+
+                       continue;
+               }
+
                encoder_funcs = encoder->base.helper_private;
-               if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
-                                               adjusted_mode))) {
+               if (!(encoder_funcs->mode_fixup(&encoder->base,
+                                               &pipe_config->requested_mode,
+                                               &pipe_config->adjusted_mode))) {
                        DRM_DEBUG_KMS("Encoder fixup failed\n");
                        goto fail;
                }
        }
 
-       if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
+       if (!(intel_crtc_compute_config(crtc, pipe_config))) {
                DRM_DEBUG_KMS("CRTC fixup failed\n");
                goto fail;
        }
        DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
 
-       return adjusted_mode;
+       pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
+       DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
+                     plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
+
+       return pipe_config;
 fail:
-       drm_mode_destroy(dev, adjusted_mode);
+       kfree(pipe_config);
        return ERR_PTR(-EINVAL);
 }
 
@@ -7646,22 +7725,28 @@ 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;
+
+       DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
+                     *modeset_pipes, *prepare_pipes, *disable_pipes);
 }
 
 static bool intel_crtc_in_use(struct drm_crtc *crtc)
@@ -7730,12 +7815,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) {
@@ -7824,17 +7926,27 @@ 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;
-       struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
+       struct drm_display_mode *saved_mode, *saved_hwmode;
+       struct intel_crtc_config *pipe_config = NULL;
        struct intel_crtc *intel_crtc;
        unsigned disable_pipes, prepare_pipes, modeset_pipes;
        int ret = 0;
@@ -7847,12 +7959,6 @@ int intel_set_mode(struct drm_crtc *crtc,
        intel_modeset_affected_pipes(crtc, &modeset_pipes,
                                     &prepare_pipes, &disable_pipes);
 
-       DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
-                     modeset_pipes, prepare_pipes, disable_pipes);
-
-       for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
-               intel_crtc_disable(&intel_crtc->base);
-
        *saved_hwmode = crtc->hwmode;
        *saved_mode = crtc->mode;
 
@@ -7861,15 +7967,19 @@ int intel_set_mode(struct drm_crtc *crtc,
         * Hence simply check whether any bit is set in modeset_pipes in all the
         * pieces of code that are not yet converted to deal with mutliple crtcs
         * changing their mode at the same time. */
-       adjusted_mode = NULL;
        if (modeset_pipes) {
-               adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
-               if (IS_ERR(adjusted_mode)) {
-                       ret = PTR_ERR(adjusted_mode);
+               pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
+               if (IS_ERR(pipe_config)) {
+                       ret = PTR_ERR(pipe_config);
+                       pipe_config = NULL;
+
                        goto out;
                }
        }
 
+       for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
+               intel_crtc_disable(&intel_crtc->base);
+
        for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
                if (intel_crtc->base.enabled)
                        dev_priv->display.crtc_disable(&intel_crtc->base);
@@ -7878,8 +7988,14 @@ int intel_set_mode(struct drm_crtc *crtc,
        /* crtc->mode is already used by the ->mode_set callbacks, hence we need
         * to set it here already despite that we pass it down the callchain.
         */
-       if (modeset_pipes)
+       if (modeset_pipes) {
+               enum transcoder tmp = to_intel_crtc(crtc)->config.cpu_transcoder;
                crtc->mode = *mode;
+               /* mode_set/enable/disable functions rely on a correct pipe
+                * config. */
+               to_intel_crtc(crtc)->config = *pipe_config;
+               to_intel_crtc(crtc)->config.cpu_transcoder = tmp;
+       }
 
        /* Only after disabling all output pipelines that will be changed can we
         * update the the output configuration. */
@@ -7893,7 +8009,6 @@ int intel_set_mode(struct drm_crtc *crtc,
         */
        for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
                ret = intel_crtc_mode_set(&intel_crtc->base,
-                                         mode, adjusted_mode,
                                          x, y, fb);
                if (ret)
                        goto done;
@@ -7905,7 +8020,7 @@ int intel_set_mode(struct drm_crtc *crtc,
 
        if (modeset_pipes) {
                /* Store real post-adjustment hardware mode. */
-               crtc->hwmode = *adjusted_mode;
+               crtc->hwmode = pipe_config->adjusted_mode;
 
                /* Calculate and store various constants which
                 * are later needed by vblank and swap-completion
@@ -7916,19 +8031,31 @@ int intel_set_mode(struct drm_crtc *crtc,
 
        /* FIXME: add subpixel order */
 done:
-       drm_mode_destroy(dev, adjusted_mode);
        if (ret && crtc->enabled) {
                crtc->hwmode = *saved_hwmode;
                crtc->mode = *saved_mode;
-       } else {
-               intel_modeset_check_state(dev);
        }
 
 out:
+       kfree(pipe_config);
        kfree(saved_mode);
        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);
@@ -8016,10 +8143,8 @@ intel_set_config_compute_mode_changes(struct drm_mode_set *set,
                        config->mode_changed = true;
                } else if (set->fb == NULL) {
                        config->mode_changed = true;
-               } else if (set->fb->depth != set->crtc->fb->depth) {
-                       config->mode_changed = true;
-               } else if (set->fb->bits_per_pixel !=
-                          set->crtc->fb->bits_per_pixel) {
+               } else if (set->fb->pixel_format !=
+                          set->crtc->fb->pixel_format) {
                        config->mode_changed = true;
                } else
                        config->fb_changed = true;
@@ -8280,7 +8405,7 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
        /* Swap pipes & planes for FBC on pre-965 */
        intel_crtc->pipe = pipe;
        intel_crtc->plane = pipe;
-       intel_crtc->cpu_transcoder = pipe;
+       intel_crtc->config.cpu_transcoder = pipe;
        if (IS_MOBILE(dev) && IS_GEN3(dev)) {
                DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
                intel_crtc->plane = !pipe;
@@ -8291,8 +8416,6 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
        dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
        dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
 
-       intel_crtc->bpp = 24; /* default for pre-Ironlake */
-
        drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
 }
 
@@ -8373,7 +8496,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)) {
@@ -8629,18 +8752,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;
@@ -8883,7 +9009,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);
 
@@ -8899,6 +9025,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)) {
@@ -8919,9 +9048,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 %c sprite %c init failed: %d\n",
+                                             pipe_name(i), sprite_name(i, j), ret);
+               }
        }
 
        intel_cpu_pll_init(dev);
@@ -8998,7 +9130,7 @@ static void intel_sanitize_crtc(struct intel_crtc *crtc)
        u32 reg;
 
        /* Clear any frame start delays used for debugging left by the BIOS */
-       reg = PIPECONF(crtc->cpu_transcoder);
+       reg = PIPECONF(crtc->config.cpu_transcoder);
        I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
 
        /* We need to sanitize the plane -> pipe mapping first because this will
@@ -9164,7 +9296,7 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
                        }
 
                        crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
-                       crtc->cpu_transcoder = TRANSCODER_EDP;
+                       crtc->config.cpu_transcoder = TRANSCODER_EDP;
 
                        DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
                                      pipe_name(pipe));
@@ -9172,14 +9304,14 @@ 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]);
+       list_for_each_entry(crtc, &dev->mode_config.crtc_list,
+                           base.head) {
+               enum transcoder tmp = crtc->config.cpu_transcoder;
+               memset(&crtc->config, 0, sizeof(crtc->config));
+               crtc->config.cpu_transcoder = tmp;
 
-               tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
-               if (tmp & PIPECONF_ENABLE)
-                       crtc->active = true;
-               else
-                       crtc->active = false;
+               crtc->active = dev_priv->display.get_pipe_config(crtc,
+                                                                &crtc->config);
 
                crtc->base.enabled = crtc->active;
 
@@ -9238,10 +9370,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);
@@ -9306,6 +9444,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);