drm/radeon/kms: do dp link training at dpms on time not mode set.
[safe/jmp/linux-2.6] / drivers / gpu / drm / radeon / radeon_encoders.c
index 9ad2035..b4f23ec 100644 (file)
 
 extern int atom_debug;
 
+/* evil but including atombios.h is much worse */
+bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
+                               struct drm_display_mode *mode);
+
+static uint32_t radeon_encoder_clones(struct drm_encoder *encoder)
+{
+       struct drm_device *dev = encoder->dev;
+       struct radeon_device *rdev = dev->dev_private;
+       struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
+       struct drm_encoder *clone_encoder;
+       uint32_t index_mask = 0;
+       int count;
+
+       /* DIG routing gets problematic */
+       if (rdev->family >= CHIP_R600)
+               return index_mask;
+       /* LVDS/TV are too wacky */
+       if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
+               return index_mask;
+       /* DVO requires 2x ppll clocks depending on tmds chip */
+       if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT)
+               return index_mask;
+       
+       count = -1;
+       list_for_each_entry(clone_encoder, &dev->mode_config.encoder_list, head) {
+               struct radeon_encoder *radeon_clone = to_radeon_encoder(clone_encoder);
+               count++;
+
+               if (clone_encoder == encoder)
+                       continue;
+               if (radeon_clone->devices & (ATOM_DEVICE_LCD_SUPPORT))
+                       continue;
+               if (radeon_clone->devices & ATOM_DEVICE_DFP2_SUPPORT)
+                       continue;
+               else
+                       index_mask |= (1 << count);
+       }
+       return index_mask;
+}
+
+void radeon_setup_encoder_clones(struct drm_device *dev)
+{
+       struct drm_encoder *encoder;
+
+       list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
+               encoder->possible_clones = radeon_encoder_clones(encoder);
+       }
+}
+
 uint32_t
 radeon_get_encoder_id(struct drm_device *dev, uint32_t supported_device, uint8_t dac)
 {
@@ -159,77 +208,54 @@ radeon_get_connector_for_encoder(struct drm_encoder *encoder)
        return NULL;
 }
 
-/* used for both atom and legacy */
-void radeon_rmx_mode_fixup(struct drm_encoder *encoder,
-                          struct drm_display_mode *mode,
-                          struct drm_display_mode *adjusted_mode)
-{
-       struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
-       struct drm_device *dev = encoder->dev;
-       struct radeon_device *rdev = dev->dev_private;
-       struct radeon_native_mode *native_mode = &radeon_encoder->native_mode;
-
-       if (mode->hdisplay < native_mode->panel_xres ||
-           mode->vdisplay < native_mode->panel_yres) {
-               if (ASIC_IS_AVIVO(rdev)) {
-                       adjusted_mode->hdisplay = native_mode->panel_xres;
-                       adjusted_mode->vdisplay = native_mode->panel_yres;
-                       adjusted_mode->htotal = native_mode->panel_xres + native_mode->hblank;
-                       adjusted_mode->hsync_start = native_mode->panel_xres + native_mode->hoverplus;
-                       adjusted_mode->hsync_end = adjusted_mode->hsync_start + native_mode->hsync_width;
-                       adjusted_mode->vtotal = native_mode->panel_yres + native_mode->vblank;
-                       adjusted_mode->vsync_start = native_mode->panel_yres + native_mode->voverplus;
-                       adjusted_mode->vsync_end = adjusted_mode->vsync_start + native_mode->vsync_width;
-                       /* update crtc values */
-                       drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
-                       /* adjust crtc values */
-                       adjusted_mode->crtc_hdisplay = native_mode->panel_xres;
-                       adjusted_mode->crtc_vdisplay = native_mode->panel_yres;
-                       adjusted_mode->crtc_htotal = adjusted_mode->crtc_hdisplay + native_mode->hblank;
-                       adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hdisplay + native_mode->hoverplus;
-                       adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + native_mode->hsync_width;
-                       adjusted_mode->crtc_vtotal = adjusted_mode->crtc_vdisplay + native_mode->vblank;
-                       adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + native_mode->voverplus;
-                       adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + native_mode->vsync_width;
-               } else {
-                       adjusted_mode->htotal = native_mode->panel_xres + native_mode->hblank;
-                       adjusted_mode->hsync_start = native_mode->panel_xres + native_mode->hoverplus;
-                       adjusted_mode->hsync_end = adjusted_mode->hsync_start + native_mode->hsync_width;
-                       adjusted_mode->vtotal = native_mode->panel_yres + native_mode->vblank;
-                       adjusted_mode->vsync_start = native_mode->panel_yres + native_mode->voverplus;
-                       adjusted_mode->vsync_end = adjusted_mode->vsync_start + native_mode->vsync_width;
-                       /* update crtc values */
-                       drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
-                       /* adjust crtc values */
-                       adjusted_mode->crtc_htotal = adjusted_mode->crtc_hdisplay + native_mode->hblank;
-                       adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hdisplay + native_mode->hoverplus;
-                       adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + native_mode->hsync_width;
-                       adjusted_mode->crtc_vtotal = adjusted_mode->crtc_vdisplay + native_mode->vblank;
-                       adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + native_mode->voverplus;
-                       adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + native_mode->vsync_width;
-               }
-               adjusted_mode->flags = native_mode->flags;
-               adjusted_mode->clock = native_mode->dotclock;
-       }
-}
-
-
 static bool radeon_atom_mode_fixup(struct drm_encoder *encoder,
                                   struct drm_display_mode *mode,
                                   struct drm_display_mode *adjusted_mode)
 {
        struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
+       struct drm_device *dev = encoder->dev;
+       struct radeon_device *rdev = dev->dev_private;
 
+       /* set the active encoder to connector routing */
+       radeon_encoder_set_active_device(encoder);
        drm_mode_set_crtcinfo(adjusted_mode, 0);
 
-       if (radeon_encoder->rmx_type != RMX_OFF)
-               radeon_rmx_mode_fixup(encoder, mode, adjusted_mode);
-
        /* hw bug */
        if ((mode->flags & DRM_MODE_FLAG_INTERLACE)
            && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2)))
                adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2;
 
+       /* get the native mode for LVDS */
+       if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) {
+               struct drm_display_mode *native_mode = &radeon_encoder->native_mode;
+               int mode_id = adjusted_mode->base.id;
+               *adjusted_mode = *native_mode;
+               if (!ASIC_IS_AVIVO(rdev)) {
+                       adjusted_mode->hdisplay = mode->hdisplay;
+                       adjusted_mode->vdisplay = mode->vdisplay;
+               }
+               adjusted_mode->base.id = mode_id;
+       }
+
+       /* get the native mode for TV */
+       if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) {
+               struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv;
+               if (tv_dac) {
+                       if (tv_dac->tv_std == TV_STD_NTSC ||
+                           tv_dac->tv_std == TV_STD_NTSC_J ||
+                           tv_dac->tv_std == TV_STD_PAL_M)
+                               radeon_atom_get_tv_timings(rdev, 0, adjusted_mode);
+                       else
+                               radeon_atom_get_tv_timings(rdev, 1, adjusted_mode);
+               }
+       }
+
+       if (ASIC_IS_DCE3(rdev) &&
+           (radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT))) {
+               struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
+               radeon_dp_set_link_config(connector, mode);
+       }
+
        return true;
 }
 
@@ -241,9 +267,12 @@ atombios_dac_setup(struct drm_encoder *encoder, int action)
        struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
        DAC_ENCODER_CONTROL_PS_ALLOCATION args;
        int index = 0, num = 0;
-       /* fixme - fill in enc_priv for atom dac */
+       struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
        enum radeon_tv_std tv_std = TV_STD_NTSC;
 
+       if (dac_info->tv_std)
+               tv_std = dac_info->tv_std;
+
        memset(&args, 0, sizeof(args));
 
        switch (radeon_encoder->encoder_id) {
@@ -296,9 +325,12 @@ atombios_tv_setup(struct drm_encoder *encoder, int action)
        struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
        TV_ENCODER_CONTROL_PS_ALLOCATION args;
        int index = 0;
-       /* fixme - fill in enc_priv for atom dac */
+       struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
        enum radeon_tv_std tv_std = TV_STD_NTSC;
 
+       if (dac_info->tv_std)
+               tv_std = dac_info->tv_std;
+
        memset(&args, 0, sizeof(args));
 
        index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl);
@@ -398,7 +430,7 @@ union lvds_encoder_control {
        LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2;
 };
 
-static void
+void
 atombios_digital_setup(struct drm_encoder *encoder, int action)
 {
        struct drm_device *dev = encoder->dev;
@@ -455,7 +487,7 @@ atombios_digital_setup(struct drm_encoder *encoder, int action)
                case 1:
                        args.v1.ucMisc = 0;
                        args.v1.ucAction = action;
-                       if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr))
+                       if (drm_detect_hdmi_monitor(radeon_connector->edid))
                                args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
                        args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
                        if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
@@ -480,7 +512,7 @@ atombios_digital_setup(struct drm_encoder *encoder, int action)
                                if (dig->coherent_mode)
                                        args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT;
                        }
-                       if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr))
+                       if (drm_detect_hdmi_monitor(radeon_connector->edid))
                                args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
                        args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
                        args.v2.ucTruncate = 0;
@@ -528,6 +560,7 @@ atombios_get_encoder_mode(struct drm_encoder *encoder)
 {
        struct drm_connector *connector;
        struct radeon_connector *radeon_connector;
+       struct radeon_connector_atom_dig *radeon_dig_connector;
 
        connector = radeon_get_connector_for_encoder(encoder);
        if (!connector)
@@ -537,7 +570,8 @@ atombios_get_encoder_mode(struct drm_encoder *encoder)
 
        switch (connector->connector_type) {
        case DRM_MODE_CONNECTOR_DVII:
-               if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr))
+       case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */
+               if (drm_detect_hdmi_monitor(radeon_connector->edid))
                        return ATOM_ENCODER_MODE_HDMI;
                else if (radeon_connector->use_digital)
                        return ATOM_ENCODER_MODE_DVI;
@@ -546,9 +580,8 @@ atombios_get_encoder_mode(struct drm_encoder *encoder)
                break;
        case DRM_MODE_CONNECTOR_DVID:
        case DRM_MODE_CONNECTOR_HDMIA:
-       case DRM_MODE_CONNECTOR_HDMIB:
        default:
-               if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr))
+               if (drm_detect_hdmi_monitor(radeon_connector->edid))
                        return ATOM_ENCODER_MODE_HDMI;
                else
                        return ATOM_ENCODER_MODE_DVI;
@@ -557,10 +590,10 @@ atombios_get_encoder_mode(struct drm_encoder *encoder)
                return ATOM_ENCODER_MODE_LVDS;
                break;
        case DRM_MODE_CONNECTOR_DisplayPort:
-               /*if (radeon_output->MonType == MT_DP)
-                 return ATOM_ENCODER_MODE_DP;
-                 else*/
-               if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr))
+               radeon_dig_connector = radeon_connector->con_priv;
+               if (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT)
+                       return ATOM_ENCODER_MODE_DP;
+               else if (drm_detect_hdmi_monitor(radeon_connector->edid))
                        return ATOM_ENCODER_MODE_HDMI;
                else
                        return ATOM_ENCODER_MODE_DVI;
@@ -579,6 +612,30 @@ atombios_get_encoder_mode(struct drm_encoder *encoder)
        }
 }
 
+/*
+ * DIG Encoder/Transmitter Setup
+ *
+ * DCE 3.0/3.1
+ * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
+ * Supports up to 3 digital outputs
+ * - 2 DIG encoder blocks.
+ * DIG1 can drive UNIPHY link A or link B
+ * DIG2 can drive UNIPHY link B or LVTMA
+ *
+ * DCE 3.2
+ * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
+ * Supports up to 5 digital outputs
+ * - 2 DIG encoder blocks.
+ * DIG1/2 can drive UNIPHY0/1/2 link A or link B
+ *
+ * Routing
+ * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
+ * Examples:
+ * crtc0 -> dig2 -> LVTMA   links A+B -> TMDS/HDMI
+ * crtc1 -> dig1 -> UNIPHY0 link  B   -> DP
+ * crtc0 -> dig1 -> UNIPHY2 link  A   -> LVDS
+ * crtc1 -> dig2 -> UNIPHY1 link  B+A -> TMDS/HDMI
+ */
 static void
 atombios_dig_encoder_setup(struct drm_encoder *encoder, int action)
 {
@@ -620,10 +677,17 @@ atombios_dig_encoder_setup(struct drm_encoder *encoder, int action)
        } else {
                switch (radeon_encoder->encoder_id) {
                case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
-                       index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl);
+                       /* XXX doesn't really matter which dig encoder we pick as long as it's
+                        * not already in use
+                        */
+                       if (dig_connector->linkb)
+                               index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl);
+                       else
+                               index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl);
                        num = 1;
                        break;
                case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
+                       /* Only dig2 encoder can drive LVTMA */
                        index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl);
                        num = 2;
                        break;
@@ -658,18 +722,21 @@ atombios_dig_encoder_setup(struct drm_encoder *encoder, int action)
                }
        }
 
-       if (radeon_encoder->pixel_clock > 165000) {
-               args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA_B;
+       args.ucEncoderMode = atombios_get_encoder_mode(encoder);
+
+       if (args.ucEncoderMode == ATOM_ENCODER_MODE_DP) {
+               if (dig_connector->dp_clock == 270000)
+                       args.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
+               args.ucLaneNum = dig_connector->dp_lane_count;
+       } else if (radeon_encoder->pixel_clock > 165000)
                args.ucLaneNum = 8;
-       } else {
-               if (dig_connector->linkb)
-                       args.ucConfig |= ATOM_ENCODER_CONFIG_LINKB;
-               else
-                       args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA;
+       else
                args.ucLaneNum = 4;
-       }
 
-       args.ucEncoderMode = atombios_get_encoder_mode(encoder);
+       if (dig_connector->linkb)
+               args.ucConfig |= ATOM_ENCODER_CONFIG_LINKB;
+       else
+               args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA;
 
        atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
 
@@ -680,8 +747,8 @@ union dig_transmitter_control {
        DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2;
 };
 
-static void
-atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action)
+void
+atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t lane_num, uint8_t lane_set)
 {
        struct drm_device *dev = encoder->dev;
        struct radeon_device *rdev = dev->dev_private;
@@ -693,6 +760,7 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action)
        struct drm_connector *connector;
        struct radeon_connector *radeon_connector;
        struct radeon_connector_atom_dig *dig_connector;
+       bool is_dp = false;
 
        connector = radeon_get_connector_for_encoder(encoder);
        if (!connector)
@@ -710,6 +778,9 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action)
 
        dig_connector = radeon_connector->con_priv;
 
+       if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP)
+               is_dp = true;
+
        memset(&args, 0, sizeof(args));
 
        if (ASIC_IS_DCE32(rdev))
@@ -728,16 +799,25 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action)
        atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev);
 
        args.v1.ucAction = action;
-
+       if (action == ATOM_TRANSMITTER_ACTION_INIT) {
+               args.v1.usInitInfo = radeon_connector->connector_object_id;
+       } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
+               args.v1.asMode.ucLaneSel = lane_num;
+               args.v1.asMode.ucLaneSet = lane_set;
+       } else {
+               if (is_dp)
+                       args.v1.usPixelClock =
+                               cpu_to_le16(dig_connector->dp_clock / 10);
+               else if (radeon_encoder->pixel_clock > 165000)
+                       args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
+               else
+                       args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
+       }
        if (ASIC_IS_DCE32(rdev)) {
-               if (radeon_encoder->pixel_clock > 165000) {
-                       args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock * 10 * 2) / 100);
-                       args.v2.acConfig.fDualLinkConnector = 1;
-               } else {
-                       args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock * 10 * 4) / 100);
-               }
                if (dig->dig_block)
                        args.v2.acConfig.ucEncoderSel = 1;
+               if (dig_connector->linkb)
+                       args.v2.acConfig.ucLinkSel = 1;
 
                switch (radeon_encoder->encoder_id) {
                case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
@@ -754,27 +834,31 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action)
                        break;
                }
 
-               if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
+               if (is_dp)
+                       args.v2.acConfig.fCoherentMode = 1;
+               else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
                        if (dig->coherent_mode)
                                args.v2.acConfig.fCoherentMode = 1;
                }
        } else {
                args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL;
-               args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock) / 10);
 
                switch (radeon_encoder->encoder_id) {
                case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
-                       args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER;
+                       /* XXX doesn't really matter which dig encoder we pick as long as it's
+                        * not already in use
+                        */
+                       if (dig_connector->linkb)
+                               args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER;
+                       else
+                               args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER;
                        if (rdev->flags & RADEON_IS_IGP) {
                                if (radeon_encoder->pixel_clock > 165000) {
-                                       args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK |
-                                                            ATOM_TRANSMITTER_CONFIG_LINKA_B);
                                        if (dig_connector->igp_lane_info & 0x3)
                                                args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7;
                                        else if (dig_connector->igp_lane_info & 0xc)
                                                args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15;
                                } else {
-                                       args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA;
                                        if (dig_connector->igp_lane_info & 0x1)
                                                args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3;
                                        else if (dig_connector->igp_lane_info & 0x2)
@@ -784,35 +868,25 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action)
                                        else if (dig_connector->igp_lane_info & 0x8)
                                                args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15;
                                }
-                       } else {
-                               if (radeon_encoder->pixel_clock > 165000)
-                                       args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK |
-                                                            ATOM_TRANSMITTER_CONFIG_LINKA_B |
-                                                            ATOM_TRANSMITTER_CONFIG_LANE_0_7);
-                               else {
-                                       if (dig_connector->linkb)
-                                               args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB | ATOM_TRANSMITTER_CONFIG_LANE_0_3;
-                                       else
-                                               args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA | ATOM_TRANSMITTER_CONFIG_LANE_0_3;
-                               }
                        }
                        break;
                case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
+                       /* Only dig2 encoder can drive LVTMA */
                        args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER;
-                       if (radeon_encoder->pixel_clock > 165000)
-                               args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK |
-                                                    ATOM_TRANSMITTER_CONFIG_LINKA_B |
-                                                    ATOM_TRANSMITTER_CONFIG_LANE_0_7);
-                       else {
-                               if (dig_connector->linkb)
-                                       args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB | ATOM_TRANSMITTER_CONFIG_LANE_0_3;
-                               else
-                                       args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA | ATOM_TRANSMITTER_CONFIG_LANE_0_3;
-                       }
                        break;
                }
 
-               if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
+               if (radeon_encoder->pixel_clock > 165000)
+                       args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK;
+
+               if (dig_connector->linkb)
+                       args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB;
+               else
+                       args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA;
+
+               if (is_dp)
+                       args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
+               else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
                        if (dig->coherent_mode)
                                args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
                }
@@ -868,16 +942,9 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
        DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
        int index = 0;
        bool is_dig = false;
-       int devices;
 
        memset(&args, 0, sizeof(args));
 
-       /* on DPMS off we have no idea if active device is meaningful */
-       if (mode != DRM_MODE_DPMS_ON && !radeon_encoder->active_device)
-               devices = radeon_encoder->devices;
-       else
-               devices = radeon_encoder->active_device;
-
        DRM_DEBUG("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
                  radeon_encoder->encoder_id, mode, radeon_encoder->devices,
                  radeon_encoder->active_device);
@@ -908,18 +975,18 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
                break;
        case ENCODER_OBJECT_ID_INTERNAL_DAC1:
        case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
-               if (devices & (ATOM_DEVICE_TV_SUPPORT))
+               if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
                        index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
-               else if (devices & (ATOM_DEVICE_CV_SUPPORT))
+               else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
                        index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
                else
                        index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl);
                break;
        case ENCODER_OBJECT_ID_INTERNAL_DAC2:
        case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
-               if (devices & (ATOM_DEVICE_TV_SUPPORT))
+               if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
                        index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
-               else if (devices & (ATOM_DEVICE_CV_SUPPORT))
+               else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
                        index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
                else
                        index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl);
@@ -929,12 +996,16 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
        if (is_dig) {
                switch (mode) {
                case DRM_MODE_DPMS_ON:
-                       atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE);
+                       atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0);
+                       {
+                               struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
+                               dp_link_train(encoder, connector);
+                       }
                        break;
                case DRM_MODE_DPMS_STANDBY:
                case DRM_MODE_DPMS_SUSPEND:
                case DRM_MODE_DPMS_OFF:
-                       atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE);
+                       atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0);
                        break;
                }
        } else {
@@ -1036,13 +1107,33 @@ atombios_set_encoder_crtc_source(struct drm_encoder *encoder)
                                                args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID;
                                        else
                                                args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID;
-                               } else
-                                       args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID;
+                               } else {
+                                       struct drm_connector *connector;
+                                       struct radeon_connector *radeon_connector;
+                                       struct radeon_connector_atom_dig *dig_connector;
+
+                                       connector = radeon_get_connector_for_encoder(encoder);
+                                       if (!connector)
+                                               return;
+                                       radeon_connector = to_radeon_connector(connector);
+                                       if (!radeon_connector->con_priv)
+                                               return;
+                                       dig_connector = radeon_connector->con_priv;
+
+                                       /* XXX doesn't really matter which dig encoder we pick as long as it's
+                                        * not already in use
+                                        */
+                                       if (dig_connector->linkb)
+                                               args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID;
+                                       else
+                                               args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID;
+                               }
                                break;
                        case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
                                args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID;
                                break;
                        case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
+                               /* Only dig2 encoder can drive LVTMA */
                                args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID;
                                break;
                        case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
@@ -1098,8 +1189,11 @@ atombios_apply_encoder_quirks(struct drm_encoder *encoder,
        }
 
        /* set scaler clears this on some chips */
-       if (ASIC_IS_AVIVO(rdev) && (mode->flags & DRM_MODE_FLAG_INTERLACE))
-               WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, AVIVO_D1MODE_INTERLEAVE_EN);
+       if (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))) {
+               if (ASIC_IS_AVIVO(rdev) && (mode->flags & DRM_MODE_FLAG_INTERLACE))
+                       WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset,
+                              AVIVO_D1MODE_INTERLEAVE_EN);
+       }
 }
 
 static void
@@ -1112,11 +1206,14 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
        struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
        struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
 
-       if (radeon_encoder->enc_priv) {
-               struct radeon_encoder_atom_dig *dig;
+       if (radeon_encoder->active_device &
+           (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) {
+               if (radeon_encoder->enc_priv) {
+                       struct radeon_encoder_atom_dig *dig;
 
-               dig = radeon_encoder->enc_priv;
-               dig->dig_block = radeon_crtc->crtc_id;
+                       dig = radeon_encoder->enc_priv;
+                       dig->dig_block = radeon_crtc->crtc_id;
+               }
        }
        radeon_encoder->pixel_clock = adjusted_mode->clock;
 
@@ -1142,13 +1239,14 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
        case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
        case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
                /* disable the encoder and transmitter */
-               atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE);
+               atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
                atombios_dig_encoder_setup(encoder, ATOM_DISABLE);
 
                /* setup and enable the encoder and transmitter */
                atombios_dig_encoder_setup(encoder, ATOM_ENABLE);
-               atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP);
-               atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE);
+               atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0);
+               atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0);
+               atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
                break;
        case ENCODER_OBJECT_ID_INTERNAL_DDI:
                atombios_ddia_setup(encoder, ATOM_ENABLE);
@@ -1262,8 +1360,6 @@ static void radeon_atom_encoder_prepare(struct drm_encoder *encoder)
 {
        radeon_atom_output_lock(encoder, true);
        radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
-
-       radeon_encoder_set_active_device(encoder);
 }
 
 static void radeon_atom_encoder_commit(struct drm_encoder *encoder)
@@ -1339,6 +1435,7 @@ radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder)
 void
 radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t supported_device)
 {
+       struct radeon_device *rdev = dev->dev_private;
        struct drm_encoder *encoder;
        struct radeon_encoder *radeon_encoder;
 
@@ -1358,8 +1455,10 @@ radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t su
                return;
 
        encoder = &radeon_encoder->base;
-       encoder->possible_crtcs = 0x3;
-       encoder->possible_clones = 0;
+       if (rdev->flags & RADEON_SINGLE_CRTC)
+               encoder->possible_crtcs = 0x1;
+       else
+               encoder->possible_crtcs = 0x3;
 
        radeon_encoder->enc_priv = NULL;