13f03ced8SAlex Deucher /* 23f03ced8SAlex Deucher * Copyright 2007-11 Advanced Micro Devices, Inc. 33f03ced8SAlex Deucher * Copyright 2008 Red Hat Inc. 43f03ced8SAlex Deucher * 53f03ced8SAlex Deucher * Permission is hereby granted, free of charge, to any person obtaining a 63f03ced8SAlex Deucher * copy of this software and associated documentation files (the "Software"), 73f03ced8SAlex Deucher * to deal in the Software without restriction, including without limitation 83f03ced8SAlex Deucher * the rights to use, copy, modify, merge, publish, distribute, sublicense, 93f03ced8SAlex Deucher * and/or sell copies of the Software, and to permit persons to whom the 103f03ced8SAlex Deucher * Software is furnished to do so, subject to the following conditions: 113f03ced8SAlex Deucher * 123f03ced8SAlex Deucher * The above copyright notice and this permission notice shall be included in 133f03ced8SAlex Deucher * all copies or substantial portions of the Software. 143f03ced8SAlex Deucher * 153f03ced8SAlex Deucher * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 163f03ced8SAlex Deucher * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 173f03ced8SAlex Deucher * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 183f03ced8SAlex Deucher * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 193f03ced8SAlex Deucher * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 203f03ced8SAlex Deucher * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 213f03ced8SAlex Deucher * OTHER DEALINGS IN THE SOFTWARE. 223f03ced8SAlex Deucher * 233f03ced8SAlex Deucher * Authors: Dave Airlie 243f03ced8SAlex Deucher * Alex Deucher 253f03ced8SAlex Deucher */ 26c182615fSSam Ravnborg 27f3728734SAlex Deucher #include <linux/backlight.h> 28564d8a2cSMario Kleiner #include <linux/dmi.h> 292ef79416SThomas Zimmermann #include <linux/pci.h> 303f03ced8SAlex Deucher 31c182615fSSam Ravnborg #include <drm/drm_crtc_helper.h> 32c182615fSSam Ravnborg #include <drm/drm_file.h> 33f7d17cd4SThomas Zimmermann #include <drm/drm_modeset_helper_vtables.h> 34c182615fSSam Ravnborg #include <drm/radeon_drm.h> 35c182615fSSam Ravnborg 361eb67781SHans de Goede #include <acpi/video.h> 371eb67781SHans de Goede 38c182615fSSam Ravnborg #include "atom.h" 3954ae7f99SLee Jones #include "radeon_atombios.h" 40c182615fSSam Ravnborg #include "radeon.h" 41c182615fSSam Ravnborg #include "radeon_asic.h" 42c182615fSSam Ravnborg #include "radeon_audio.h" 43c182615fSSam Ravnborg 443f03ced8SAlex Deucher extern int atom_debug; 453f03ced8SAlex Deucher 46f3728734SAlex Deucher static u8 47f3728734SAlex Deucher radeon_atom_get_backlight_level_from_reg(struct radeon_device *rdev) 48f3728734SAlex Deucher { 49f3728734SAlex Deucher u8 backlight_level; 50f3728734SAlex Deucher u32 bios_2_scratch; 51f3728734SAlex Deucher 52f3728734SAlex Deucher if (rdev->family >= CHIP_R600) 53f3728734SAlex Deucher bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH); 54f3728734SAlex Deucher else 55f3728734SAlex Deucher bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH); 56f3728734SAlex Deucher 57f3728734SAlex Deucher backlight_level = ((bios_2_scratch & ATOM_S2_CURRENT_BL_LEVEL_MASK) >> 58f3728734SAlex Deucher ATOM_S2_CURRENT_BL_LEVEL_SHIFT); 59f3728734SAlex Deucher 60f3728734SAlex Deucher return backlight_level; 61f3728734SAlex Deucher } 62f3728734SAlex Deucher 63f3728734SAlex Deucher static void 64f3728734SAlex Deucher radeon_atom_set_backlight_level_to_reg(struct radeon_device *rdev, 65f3728734SAlex Deucher u8 backlight_level) 66f3728734SAlex Deucher { 67f3728734SAlex Deucher u32 bios_2_scratch; 68f3728734SAlex Deucher 69f3728734SAlex Deucher if (rdev->family >= CHIP_R600) 70f3728734SAlex Deucher bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH); 71f3728734SAlex Deucher else 72f3728734SAlex Deucher bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH); 73f3728734SAlex Deucher 74f3728734SAlex Deucher bios_2_scratch &= ~ATOM_S2_CURRENT_BL_LEVEL_MASK; 75f3728734SAlex Deucher bios_2_scratch |= ((backlight_level << ATOM_S2_CURRENT_BL_LEVEL_SHIFT) & 76f3728734SAlex Deucher ATOM_S2_CURRENT_BL_LEVEL_MASK); 77f3728734SAlex Deucher 78f3728734SAlex Deucher if (rdev->family >= CHIP_R600) 79f3728734SAlex Deucher WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch); 80f3728734SAlex Deucher else 81f3728734SAlex Deucher WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch); 82f3728734SAlex Deucher } 83f3728734SAlex Deucher 846d92f81dSAlex Deucher u8 856d92f81dSAlex Deucher atombios_get_backlight_level(struct radeon_encoder *radeon_encoder) 866d92f81dSAlex Deucher { 876d92f81dSAlex Deucher struct drm_device *dev = radeon_encoder->base.dev; 886d92f81dSAlex Deucher struct radeon_device *rdev = dev->dev_private; 896d92f81dSAlex Deucher 906d92f81dSAlex Deucher if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU)) 916d92f81dSAlex Deucher return 0; 926d92f81dSAlex Deucher 936d92f81dSAlex Deucher return radeon_atom_get_backlight_level_from_reg(rdev); 946d92f81dSAlex Deucher } 956d92f81dSAlex Deucher 96fda4b25cSLuca Tettamanti void 9737e9b6a6SAlex Deucher atombios_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level) 98f3728734SAlex Deucher { 99f3728734SAlex Deucher struct drm_encoder *encoder = &radeon_encoder->base; 100f3728734SAlex Deucher struct drm_device *dev = radeon_encoder->base.dev; 101f3728734SAlex Deucher struct radeon_device *rdev = dev->dev_private; 102f3728734SAlex Deucher struct radeon_encoder_atom_dig *dig; 103f3728734SAlex Deucher DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args; 104f3728734SAlex Deucher int index; 105f3728734SAlex Deucher 10637e9b6a6SAlex Deucher if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU)) 10737e9b6a6SAlex Deucher return; 10837e9b6a6SAlex Deucher 10937e9b6a6SAlex Deucher if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) && 11037e9b6a6SAlex Deucher radeon_encoder->enc_priv) { 111f3728734SAlex Deucher dig = radeon_encoder->enc_priv; 11237e9b6a6SAlex Deucher dig->backlight_level = level; 113f3728734SAlex Deucher radeon_atom_set_backlight_level_to_reg(rdev, dig->backlight_level); 114f3728734SAlex Deucher 115f3728734SAlex Deucher switch (radeon_encoder->encoder_id) { 116f3728734SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVDS: 117f3728734SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 118f3728734SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); 119f3728734SAlex Deucher if (dig->backlight_level == 0) { 120f3728734SAlex Deucher args.ucAction = ATOM_LCD_BLOFF; 121f3728734SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 122f3728734SAlex Deucher } else { 123f3728734SAlex Deucher args.ucAction = ATOM_LCD_BL_BRIGHTNESS_CONTROL; 124f3728734SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 125f3728734SAlex Deucher args.ucAction = ATOM_LCD_BLON; 126f3728734SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 127f3728734SAlex Deucher } 128f3728734SAlex Deucher break; 129f3728734SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 130f3728734SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 131f3728734SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 132f3728734SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 133d3200be6SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 134f3728734SAlex Deucher if (dig->backlight_level == 0) 135f3728734SAlex Deucher atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0); 136f3728734SAlex Deucher else { 137f3728734SAlex Deucher atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_BL_BRIGHTNESS_CONTROL, 0, 0); 138f3728734SAlex Deucher atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0); 139f3728734SAlex Deucher } 140f3728734SAlex Deucher break; 141f3728734SAlex Deucher default: 142f3728734SAlex Deucher break; 143f3728734SAlex Deucher } 144f3728734SAlex Deucher } 145f3728734SAlex Deucher } 146f3728734SAlex Deucher 147f3728734SAlex Deucher static u8 radeon_atom_bl_level(struct backlight_device *bd) 148f3728734SAlex Deucher { 149f3728734SAlex Deucher u8 level; 150f3728734SAlex Deucher 151f3728734SAlex Deucher /* Convert brightness to hardware level */ 152f3728734SAlex Deucher if (bd->props.brightness < 0) 153f3728734SAlex Deucher level = 0; 154f3728734SAlex Deucher else if (bd->props.brightness > RADEON_MAX_BL_LEVEL) 155f3728734SAlex Deucher level = RADEON_MAX_BL_LEVEL; 156f3728734SAlex Deucher else 157f3728734SAlex Deucher level = bd->props.brightness; 158f3728734SAlex Deucher 159f3728734SAlex Deucher return level; 160f3728734SAlex Deucher } 161f3728734SAlex Deucher 162f3728734SAlex Deucher static int radeon_atom_backlight_update_status(struct backlight_device *bd) 163f3728734SAlex Deucher { 164f3728734SAlex Deucher struct radeon_backlight_privdata *pdata = bl_get_data(bd); 165f3728734SAlex Deucher struct radeon_encoder *radeon_encoder = pdata->encoder; 166f3728734SAlex Deucher 16737e9b6a6SAlex Deucher atombios_set_backlight_level(radeon_encoder, radeon_atom_bl_level(bd)); 168f3728734SAlex Deucher 169f3728734SAlex Deucher return 0; 170f3728734SAlex Deucher } 171f3728734SAlex Deucher 172f3728734SAlex Deucher static int radeon_atom_backlight_get_brightness(struct backlight_device *bd) 173f3728734SAlex Deucher { 174f3728734SAlex Deucher struct radeon_backlight_privdata *pdata = bl_get_data(bd); 175f3728734SAlex Deucher struct radeon_encoder *radeon_encoder = pdata->encoder; 176f3728734SAlex Deucher struct drm_device *dev = radeon_encoder->base.dev; 177f3728734SAlex Deucher struct radeon_device *rdev = dev->dev_private; 178f3728734SAlex Deucher 179f3728734SAlex Deucher return radeon_atom_get_backlight_level_from_reg(rdev); 180f3728734SAlex Deucher } 181f3728734SAlex Deucher 182f3728734SAlex Deucher static const struct backlight_ops radeon_atom_backlight_ops = { 183f3728734SAlex Deucher .get_brightness = radeon_atom_backlight_get_brightness, 184f3728734SAlex Deucher .update_status = radeon_atom_backlight_update_status, 185f3728734SAlex Deucher }; 186f3728734SAlex Deucher 187f3728734SAlex Deucher void radeon_atom_backlight_init(struct radeon_encoder *radeon_encoder, 188f3728734SAlex Deucher struct drm_connector *drm_connector) 189f3728734SAlex Deucher { 190f3728734SAlex Deucher struct drm_device *dev = radeon_encoder->base.dev; 191f3728734SAlex Deucher struct radeon_device *rdev = dev->dev_private; 192f3728734SAlex Deucher struct backlight_device *bd; 193f3728734SAlex Deucher struct backlight_properties props; 194f3728734SAlex Deucher struct radeon_backlight_privdata *pdata; 195f3728734SAlex Deucher struct radeon_encoder_atom_dig *dig; 196614499b4SAlex Deucher char bl_name[16]; 197f3728734SAlex Deucher 19880101790SAlex Deucher /* Mac laptops with multiple GPUs use the gmux driver for backlight 19980101790SAlex Deucher * so don't register a backlight device 20080101790SAlex Deucher */ 20180101790SAlex Deucher if ((rdev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE) && 202364438fdSNicholas Bishop (rdev->pdev->device == 0x6741) && 203364438fdSNicholas Bishop !dmi_match(DMI_PRODUCT_NAME, "iMac12,1")) 20480101790SAlex Deucher return; 20580101790SAlex Deucher 206f3728734SAlex Deucher if (!radeon_encoder->enc_priv) 207f3728734SAlex Deucher return; 208f3728734SAlex Deucher 209f3728734SAlex Deucher if (!rdev->is_atom_bios) 210f3728734SAlex Deucher return; 211f3728734SAlex Deucher 212f3728734SAlex Deucher if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU)) 213f3728734SAlex Deucher return; 214f3728734SAlex Deucher 2151eb67781SHans de Goede if (!acpi_video_backlight_use_native()) { 2161eb67781SHans de Goede drm_info(dev, "Skipping radeon atom DIG backlight registration\n"); 2171eb67781SHans de Goede return; 2181eb67781SHans de Goede } 2191eb67781SHans de Goede 220f3728734SAlex Deucher pdata = kmalloc(sizeof(struct radeon_backlight_privdata), GFP_KERNEL); 221f3728734SAlex Deucher if (!pdata) { 222f3728734SAlex Deucher DRM_ERROR("Memory allocation failed\n"); 223f3728734SAlex Deucher goto error; 224f3728734SAlex Deucher } 225f3728734SAlex Deucher 226f3728734SAlex Deucher memset(&props, 0, sizeof(props)); 227f3728734SAlex Deucher props.max_brightness = RADEON_MAX_BL_LEVEL; 228f3728734SAlex Deucher props.type = BACKLIGHT_RAW; 229614499b4SAlex Deucher snprintf(bl_name, sizeof(bl_name), 230614499b4SAlex Deucher "radeon_bl%d", dev->primary->index); 2315bdebb18SDave Airlie bd = backlight_device_register(bl_name, drm_connector->kdev, 232f3728734SAlex Deucher pdata, &radeon_atom_backlight_ops, &props); 233f3728734SAlex Deucher if (IS_ERR(bd)) { 234f3728734SAlex Deucher DRM_ERROR("Backlight registration failed\n"); 235f3728734SAlex Deucher goto error; 236f3728734SAlex Deucher } 237f3728734SAlex Deucher 238f3728734SAlex Deucher pdata->encoder = radeon_encoder; 239f3728734SAlex Deucher 240f3728734SAlex Deucher dig = radeon_encoder->enc_priv; 241f3728734SAlex Deucher dig->bl_dev = bd; 242f3728734SAlex Deucher 243f3728734SAlex Deucher bd->props.brightness = radeon_atom_backlight_get_brightness(bd); 244201bb624SAlex Deucher /* Set a reasonable default here if the level is 0 otherwise 245201bb624SAlex Deucher * fbdev will attempt to turn the backlight on after console 246201bb624SAlex Deucher * unblanking and it will try and restore 0 which turns the backlight 247201bb624SAlex Deucher * off again. 248201bb624SAlex Deucher */ 249201bb624SAlex Deucher if (bd->props.brightness == 0) 250201bb624SAlex Deucher bd->props.brightness = RADEON_MAX_BL_LEVEL; 251f3728734SAlex Deucher bd->props.power = FB_BLANK_UNBLANK; 252f3728734SAlex Deucher backlight_update_status(bd); 253f3728734SAlex Deucher 254f3728734SAlex Deucher DRM_INFO("radeon atom DIG backlight initialized\n"); 2554cee6a90SAlex Deucher rdev->mode_info.bl_encoder = radeon_encoder; 256f3728734SAlex Deucher 257f3728734SAlex Deucher return; 258f3728734SAlex Deucher 259f3728734SAlex Deucher error: 260f3728734SAlex Deucher kfree(pdata); 261f3728734SAlex Deucher return; 262f3728734SAlex Deucher } 263f3728734SAlex Deucher 264f3728734SAlex Deucher static void radeon_atom_backlight_exit(struct radeon_encoder *radeon_encoder) 265f3728734SAlex Deucher { 266f3728734SAlex Deucher struct drm_device *dev = radeon_encoder->base.dev; 267f3728734SAlex Deucher struct radeon_device *rdev = dev->dev_private; 268f3728734SAlex Deucher struct backlight_device *bd = NULL; 269f3728734SAlex Deucher struct radeon_encoder_atom_dig *dig; 270f3728734SAlex Deucher 271f3728734SAlex Deucher if (!radeon_encoder->enc_priv) 272f3728734SAlex Deucher return; 273f3728734SAlex Deucher 274f3728734SAlex Deucher if (!rdev->is_atom_bios) 275f3728734SAlex Deucher return; 276f3728734SAlex Deucher 277f3728734SAlex Deucher if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU)) 278f3728734SAlex Deucher return; 279f3728734SAlex Deucher 280f3728734SAlex Deucher dig = radeon_encoder->enc_priv; 281f3728734SAlex Deucher bd = dig->bl_dev; 282f3728734SAlex Deucher dig->bl_dev = NULL; 283f3728734SAlex Deucher 284f3728734SAlex Deucher if (bd) { 285f3728734SAlex Deucher struct radeon_legacy_backlight_privdata *pdata; 286f3728734SAlex Deucher 287f3728734SAlex Deucher pdata = bl_get_data(bd); 288f3728734SAlex Deucher backlight_device_unregister(bd); 289f3728734SAlex Deucher kfree(pdata); 290f3728734SAlex Deucher 291f3728734SAlex Deucher DRM_INFO("radeon atom LVDS backlight unloaded\n"); 292f3728734SAlex Deucher } 293f3728734SAlex Deucher } 294f3728734SAlex Deucher 2953f03ced8SAlex Deucher static bool radeon_atom_mode_fixup(struct drm_encoder *encoder, 296e811f5aeSLaurent Pinchart const struct drm_display_mode *mode, 2973f03ced8SAlex Deucher struct drm_display_mode *adjusted_mode) 2983f03ced8SAlex Deucher { 2993f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 3003f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 3013f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 3023f03ced8SAlex Deucher 3033f03ced8SAlex Deucher /* set the active encoder to connector routing */ 3043f03ced8SAlex Deucher radeon_encoder_set_active_device(encoder); 3053f03ced8SAlex Deucher drm_mode_set_crtcinfo(adjusted_mode, 0); 3063f03ced8SAlex Deucher 3073f03ced8SAlex Deucher /* hw bug */ 3083f03ced8SAlex Deucher if ((mode->flags & DRM_MODE_FLAG_INTERLACE) 3093f03ced8SAlex Deucher && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2))) 3103f03ced8SAlex Deucher adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2; 3113f03ced8SAlex Deucher 3123104b812SAlex Deucher /* vertical FP must be at least 1 */ 3133104b812SAlex Deucher if (mode->crtc_vsync_start == mode->crtc_vdisplay) 3143104b812SAlex Deucher adjusted_mode->crtc_vsync_start++; 3153104b812SAlex Deucher 316da997620SAlex Deucher /* get the native mode for scaling */ 317da997620SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) { 3183f03ced8SAlex Deucher radeon_panel_mode_fixup(encoder, adjusted_mode); 319da997620SAlex Deucher } else if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) { 3203f03ced8SAlex Deucher struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv; 3213f03ced8SAlex Deucher if (tv_dac) { 3223f03ced8SAlex Deucher if (tv_dac->tv_std == TV_STD_NTSC || 3233f03ced8SAlex Deucher tv_dac->tv_std == TV_STD_NTSC_J || 3243f03ced8SAlex Deucher tv_dac->tv_std == TV_STD_PAL_M) 3253f03ced8SAlex Deucher radeon_atom_get_tv_timings(rdev, 0, adjusted_mode); 3263f03ced8SAlex Deucher else 3273f03ced8SAlex Deucher radeon_atom_get_tv_timings(rdev, 1, adjusted_mode); 3283f03ced8SAlex Deucher } 329da997620SAlex Deucher } else if (radeon_encoder->rmx_type != RMX_OFF) { 330da997620SAlex Deucher radeon_panel_mode_fixup(encoder, adjusted_mode); 3313f03ced8SAlex Deucher } 3323f03ced8SAlex Deucher 3333f03ced8SAlex Deucher if (ASIC_IS_DCE3(rdev) && 3343f03ced8SAlex Deucher ((radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) || 3353f03ced8SAlex Deucher (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE))) { 3363f03ced8SAlex Deucher struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 33793927f9cSAlex Deucher radeon_dp_set_link_config(connector, adjusted_mode); 3383f03ced8SAlex Deucher } 3393f03ced8SAlex Deucher 3403f03ced8SAlex Deucher return true; 3413f03ced8SAlex Deucher } 3423f03ced8SAlex Deucher 3433f03ced8SAlex Deucher static void 3443f03ced8SAlex Deucher atombios_dac_setup(struct drm_encoder *encoder, int action) 3453f03ced8SAlex Deucher { 3463f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 3473f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 3483f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 3493f03ced8SAlex Deucher DAC_ENCODER_CONTROL_PS_ALLOCATION args; 3503f03ced8SAlex Deucher int index = 0; 3513f03ced8SAlex Deucher struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv; 3523f03ced8SAlex Deucher 3533f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 3543f03ced8SAlex Deucher 3553f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 3563f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC1: 3573f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 3583f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl); 3593f03ced8SAlex Deucher break; 3603f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC2: 3613f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 3623f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl); 3633f03ced8SAlex Deucher break; 3643f03ced8SAlex Deucher } 3653f03ced8SAlex Deucher 3663f03ced8SAlex Deucher args.ucAction = action; 3673f03ced8SAlex Deucher 3683f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT)) 3693f03ced8SAlex Deucher args.ucDacStandard = ATOM_DAC1_PS2; 3703f03ced8SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 3713f03ced8SAlex Deucher args.ucDacStandard = ATOM_DAC1_CV; 3723f03ced8SAlex Deucher else { 3733f03ced8SAlex Deucher switch (dac_info->tv_std) { 3743f03ced8SAlex Deucher case TV_STD_PAL: 3753f03ced8SAlex Deucher case TV_STD_PAL_M: 3763f03ced8SAlex Deucher case TV_STD_SCART_PAL: 3773f03ced8SAlex Deucher case TV_STD_SECAM: 3783f03ced8SAlex Deucher case TV_STD_PAL_CN: 3793f03ced8SAlex Deucher args.ucDacStandard = ATOM_DAC1_PAL; 3803f03ced8SAlex Deucher break; 3813f03ced8SAlex Deucher case TV_STD_NTSC: 3823f03ced8SAlex Deucher case TV_STD_NTSC_J: 3833f03ced8SAlex Deucher case TV_STD_PAL_60: 3843f03ced8SAlex Deucher default: 3853f03ced8SAlex Deucher args.ucDacStandard = ATOM_DAC1_NTSC; 3863f03ced8SAlex Deucher break; 3873f03ced8SAlex Deucher } 3883f03ced8SAlex Deucher } 3893f03ced8SAlex Deucher args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 3903f03ced8SAlex Deucher 3913f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 3923f03ced8SAlex Deucher 3933f03ced8SAlex Deucher } 3943f03ced8SAlex Deucher 3953f03ced8SAlex Deucher static void 3963f03ced8SAlex Deucher atombios_tv_setup(struct drm_encoder *encoder, int action) 3973f03ced8SAlex Deucher { 3983f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 3993f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 4003f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 4013f03ced8SAlex Deucher TV_ENCODER_CONTROL_PS_ALLOCATION args; 4023f03ced8SAlex Deucher int index = 0; 4033f03ced8SAlex Deucher struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv; 4043f03ced8SAlex Deucher 4053f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 4063f03ced8SAlex Deucher 4073f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl); 4083f03ced8SAlex Deucher 4093f03ced8SAlex Deucher args.sTVEncoder.ucAction = action; 4103f03ced8SAlex Deucher 4113f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 4123f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_CV; 4133f03ced8SAlex Deucher else { 4143f03ced8SAlex Deucher switch (dac_info->tv_std) { 4153f03ced8SAlex Deucher case TV_STD_NTSC: 4163f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC; 4173f03ced8SAlex Deucher break; 4183f03ced8SAlex Deucher case TV_STD_PAL: 4193f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; 4203f03ced8SAlex Deucher break; 4213f03ced8SAlex Deucher case TV_STD_PAL_M: 4223f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_PALM; 4233f03ced8SAlex Deucher break; 4243f03ced8SAlex Deucher case TV_STD_PAL_60: 4253f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60; 4263f03ced8SAlex Deucher break; 4273f03ced8SAlex Deucher case TV_STD_NTSC_J: 4283f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ; 4293f03ced8SAlex Deucher break; 4303f03ced8SAlex Deucher case TV_STD_SCART_PAL: 4313f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */ 4323f03ced8SAlex Deucher break; 4333f03ced8SAlex Deucher case TV_STD_SECAM: 4343f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM; 4353f03ced8SAlex Deucher break; 4363f03ced8SAlex Deucher case TV_STD_PAL_CN: 4373f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN; 4383f03ced8SAlex Deucher break; 4393f03ced8SAlex Deucher default: 4403f03ced8SAlex Deucher args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC; 4413f03ced8SAlex Deucher break; 4423f03ced8SAlex Deucher } 4433f03ced8SAlex Deucher } 4443f03ced8SAlex Deucher 4453f03ced8SAlex Deucher args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 4463f03ced8SAlex Deucher 4473f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 4483f03ced8SAlex Deucher 4493f03ced8SAlex Deucher } 4503f03ced8SAlex Deucher 4511f0e2943SAlex Deucher static u8 radeon_atom_get_bpc(struct drm_encoder *encoder) 4521f0e2943SAlex Deucher { 4531f0e2943SAlex Deucher int bpc = 8; 4541f0e2943SAlex Deucher 4557d5a33b0SAlex Deucher if (encoder->crtc) { 4567d5a33b0SAlex Deucher struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 4577d5a33b0SAlex Deucher bpc = radeon_crtc->bpc; 4587d5a33b0SAlex Deucher } 4591f0e2943SAlex Deucher 4601f0e2943SAlex Deucher switch (bpc) { 4611f0e2943SAlex Deucher case 0: 4621f0e2943SAlex Deucher return PANEL_BPC_UNDEFINE; 4631f0e2943SAlex Deucher case 6: 4641f0e2943SAlex Deucher return PANEL_6BIT_PER_COLOR; 4651f0e2943SAlex Deucher case 8: 4661f0e2943SAlex Deucher default: 4671f0e2943SAlex Deucher return PANEL_8BIT_PER_COLOR; 4681f0e2943SAlex Deucher case 10: 4691f0e2943SAlex Deucher return PANEL_10BIT_PER_COLOR; 4701f0e2943SAlex Deucher case 12: 4711f0e2943SAlex Deucher return PANEL_12BIT_PER_COLOR; 4721f0e2943SAlex Deucher case 16: 4731f0e2943SAlex Deucher return PANEL_16BIT_PER_COLOR; 4741f0e2943SAlex Deucher } 4751f0e2943SAlex Deucher } 4761f0e2943SAlex Deucher 4773f03ced8SAlex Deucher union dvo_encoder_control { 4783f03ced8SAlex Deucher ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds; 4793f03ced8SAlex Deucher DVO_ENCODER_CONTROL_PS_ALLOCATION dvo; 4803f03ced8SAlex Deucher DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3; 481aea65641SAlex Deucher DVO_ENCODER_CONTROL_PS_ALLOCATION_V1_4 dvo_v4; 4823f03ced8SAlex Deucher }; 4833f03ced8SAlex Deucher 4843f03ced8SAlex Deucher void 4853f03ced8SAlex Deucher atombios_dvo_setup(struct drm_encoder *encoder, int action) 4863f03ced8SAlex Deucher { 4873f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 4883f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 4893f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 4903f03ced8SAlex Deucher union dvo_encoder_control args; 4913f03ced8SAlex Deucher int index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl); 49224153dd3SAlex Deucher uint8_t frev, crev; 4933f03ced8SAlex Deucher 4943f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 4953f03ced8SAlex Deucher 49624153dd3SAlex Deucher if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 49724153dd3SAlex Deucher return; 49824153dd3SAlex Deucher 499afceb931SAlex Deucher /* some R4xx chips have the wrong frev */ 500afceb931SAlex Deucher if (rdev->family <= CHIP_RV410) 501afceb931SAlex Deucher frev = 1; 502afceb931SAlex Deucher 50324153dd3SAlex Deucher switch (frev) { 50424153dd3SAlex Deucher case 1: 50524153dd3SAlex Deucher switch (crev) { 50624153dd3SAlex Deucher case 1: 50724153dd3SAlex Deucher /* R4xx, R5xx */ 50824153dd3SAlex Deucher args.ext_tmds.sXTmdsEncoder.ucEnable = action; 50924153dd3SAlex Deucher 5109aa59993SAlex Deucher if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 51124153dd3SAlex Deucher args.ext_tmds.sXTmdsEncoder.ucMisc |= PANEL_ENCODER_MISC_DUAL; 51224153dd3SAlex Deucher 51324153dd3SAlex Deucher args.ext_tmds.sXTmdsEncoder.ucMisc |= ATOM_PANEL_MISC_888RGB; 51424153dd3SAlex Deucher break; 51524153dd3SAlex Deucher case 2: 51624153dd3SAlex Deucher /* RS600/690/740 */ 5173f03ced8SAlex Deucher args.dvo.sDVOEncoder.ucAction = action; 5183f03ced8SAlex Deucher args.dvo.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 5193f03ced8SAlex Deucher /* DFP1, CRT1, TV1 depending on the type of port */ 5203f03ced8SAlex Deucher args.dvo.sDVOEncoder.ucDeviceType = ATOM_DEVICE_DFP1_INDEX; 5213f03ced8SAlex Deucher 5229aa59993SAlex Deucher if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 5233f03ced8SAlex Deucher args.dvo.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute |= PANEL_ENCODER_MISC_DUAL; 52424153dd3SAlex Deucher break; 52524153dd3SAlex Deucher case 3: 52624153dd3SAlex Deucher /* R6xx */ 52724153dd3SAlex Deucher args.dvo_v3.ucAction = action; 52824153dd3SAlex Deucher args.dvo_v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 52924153dd3SAlex Deucher args.dvo_v3.ucDVOConfig = 0; /* XXX */ 53024153dd3SAlex Deucher break; 531aea65641SAlex Deucher case 4: 532aea65641SAlex Deucher /* DCE8 */ 533aea65641SAlex Deucher args.dvo_v4.ucAction = action; 534aea65641SAlex Deucher args.dvo_v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 535aea65641SAlex Deucher args.dvo_v4.ucDVOConfig = 0; /* XXX */ 536aea65641SAlex Deucher args.dvo_v4.ucBitPerColor = radeon_atom_get_bpc(encoder); 537aea65641SAlex Deucher break; 53824153dd3SAlex Deucher default: 53924153dd3SAlex Deucher DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 54024153dd3SAlex Deucher break; 54124153dd3SAlex Deucher } 54224153dd3SAlex Deucher break; 54324153dd3SAlex Deucher default: 54424153dd3SAlex Deucher DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 54524153dd3SAlex Deucher break; 5463f03ced8SAlex Deucher } 5473f03ced8SAlex Deucher 5483f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 5493f03ced8SAlex Deucher } 5503f03ced8SAlex Deucher 5513f03ced8SAlex Deucher union lvds_encoder_control { 5523f03ced8SAlex Deucher LVDS_ENCODER_CONTROL_PS_ALLOCATION v1; 5533f03ced8SAlex Deucher LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2; 5543f03ced8SAlex Deucher }; 5553f03ced8SAlex Deucher 5563f03ced8SAlex Deucher void 5573f03ced8SAlex Deucher atombios_digital_setup(struct drm_encoder *encoder, int action) 5583f03ced8SAlex Deucher { 5593f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 5603f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 5613f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 5623f03ced8SAlex Deucher struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 5633f03ced8SAlex Deucher union lvds_encoder_control args; 5643f03ced8SAlex Deucher int index = 0; 5653f03ced8SAlex Deucher int hdmi_detected = 0; 5663f03ced8SAlex Deucher uint8_t frev, crev; 5673f03ced8SAlex Deucher 5683f03ced8SAlex Deucher if (!dig) 5693f03ced8SAlex Deucher return; 5703f03ced8SAlex Deucher 5713f03ced8SAlex Deucher if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) 5723f03ced8SAlex Deucher hdmi_detected = 1; 5733f03ced8SAlex Deucher 5743f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 5753f03ced8SAlex Deucher 5763f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 5773f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVDS: 5783f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl); 5793f03ced8SAlex Deucher break; 5803f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 5813f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 5823f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl); 5833f03ced8SAlex Deucher break; 5843f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 5853f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 5863f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl); 5873f03ced8SAlex Deucher else 5883f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl); 5893f03ced8SAlex Deucher break; 5903f03ced8SAlex Deucher } 5913f03ced8SAlex Deucher 5923f03ced8SAlex Deucher if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 5933f03ced8SAlex Deucher return; 5943f03ced8SAlex Deucher 5953f03ced8SAlex Deucher switch (frev) { 5963f03ced8SAlex Deucher case 1: 5973f03ced8SAlex Deucher case 2: 5983f03ced8SAlex Deucher switch (crev) { 5993f03ced8SAlex Deucher case 1: 6003f03ced8SAlex Deucher args.v1.ucMisc = 0; 6013f03ced8SAlex Deucher args.v1.ucAction = action; 6023f03ced8SAlex Deucher if (hdmi_detected) 6033f03ced8SAlex Deucher args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE; 6043f03ced8SAlex Deucher args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 6053f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 6063f03ced8SAlex Deucher if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL) 6073f03ced8SAlex Deucher args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; 6083f03ced8SAlex Deucher if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB) 6093f03ced8SAlex Deucher args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB; 6103f03ced8SAlex Deucher } else { 6113f03ced8SAlex Deucher if (dig->linkb) 6123f03ced8SAlex Deucher args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; 6139aa59993SAlex Deucher if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 6143f03ced8SAlex Deucher args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; 6153f03ced8SAlex Deucher /*if (pScrn->rgbBits == 8) */ 6163f03ced8SAlex Deucher args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB; 6173f03ced8SAlex Deucher } 6183f03ced8SAlex Deucher break; 6193f03ced8SAlex Deucher case 2: 6203f03ced8SAlex Deucher case 3: 6213f03ced8SAlex Deucher args.v2.ucMisc = 0; 6223f03ced8SAlex Deucher args.v2.ucAction = action; 6233f03ced8SAlex Deucher if (crev == 3) { 6243f03ced8SAlex Deucher if (dig->coherent_mode) 6253f03ced8SAlex Deucher args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT; 6263f03ced8SAlex Deucher } 6273f03ced8SAlex Deucher if (hdmi_detected) 6283f03ced8SAlex Deucher args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE; 6293f03ced8SAlex Deucher args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 6303f03ced8SAlex Deucher args.v2.ucTruncate = 0; 6313f03ced8SAlex Deucher args.v2.ucSpatial = 0; 6323f03ced8SAlex Deucher args.v2.ucTemporal = 0; 6333f03ced8SAlex Deucher args.v2.ucFRC = 0; 6343f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 6353f03ced8SAlex Deucher if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL) 6363f03ced8SAlex Deucher args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL; 6373f03ced8SAlex Deucher if (dig->lcd_misc & ATOM_PANEL_MISC_SPATIAL) { 6383f03ced8SAlex Deucher args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN; 6393f03ced8SAlex Deucher if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB) 6403f03ced8SAlex Deucher args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH; 6413f03ced8SAlex Deucher } 6423f03ced8SAlex Deucher if (dig->lcd_misc & ATOM_PANEL_MISC_TEMPORAL) { 6433f03ced8SAlex Deucher args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN; 6443f03ced8SAlex Deucher if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB) 6453f03ced8SAlex Deucher args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH; 6463f03ced8SAlex Deucher if (((dig->lcd_misc >> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT) & 0x3) == 2) 6473f03ced8SAlex Deucher args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4; 6483f03ced8SAlex Deucher } 6493f03ced8SAlex Deucher } else { 6503f03ced8SAlex Deucher if (dig->linkb) 6513f03ced8SAlex Deucher args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; 6529aa59993SAlex Deucher if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 6533f03ced8SAlex Deucher args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL; 6543f03ced8SAlex Deucher } 6553f03ced8SAlex Deucher break; 6563f03ced8SAlex Deucher default: 6573f03ced8SAlex Deucher DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 6583f03ced8SAlex Deucher break; 6593f03ced8SAlex Deucher } 6603f03ced8SAlex Deucher break; 6613f03ced8SAlex Deucher default: 6623f03ced8SAlex Deucher DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 6633f03ced8SAlex Deucher break; 6643f03ced8SAlex Deucher } 6653f03ced8SAlex Deucher 6663f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 6673f03ced8SAlex Deucher } 6683f03ced8SAlex Deucher 6693f03ced8SAlex Deucher int 6703f03ced8SAlex Deucher atombios_get_encoder_mode(struct drm_encoder *encoder) 6713f03ced8SAlex Deucher { 672e55bca26SSlava Grigorev struct drm_device *dev = encoder->dev; 673e55bca26SSlava Grigorev struct radeon_device *rdev = dev->dev_private; 6743f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 6753f03ced8SAlex Deucher struct drm_connector *connector; 6763f03ced8SAlex Deucher struct radeon_connector *radeon_connector; 6773f03ced8SAlex Deucher struct radeon_connector_atom_dig *dig_connector; 6783f03ced8SAlex Deucher 6793f03ced8SAlex Deucher /* dp bridges are always DP */ 6803f03ced8SAlex Deucher if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE) 6813f03ced8SAlex Deucher return ATOM_ENCODER_MODE_DP; 6823f03ced8SAlex Deucher 6833f03ced8SAlex Deucher /* DVO is always DVO */ 684a59fbb8eSAlex Deucher if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DVO1) || 685a59fbb8eSAlex Deucher (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1)) 6863f03ced8SAlex Deucher return ATOM_ENCODER_MODE_DVO; 6873f03ced8SAlex Deucher 6883f03ced8SAlex Deucher connector = radeon_get_connector_for_encoder(encoder); 6893f03ced8SAlex Deucher /* if we don't have an active device yet, just use one of 6903f03ced8SAlex Deucher * the connectors tied to the encoder. 6913f03ced8SAlex Deucher */ 6923f03ced8SAlex Deucher if (!connector) 6933f03ced8SAlex Deucher connector = radeon_get_connector_for_encoder_init(encoder); 6943f03ced8SAlex Deucher radeon_connector = to_radeon_connector(connector); 6953f03ced8SAlex Deucher 6963f03ced8SAlex Deucher switch (connector->connector_type) { 6973f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_DVII: 6983f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */ 699108dc8e8SAlex Deucher if (radeon_audio != 0) { 700108dc8e8SAlex Deucher if (radeon_connector->use_digital && 701108dc8e8SAlex Deucher (radeon_connector->audio == RADEON_AUDIO_ENABLE)) 702108dc8e8SAlex Deucher return ATOM_ENCODER_MODE_HDMI; 703377bd8a9SAlex Deucher else if (drm_detect_hdmi_monitor(radeon_connector_edid(connector)) && 704108dc8e8SAlex Deucher (radeon_connector->audio == RADEON_AUDIO_AUTO)) 7053f03ced8SAlex Deucher return ATOM_ENCODER_MODE_HDMI; 706f92e70caSRafał Miłecki else if (radeon_connector->use_digital) 7073f03ced8SAlex Deucher return ATOM_ENCODER_MODE_DVI; 7083f03ced8SAlex Deucher else 7093f03ced8SAlex Deucher return ATOM_ENCODER_MODE_CRT; 710108dc8e8SAlex Deucher } else if (radeon_connector->use_digital) { 711108dc8e8SAlex Deucher return ATOM_ENCODER_MODE_DVI; 712108dc8e8SAlex Deucher } else { 713108dc8e8SAlex Deucher return ATOM_ENCODER_MODE_CRT; 714108dc8e8SAlex Deucher } 7153f03ced8SAlex Deucher break; 7163f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_DVID: 7173f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_HDMIA: 7183f03ced8SAlex Deucher default: 719108dc8e8SAlex Deucher if (radeon_audio != 0) { 720108dc8e8SAlex Deucher if (radeon_connector->audio == RADEON_AUDIO_ENABLE) 721108dc8e8SAlex Deucher return ATOM_ENCODER_MODE_HDMI; 722377bd8a9SAlex Deucher else if (drm_detect_hdmi_monitor(radeon_connector_edid(connector)) && 723108dc8e8SAlex Deucher (radeon_connector->audio == RADEON_AUDIO_AUTO)) 7243f03ced8SAlex Deucher return ATOM_ENCODER_MODE_HDMI; 725f92e70caSRafał Miłecki else 7263f03ced8SAlex Deucher return ATOM_ENCODER_MODE_DVI; 727108dc8e8SAlex Deucher } else { 728108dc8e8SAlex Deucher return ATOM_ENCODER_MODE_DVI; 729108dc8e8SAlex Deucher } 7303f03ced8SAlex Deucher break; 7313f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_LVDS: 7323f03ced8SAlex Deucher return ATOM_ENCODER_MODE_LVDS; 7333f03ced8SAlex Deucher break; 7343f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_DisplayPort: 7353f03ced8SAlex Deucher dig_connector = radeon_connector->con_priv; 7363f03ced8SAlex Deucher if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) || 737108dc8e8SAlex Deucher (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) { 7383473f542SAlex Deucher if (radeon_audio != 0 && 7393473f542SAlex Deucher drm_detect_monitor_audio(radeon_connector_edid(connector)) && 7403473f542SAlex Deucher ASIC_IS_DCE4(rdev) && !ASIC_IS_DCE5(rdev)) 741e55bca26SSlava Grigorev return ATOM_ENCODER_MODE_DP_AUDIO; 7423f03ced8SAlex Deucher return ATOM_ENCODER_MODE_DP; 743108dc8e8SAlex Deucher } else if (radeon_audio != 0) { 744108dc8e8SAlex Deucher if (radeon_connector->audio == RADEON_AUDIO_ENABLE) 745108dc8e8SAlex Deucher return ATOM_ENCODER_MODE_HDMI; 746377bd8a9SAlex Deucher else if (drm_detect_hdmi_monitor(radeon_connector_edid(connector)) && 747108dc8e8SAlex Deucher (radeon_connector->audio == RADEON_AUDIO_AUTO)) 7483f03ced8SAlex Deucher return ATOM_ENCODER_MODE_HDMI; 749f92e70caSRafał Miłecki else 7503f03ced8SAlex Deucher return ATOM_ENCODER_MODE_DVI; 751108dc8e8SAlex Deucher } else { 752108dc8e8SAlex Deucher return ATOM_ENCODER_MODE_DVI; 753108dc8e8SAlex Deucher } 7543f03ced8SAlex Deucher break; 7553f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_eDP: 7563473f542SAlex Deucher if (radeon_audio != 0 && 7573473f542SAlex Deucher drm_detect_monitor_audio(radeon_connector_edid(connector)) && 7583473f542SAlex Deucher ASIC_IS_DCE4(rdev) && !ASIC_IS_DCE5(rdev)) 759e55bca26SSlava Grigorev return ATOM_ENCODER_MODE_DP_AUDIO; 7603f03ced8SAlex Deucher return ATOM_ENCODER_MODE_DP; 7613f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_DVIA: 7623f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_VGA: 7633f03ced8SAlex Deucher return ATOM_ENCODER_MODE_CRT; 7643f03ced8SAlex Deucher break; 7653f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_Composite: 7663f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_SVIDEO: 7673f03ced8SAlex Deucher case DRM_MODE_CONNECTOR_9PinDIN: 7683f03ced8SAlex Deucher /* fix me */ 7693f03ced8SAlex Deucher return ATOM_ENCODER_MODE_TV; 7703f03ced8SAlex Deucher /*return ATOM_ENCODER_MODE_CV;*/ 7713f03ced8SAlex Deucher break; 7723f03ced8SAlex Deucher } 7733f03ced8SAlex Deucher } 7743f03ced8SAlex Deucher 7753f03ced8SAlex Deucher /* 7763f03ced8SAlex Deucher * DIG Encoder/Transmitter Setup 7773f03ced8SAlex Deucher * 7783f03ced8SAlex Deucher * DCE 3.0/3.1 7793f03ced8SAlex Deucher * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA. 7803f03ced8SAlex Deucher * Supports up to 3 digital outputs 7813f03ced8SAlex Deucher * - 2 DIG encoder blocks. 7823f03ced8SAlex Deucher * DIG1 can drive UNIPHY link A or link B 7833f03ced8SAlex Deucher * DIG2 can drive UNIPHY link B or LVTMA 7843f03ced8SAlex Deucher * 7853f03ced8SAlex Deucher * DCE 3.2 7863f03ced8SAlex Deucher * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B). 7873f03ced8SAlex Deucher * Supports up to 5 digital outputs 7883f03ced8SAlex Deucher * - 2 DIG encoder blocks. 7893f03ced8SAlex Deucher * DIG1/2 can drive UNIPHY0/1/2 link A or link B 7903f03ced8SAlex Deucher * 7912d415869SAlex Deucher * DCE 4.0/5.0/6.0 7923f03ced8SAlex Deucher * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B). 7933f03ced8SAlex Deucher * Supports up to 6 digital outputs 7943f03ced8SAlex Deucher * - 6 DIG encoder blocks. 7953f03ced8SAlex Deucher * - DIG to PHY mapping is hardcoded 7963f03ced8SAlex Deucher * DIG1 drives UNIPHY0 link A, A+B 7973f03ced8SAlex Deucher * DIG2 drives UNIPHY0 link B 7983f03ced8SAlex Deucher * DIG3 drives UNIPHY1 link A, A+B 7993f03ced8SAlex Deucher * DIG4 drives UNIPHY1 link B 8003f03ced8SAlex Deucher * DIG5 drives UNIPHY2 link A, A+B 8013f03ced8SAlex Deucher * DIG6 drives UNIPHY2 link B 8023f03ced8SAlex Deucher * 8033f03ced8SAlex Deucher * DCE 4.1 8043f03ced8SAlex Deucher * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B). 8053f03ced8SAlex Deucher * Supports up to 6 digital outputs 8063f03ced8SAlex Deucher * - 2 DIG encoder blocks. 8072d415869SAlex Deucher * llano 8083f03ced8SAlex Deucher * DIG1/2 can drive UNIPHY0/1/2 link A or link B 8092d415869SAlex Deucher * ontario 8102d415869SAlex Deucher * DIG1 drives UNIPHY0/1/2 link A 8112d415869SAlex Deucher * DIG2 drives UNIPHY0/1/2 link B 8123f03ced8SAlex Deucher * 8133f03ced8SAlex Deucher * Routing 8143f03ced8SAlex Deucher * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links) 8153f03ced8SAlex Deucher * Examples: 8163f03ced8SAlex Deucher * crtc0 -> dig2 -> LVTMA links A+B -> TMDS/HDMI 8173f03ced8SAlex Deucher * crtc1 -> dig1 -> UNIPHY0 link B -> DP 8183f03ced8SAlex Deucher * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS 8193f03ced8SAlex Deucher * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI 8203f03ced8SAlex Deucher */ 8213f03ced8SAlex Deucher 8223f03ced8SAlex Deucher union dig_encoder_control { 8233f03ced8SAlex Deucher DIG_ENCODER_CONTROL_PS_ALLOCATION v1; 8243f03ced8SAlex Deucher DIG_ENCODER_CONTROL_PARAMETERS_V2 v2; 8253f03ced8SAlex Deucher DIG_ENCODER_CONTROL_PARAMETERS_V3 v3; 8263f03ced8SAlex Deucher DIG_ENCODER_CONTROL_PARAMETERS_V4 v4; 8273f03ced8SAlex Deucher }; 8283f03ced8SAlex Deucher 8293f03ced8SAlex Deucher void 830bf071900SDave Airlie atombios_dig_encoder_setup2(struct drm_encoder *encoder, int action, int panel_mode, int enc_override) 8313f03ced8SAlex Deucher { 8323f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 8333f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 8343f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 8353f03ced8SAlex Deucher struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 8363f03ced8SAlex Deucher struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 8373f03ced8SAlex Deucher union dig_encoder_control args; 8383f03ced8SAlex Deucher int index = 0; 8393f03ced8SAlex Deucher uint8_t frev, crev; 8403f03ced8SAlex Deucher int dp_clock = 0; 8413f03ced8SAlex Deucher int dp_lane_count = 0; 8423f03ced8SAlex Deucher int hpd_id = RADEON_HPD_NONE; 8433f03ced8SAlex Deucher 8443f03ced8SAlex Deucher if (connector) { 8453f03ced8SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 8463f03ced8SAlex Deucher struct radeon_connector_atom_dig *dig_connector = 8473f03ced8SAlex Deucher radeon_connector->con_priv; 8483f03ced8SAlex Deucher 8493f03ced8SAlex Deucher dp_clock = dig_connector->dp_clock; 8503f03ced8SAlex Deucher dp_lane_count = dig_connector->dp_lane_count; 8513f03ced8SAlex Deucher hpd_id = radeon_connector->hpd.hpd; 8523f03ced8SAlex Deucher } 8533f03ced8SAlex Deucher 8543f03ced8SAlex Deucher /* no dig encoder assigned */ 8553f03ced8SAlex Deucher if (dig->dig_encoder == -1) 8563f03ced8SAlex Deucher return; 8573f03ced8SAlex Deucher 8583f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 8593f03ced8SAlex Deucher 8603f03ced8SAlex Deucher if (ASIC_IS_DCE4(rdev)) 8613f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DIGxEncoderControl); 8623f03ced8SAlex Deucher else { 8633f03ced8SAlex Deucher if (dig->dig_encoder) 8643f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); 8653f03ced8SAlex Deucher else 8663f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); 8673f03ced8SAlex Deucher } 8683f03ced8SAlex Deucher 8693f03ced8SAlex Deucher if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 8703f03ced8SAlex Deucher return; 8713f03ced8SAlex Deucher 87258cdcb8bSAlex Deucher switch (frev) { 87358cdcb8bSAlex Deucher case 1: 87458cdcb8bSAlex Deucher switch (crev) { 87558cdcb8bSAlex Deucher case 1: 8763f03ced8SAlex Deucher args.v1.ucAction = action; 8773f03ced8SAlex Deucher args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 8783f03ced8SAlex Deucher if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE) 8793f03ced8SAlex Deucher args.v3.ucPanelMode = panel_mode; 8803f03ced8SAlex Deucher else 8813f03ced8SAlex Deucher args.v1.ucEncoderMode = atombios_get_encoder_mode(encoder); 8823f03ced8SAlex Deucher 8833f03ced8SAlex Deucher if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode)) 8843f03ced8SAlex Deucher args.v1.ucLaneNum = dp_lane_count; 8859aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 8863f03ced8SAlex Deucher args.v1.ucLaneNum = 8; 8873f03ced8SAlex Deucher else 8883f03ced8SAlex Deucher args.v1.ucLaneNum = 4; 8893f03ced8SAlex Deucher 89058cdcb8bSAlex Deucher switch (radeon_encoder->encoder_id) { 89158cdcb8bSAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 89258cdcb8bSAlex Deucher args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1; 89358cdcb8bSAlex Deucher break; 89458cdcb8bSAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 89558cdcb8bSAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 89658cdcb8bSAlex Deucher args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2; 89758cdcb8bSAlex Deucher break; 89858cdcb8bSAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 89958cdcb8bSAlex Deucher args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3; 90058cdcb8bSAlex Deucher break; 90158cdcb8bSAlex Deucher } 90258cdcb8bSAlex Deucher if (dig->linkb) 90358cdcb8bSAlex Deucher args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKB; 90458cdcb8bSAlex Deucher else 90558cdcb8bSAlex Deucher args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKA; 906459ee1c3SMario Kleiner 907459ee1c3SMario Kleiner if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode) && (dp_clock == 270000)) 908459ee1c3SMario Kleiner args.v1.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ; 909459ee1c3SMario Kleiner 91058cdcb8bSAlex Deucher break; 91158cdcb8bSAlex Deucher case 2: 91258cdcb8bSAlex Deucher case 3: 91358cdcb8bSAlex Deucher args.v3.ucAction = action; 91458cdcb8bSAlex Deucher args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 91558cdcb8bSAlex Deucher if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE) 91658cdcb8bSAlex Deucher args.v3.ucPanelMode = panel_mode; 91758cdcb8bSAlex Deucher else 91858cdcb8bSAlex Deucher args.v3.ucEncoderMode = atombios_get_encoder_mode(encoder); 91958cdcb8bSAlex Deucher 9202f6fa79aSAlex Deucher if (ENCODER_MODE_IS_DP(args.v3.ucEncoderMode)) 92158cdcb8bSAlex Deucher args.v3.ucLaneNum = dp_lane_count; 9229aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 92358cdcb8bSAlex Deucher args.v3.ucLaneNum = 8; 92458cdcb8bSAlex Deucher else 92558cdcb8bSAlex Deucher args.v3.ucLaneNum = 4; 92658cdcb8bSAlex Deucher 9272f6fa79aSAlex Deucher if (ENCODER_MODE_IS_DP(args.v3.ucEncoderMode) && (dp_clock == 270000)) 92858cdcb8bSAlex Deucher args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ; 929bf071900SDave Airlie if (enc_override != -1) 930bf071900SDave Airlie args.v3.acConfig.ucDigSel = enc_override; 931bf071900SDave Airlie else 93258cdcb8bSAlex Deucher args.v3.acConfig.ucDigSel = dig->dig_encoder; 9331f0e2943SAlex Deucher args.v3.ucBitPerColor = radeon_atom_get_bpc(encoder); 93458cdcb8bSAlex Deucher break; 93558cdcb8bSAlex Deucher case 4: 93658cdcb8bSAlex Deucher args.v4.ucAction = action; 93758cdcb8bSAlex Deucher args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 93858cdcb8bSAlex Deucher if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE) 93958cdcb8bSAlex Deucher args.v4.ucPanelMode = panel_mode; 94058cdcb8bSAlex Deucher else 94158cdcb8bSAlex Deucher args.v4.ucEncoderMode = atombios_get_encoder_mode(encoder); 94258cdcb8bSAlex Deucher 9432f6fa79aSAlex Deucher if (ENCODER_MODE_IS_DP(args.v4.ucEncoderMode)) 94458cdcb8bSAlex Deucher args.v4.ucLaneNum = dp_lane_count; 9459aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 94658cdcb8bSAlex Deucher args.v4.ucLaneNum = 8; 94758cdcb8bSAlex Deucher else 94858cdcb8bSAlex Deucher args.v4.ucLaneNum = 4; 94958cdcb8bSAlex Deucher 9502f6fa79aSAlex Deucher if (ENCODER_MODE_IS_DP(args.v4.ucEncoderMode)) { 951e68adef8SAlex Deucher if (dp_clock == 540000) 9523f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_5_40GHZ; 953e68adef8SAlex Deucher else if (dp_clock == 324000) 954e68adef8SAlex Deucher args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_3_24GHZ; 955e68adef8SAlex Deucher else if (dp_clock == 270000) 956e68adef8SAlex Deucher args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_2_70GHZ; 957e68adef8SAlex Deucher else 958e68adef8SAlex Deucher args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_1_62GHZ; 9593f03ced8SAlex Deucher } 960bf071900SDave Airlie 961bf071900SDave Airlie if (enc_override != -1) 962bf071900SDave Airlie args.v4.acConfig.ucDigSel = enc_override; 963bf071900SDave Airlie else 9643f03ced8SAlex Deucher args.v4.acConfig.ucDigSel = dig->dig_encoder; 9651f0e2943SAlex Deucher args.v4.ucBitPerColor = radeon_atom_get_bpc(encoder); 9663f03ced8SAlex Deucher if (hpd_id == RADEON_HPD_NONE) 9673f03ced8SAlex Deucher args.v4.ucHPD_ID = 0; 9683f03ced8SAlex Deucher else 9693f03ced8SAlex Deucher args.v4.ucHPD_ID = hpd_id + 1; 9703f03ced8SAlex Deucher break; 9713f03ced8SAlex Deucher default: 97258cdcb8bSAlex Deucher DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 9733f03ced8SAlex Deucher break; 9743f03ced8SAlex Deucher } 9753f03ced8SAlex Deucher break; 97658cdcb8bSAlex Deucher default: 97758cdcb8bSAlex Deucher DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 9783f03ced8SAlex Deucher break; 9793f03ced8SAlex Deucher } 9803f03ced8SAlex Deucher 9813f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 9823f03ced8SAlex Deucher 9833f03ced8SAlex Deucher } 9843f03ced8SAlex Deucher 985bf071900SDave Airlie void 986bf071900SDave Airlie atombios_dig_encoder_setup(struct drm_encoder *encoder, int action, int panel_mode) 987bf071900SDave Airlie { 988bf071900SDave Airlie atombios_dig_encoder_setup2(encoder, action, panel_mode, -1); 989bf071900SDave Airlie } 990bf071900SDave Airlie 9913f03ced8SAlex Deucher union dig_transmitter_control { 9923f03ced8SAlex Deucher DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1; 9933f03ced8SAlex Deucher DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2; 9943f03ced8SAlex Deucher DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3; 9953f03ced8SAlex Deucher DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4; 99647aef7a8SAlex Deucher DIG_TRANSMITTER_CONTROL_PARAMETERS_V1_5 v5; 9973f03ced8SAlex Deucher }; 9983f03ced8SAlex Deucher 9993f03ced8SAlex Deucher void 1000bf071900SDave Airlie atombios_dig_transmitter_setup2(struct drm_encoder *encoder, int action, uint8_t lane_num, uint8_t lane_set, int fe) 10013f03ced8SAlex Deucher { 10023f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 10033f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 10043f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 10053f03ced8SAlex Deucher struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 10063f03ced8SAlex Deucher struct drm_connector *connector; 10073f03ced8SAlex Deucher union dig_transmitter_control args; 10083f03ced8SAlex Deucher int index = 0; 10093f03ced8SAlex Deucher uint8_t frev, crev; 10103f03ced8SAlex Deucher bool is_dp = false; 10113f03ced8SAlex Deucher int pll_id = 0; 10123f03ced8SAlex Deucher int dp_clock = 0; 10133f03ced8SAlex Deucher int dp_lane_count = 0; 10143f03ced8SAlex Deucher int connector_object_id = 0; 10153f03ced8SAlex Deucher int igp_lane_info = 0; 10163f03ced8SAlex Deucher int dig_encoder = dig->dig_encoder; 101747aef7a8SAlex Deucher int hpd_id = RADEON_HPD_NONE; 10183f03ced8SAlex Deucher 10193f03ced8SAlex Deucher if (action == ATOM_TRANSMITTER_ACTION_INIT) { 10203f03ced8SAlex Deucher connector = radeon_get_connector_for_encoder_init(encoder); 10213f03ced8SAlex Deucher /* just needed to avoid bailing in the encoder check. the encoder 10223f03ced8SAlex Deucher * isn't used for init 10233f03ced8SAlex Deucher */ 10243f03ced8SAlex Deucher dig_encoder = 0; 10253f03ced8SAlex Deucher } else 10263f03ced8SAlex Deucher connector = radeon_get_connector_for_encoder(encoder); 10273f03ced8SAlex Deucher 10283f03ced8SAlex Deucher if (connector) { 10293f03ced8SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 10303f03ced8SAlex Deucher struct radeon_connector_atom_dig *dig_connector = 10313f03ced8SAlex Deucher radeon_connector->con_priv; 10323f03ced8SAlex Deucher 103347aef7a8SAlex Deucher hpd_id = radeon_connector->hpd.hpd; 10343f03ced8SAlex Deucher dp_clock = dig_connector->dp_clock; 10353f03ced8SAlex Deucher dp_lane_count = dig_connector->dp_lane_count; 10363f03ced8SAlex Deucher connector_object_id = 10373f03ced8SAlex Deucher (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; 10383f03ced8SAlex Deucher igp_lane_info = dig_connector->igp_lane_info; 10393f03ced8SAlex Deucher } 10403f03ced8SAlex Deucher 1041a3b08294SAlex Deucher if (encoder->crtc) { 1042a3b08294SAlex Deucher struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 1043a3b08294SAlex Deucher pll_id = radeon_crtc->pll_id; 1044a3b08294SAlex Deucher } 1045a3b08294SAlex Deucher 10463f03ced8SAlex Deucher /* no dig encoder assigned */ 10473f03ced8SAlex Deucher if (dig_encoder == -1) 10483f03ced8SAlex Deucher return; 10493f03ced8SAlex Deucher 10503f03ced8SAlex Deucher if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder))) 10513f03ced8SAlex Deucher is_dp = true; 10523f03ced8SAlex Deucher 10533f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 10543f03ced8SAlex Deucher 10553f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 10563f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 10573f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl); 10583f03ced8SAlex Deucher break; 10593f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 10603f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 10613f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1062e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 10633f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl); 10643f03ced8SAlex Deucher break; 10653f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 10663f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, LVTMATransmitterControl); 10673f03ced8SAlex Deucher break; 10683f03ced8SAlex Deucher } 10693f03ced8SAlex Deucher 10703f03ced8SAlex Deucher if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 10713f03ced8SAlex Deucher return; 10723f03ced8SAlex Deucher 1073a3b08294SAlex Deucher switch (frev) { 1074a3b08294SAlex Deucher case 1: 1075a3b08294SAlex Deucher switch (crev) { 1076a3b08294SAlex Deucher case 1: 10773f03ced8SAlex Deucher args.v1.ucAction = action; 10783f03ced8SAlex Deucher if (action == ATOM_TRANSMITTER_ACTION_INIT) { 10793f03ced8SAlex Deucher args.v1.usInitInfo = cpu_to_le16(connector_object_id); 10803f03ced8SAlex Deucher } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) { 10813f03ced8SAlex Deucher args.v1.asMode.ucLaneSel = lane_num; 10823f03ced8SAlex Deucher args.v1.asMode.ucLaneSet = lane_set; 10833f03ced8SAlex Deucher } else { 10843f03ced8SAlex Deucher if (is_dp) 10856e76a2dfSAlex Deucher args.v1.usPixelClock = cpu_to_le16(dp_clock / 10); 10869aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 10873f03ced8SAlex Deucher args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10); 10883f03ced8SAlex Deucher else 10893f03ced8SAlex Deucher args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 10903f03ced8SAlex Deucher } 10913f03ced8SAlex Deucher 10923f03ced8SAlex Deucher args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL; 10933f03ced8SAlex Deucher 10943f03ced8SAlex Deucher if (dig_encoder) 10953f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER; 10963f03ced8SAlex Deucher else 10973f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER; 10983f03ced8SAlex Deucher 10993f03ced8SAlex Deucher if ((rdev->flags & RADEON_IS_IGP) && 11003f03ced8SAlex Deucher (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY)) { 11019aa59993SAlex Deucher if (is_dp || 11029aa59993SAlex Deucher !radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) { 11033f03ced8SAlex Deucher if (igp_lane_info & 0x1) 11043f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3; 11053f03ced8SAlex Deucher else if (igp_lane_info & 0x2) 11063f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7; 11073f03ced8SAlex Deucher else if (igp_lane_info & 0x4) 11083f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11; 11093f03ced8SAlex Deucher else if (igp_lane_info & 0x8) 11103f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15; 11113f03ced8SAlex Deucher } else { 11123f03ced8SAlex Deucher if (igp_lane_info & 0x3) 11133f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7; 11143f03ced8SAlex Deucher else if (igp_lane_info & 0xc) 11153f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15; 11163f03ced8SAlex Deucher } 11173f03ced8SAlex Deucher } 11183f03ced8SAlex Deucher 11193f03ced8SAlex Deucher if (dig->linkb) 11203f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB; 11213f03ced8SAlex Deucher else 11223f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA; 11233f03ced8SAlex Deucher 11243f03ced8SAlex Deucher if (is_dp) 11253f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT; 11263f03ced8SAlex Deucher else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 11273f03ced8SAlex Deucher if (dig->coherent_mode) 11283f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT; 11299aa59993SAlex Deucher if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 11303f03ced8SAlex Deucher args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK; 11313f03ced8SAlex Deucher } 1132a3b08294SAlex Deucher break; 1133a3b08294SAlex Deucher case 2: 1134a3b08294SAlex Deucher args.v2.ucAction = action; 1135a3b08294SAlex Deucher if (action == ATOM_TRANSMITTER_ACTION_INIT) { 1136a3b08294SAlex Deucher args.v2.usInitInfo = cpu_to_le16(connector_object_id); 1137a3b08294SAlex Deucher } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) { 1138a3b08294SAlex Deucher args.v2.asMode.ucLaneSel = lane_num; 1139a3b08294SAlex Deucher args.v2.asMode.ucLaneSet = lane_set; 1140a3b08294SAlex Deucher } else { 1141a3b08294SAlex Deucher if (is_dp) 11426e76a2dfSAlex Deucher args.v2.usPixelClock = cpu_to_le16(dp_clock / 10); 11439aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 1144a3b08294SAlex Deucher args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10); 1145a3b08294SAlex Deucher else 1146a3b08294SAlex Deucher args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 1147a3b08294SAlex Deucher } 1148a3b08294SAlex Deucher 1149a3b08294SAlex Deucher args.v2.acConfig.ucEncoderSel = dig_encoder; 1150a3b08294SAlex Deucher if (dig->linkb) 1151a3b08294SAlex Deucher args.v2.acConfig.ucLinkSel = 1; 1152a3b08294SAlex Deucher 1153a3b08294SAlex Deucher switch (radeon_encoder->encoder_id) { 1154a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1155a3b08294SAlex Deucher args.v2.acConfig.ucTransmitterSel = 0; 1156a3b08294SAlex Deucher break; 1157a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1158a3b08294SAlex Deucher args.v2.acConfig.ucTransmitterSel = 1; 1159a3b08294SAlex Deucher break; 1160a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1161a3b08294SAlex Deucher args.v2.acConfig.ucTransmitterSel = 2; 1162a3b08294SAlex Deucher break; 1163a3b08294SAlex Deucher } 1164a3b08294SAlex Deucher 1165a3b08294SAlex Deucher if (is_dp) { 1166a3b08294SAlex Deucher args.v2.acConfig.fCoherentMode = 1; 1167a3b08294SAlex Deucher args.v2.acConfig.fDPConnector = 1; 1168a3b08294SAlex Deucher } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 1169a3b08294SAlex Deucher if (dig->coherent_mode) 1170a3b08294SAlex Deucher args.v2.acConfig.fCoherentMode = 1; 11719aa59993SAlex Deucher if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 1172a3b08294SAlex Deucher args.v2.acConfig.fDualLinkConnector = 1; 1173a3b08294SAlex Deucher } 1174a3b08294SAlex Deucher break; 1175a3b08294SAlex Deucher case 3: 1176a3b08294SAlex Deucher args.v3.ucAction = action; 1177a3b08294SAlex Deucher if (action == ATOM_TRANSMITTER_ACTION_INIT) { 1178a3b08294SAlex Deucher args.v3.usInitInfo = cpu_to_le16(connector_object_id); 1179a3b08294SAlex Deucher } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) { 1180a3b08294SAlex Deucher args.v3.asMode.ucLaneSel = lane_num; 1181a3b08294SAlex Deucher args.v3.asMode.ucLaneSet = lane_set; 1182a3b08294SAlex Deucher } else { 1183a3b08294SAlex Deucher if (is_dp) 11846e76a2dfSAlex Deucher args.v3.usPixelClock = cpu_to_le16(dp_clock / 10); 11859aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 1186a3b08294SAlex Deucher args.v3.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10); 1187a3b08294SAlex Deucher else 1188a3b08294SAlex Deucher args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 1189a3b08294SAlex Deucher } 1190a3b08294SAlex Deucher 1191a3b08294SAlex Deucher if (is_dp) 1192a3b08294SAlex Deucher args.v3.ucLaneNum = dp_lane_count; 11939aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 1194a3b08294SAlex Deucher args.v3.ucLaneNum = 8; 1195a3b08294SAlex Deucher else 1196a3b08294SAlex Deucher args.v3.ucLaneNum = 4; 1197a3b08294SAlex Deucher 1198a3b08294SAlex Deucher if (dig->linkb) 1199a3b08294SAlex Deucher args.v3.acConfig.ucLinkSel = 1; 1200a3b08294SAlex Deucher if (dig_encoder & 1) 1201a3b08294SAlex Deucher args.v3.acConfig.ucEncoderSel = 1; 1202a3b08294SAlex Deucher 1203a3b08294SAlex Deucher /* Select the PLL for the PHY 1204a3b08294SAlex Deucher * DP PHY should be clocked from external src if there is 1205a3b08294SAlex Deucher * one. 1206a3b08294SAlex Deucher */ 1207a3b08294SAlex Deucher /* On DCE4, if there is an external clock, it generates the DP ref clock */ 1208a3b08294SAlex Deucher if (is_dp && rdev->clock.dp_extclk) 1209a3b08294SAlex Deucher args.v3.acConfig.ucRefClkSource = 2; /* external src */ 1210a3b08294SAlex Deucher else 1211a3b08294SAlex Deucher args.v3.acConfig.ucRefClkSource = pll_id; 1212a3b08294SAlex Deucher 1213a3b08294SAlex Deucher switch (radeon_encoder->encoder_id) { 1214a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1215a3b08294SAlex Deucher args.v3.acConfig.ucTransmitterSel = 0; 1216a3b08294SAlex Deucher break; 1217a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1218a3b08294SAlex Deucher args.v3.acConfig.ucTransmitterSel = 1; 1219a3b08294SAlex Deucher break; 1220a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1221a3b08294SAlex Deucher args.v3.acConfig.ucTransmitterSel = 2; 1222a3b08294SAlex Deucher break; 1223a3b08294SAlex Deucher } 1224a3b08294SAlex Deucher 1225a3b08294SAlex Deucher if (is_dp) 1226a3b08294SAlex Deucher args.v3.acConfig.fCoherentMode = 1; /* DP requires coherent */ 1227a3b08294SAlex Deucher else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 1228a3b08294SAlex Deucher if (dig->coherent_mode) 1229a3b08294SAlex Deucher args.v3.acConfig.fCoherentMode = 1; 12309aa59993SAlex Deucher if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 1231a3b08294SAlex Deucher args.v3.acConfig.fDualLinkConnector = 1; 1232a3b08294SAlex Deucher } 1233a3b08294SAlex Deucher break; 1234a3b08294SAlex Deucher case 4: 1235a3b08294SAlex Deucher args.v4.ucAction = action; 1236a3b08294SAlex Deucher if (action == ATOM_TRANSMITTER_ACTION_INIT) { 1237a3b08294SAlex Deucher args.v4.usInitInfo = cpu_to_le16(connector_object_id); 1238a3b08294SAlex Deucher } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) { 1239a3b08294SAlex Deucher args.v4.asMode.ucLaneSel = lane_num; 1240a3b08294SAlex Deucher args.v4.asMode.ucLaneSet = lane_set; 1241a3b08294SAlex Deucher } else { 1242a3b08294SAlex Deucher if (is_dp) 12436e76a2dfSAlex Deucher args.v4.usPixelClock = cpu_to_le16(dp_clock / 10); 12449aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 1245a3b08294SAlex Deucher args.v4.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10); 1246a3b08294SAlex Deucher else 1247a3b08294SAlex Deucher args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 1248a3b08294SAlex Deucher } 1249a3b08294SAlex Deucher 1250a3b08294SAlex Deucher if (is_dp) 1251a3b08294SAlex Deucher args.v4.ucLaneNum = dp_lane_count; 12529aa59993SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 1253a3b08294SAlex Deucher args.v4.ucLaneNum = 8; 1254a3b08294SAlex Deucher else 1255a3b08294SAlex Deucher args.v4.ucLaneNum = 4; 1256a3b08294SAlex Deucher 1257a3b08294SAlex Deucher if (dig->linkb) 1258a3b08294SAlex Deucher args.v4.acConfig.ucLinkSel = 1; 1259a3b08294SAlex Deucher if (dig_encoder & 1) 1260a3b08294SAlex Deucher args.v4.acConfig.ucEncoderSel = 1; 1261a3b08294SAlex Deucher 1262a3b08294SAlex Deucher /* Select the PLL for the PHY 1263a3b08294SAlex Deucher * DP PHY should be clocked from external src if there is 1264a3b08294SAlex Deucher * one. 1265a3b08294SAlex Deucher */ 1266a3b08294SAlex Deucher /* On DCE5 DCPLL usually generates the DP ref clock */ 1267a3b08294SAlex Deucher if (is_dp) { 1268a3b08294SAlex Deucher if (rdev->clock.dp_extclk) 1269a3b08294SAlex Deucher args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_EXTCLK; 1270a3b08294SAlex Deucher else 1271a3b08294SAlex Deucher args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_DCPLL; 1272a3b08294SAlex Deucher } else 1273a3b08294SAlex Deucher args.v4.acConfig.ucRefClkSource = pll_id; 1274a3b08294SAlex Deucher 1275a3b08294SAlex Deucher switch (radeon_encoder->encoder_id) { 1276a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1277a3b08294SAlex Deucher args.v4.acConfig.ucTransmitterSel = 0; 1278a3b08294SAlex Deucher break; 1279a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1280a3b08294SAlex Deucher args.v4.acConfig.ucTransmitterSel = 1; 1281a3b08294SAlex Deucher break; 1282a3b08294SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1283a3b08294SAlex Deucher args.v4.acConfig.ucTransmitterSel = 2; 1284a3b08294SAlex Deucher break; 1285a3b08294SAlex Deucher } 1286a3b08294SAlex Deucher 1287a3b08294SAlex Deucher if (is_dp) 1288a3b08294SAlex Deucher args.v4.acConfig.fCoherentMode = 1; /* DP requires coherent */ 1289a3b08294SAlex Deucher else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 1290a3b08294SAlex Deucher if (dig->coherent_mode) 1291a3b08294SAlex Deucher args.v4.acConfig.fCoherentMode = 1; 12929aa59993SAlex Deucher if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 1293a3b08294SAlex Deucher args.v4.acConfig.fDualLinkConnector = 1; 1294a3b08294SAlex Deucher } 1295a3b08294SAlex Deucher break; 129647aef7a8SAlex Deucher case 5: 129747aef7a8SAlex Deucher args.v5.ucAction = action; 129847aef7a8SAlex Deucher if (is_dp) 129947aef7a8SAlex Deucher args.v5.usSymClock = cpu_to_le16(dp_clock / 10); 130047aef7a8SAlex Deucher else 130147aef7a8SAlex Deucher args.v5.usSymClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 130247aef7a8SAlex Deucher 130347aef7a8SAlex Deucher switch (radeon_encoder->encoder_id) { 130447aef7a8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 130547aef7a8SAlex Deucher if (dig->linkb) 130647aef7a8SAlex Deucher args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYB; 130747aef7a8SAlex Deucher else 130847aef7a8SAlex Deucher args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYA; 130947aef7a8SAlex Deucher break; 131047aef7a8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 131147aef7a8SAlex Deucher if (dig->linkb) 131247aef7a8SAlex Deucher args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYD; 131347aef7a8SAlex Deucher else 131447aef7a8SAlex Deucher args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYC; 131547aef7a8SAlex Deucher break; 131647aef7a8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 131747aef7a8SAlex Deucher if (dig->linkb) 131847aef7a8SAlex Deucher args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYF; 131947aef7a8SAlex Deucher else 132047aef7a8SAlex Deucher args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYE; 132147aef7a8SAlex Deucher break; 1322e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 1323e68adef8SAlex Deucher args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYG; 1324e68adef8SAlex Deucher break; 132547aef7a8SAlex Deucher } 132647aef7a8SAlex Deucher if (is_dp) 132747aef7a8SAlex Deucher args.v5.ucLaneNum = dp_lane_count; 1328d03874c8SAlex Deucher else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 132947aef7a8SAlex Deucher args.v5.ucLaneNum = 8; 133047aef7a8SAlex Deucher else 133147aef7a8SAlex Deucher args.v5.ucLaneNum = 4; 133247aef7a8SAlex Deucher args.v5.ucConnObjId = connector_object_id; 133347aef7a8SAlex Deucher args.v5.ucDigMode = atombios_get_encoder_mode(encoder); 133447aef7a8SAlex Deucher 133547aef7a8SAlex Deucher if (is_dp && rdev->clock.dp_extclk) 133647aef7a8SAlex Deucher args.v5.asConfig.ucPhyClkSrcId = ENCODER_REFCLK_SRC_EXTCLK; 133747aef7a8SAlex Deucher else 133847aef7a8SAlex Deucher args.v5.asConfig.ucPhyClkSrcId = pll_id; 133947aef7a8SAlex Deucher 134047aef7a8SAlex Deucher if (is_dp) 134147aef7a8SAlex Deucher args.v5.asConfig.ucCoherentMode = 1; /* DP requires coherent */ 134247aef7a8SAlex Deucher else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 134347aef7a8SAlex Deucher if (dig->coherent_mode) 134447aef7a8SAlex Deucher args.v5.asConfig.ucCoherentMode = 1; 134547aef7a8SAlex Deucher } 134647aef7a8SAlex Deucher if (hpd_id == RADEON_HPD_NONE) 134747aef7a8SAlex Deucher args.v5.asConfig.ucHPDSel = 0; 134847aef7a8SAlex Deucher else 134947aef7a8SAlex Deucher args.v5.asConfig.ucHPDSel = hpd_id + 1; 1350bf071900SDave Airlie args.v5.ucDigEncoderSel = (fe != -1) ? (1 << fe) : (1 << dig_encoder); 135147aef7a8SAlex Deucher args.v5.ucDPLaneSet = lane_set; 135247aef7a8SAlex Deucher break; 1353a3b08294SAlex Deucher default: 1354a3b08294SAlex Deucher DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 1355a3b08294SAlex Deucher break; 1356a3b08294SAlex Deucher } 1357a3b08294SAlex Deucher break; 1358a3b08294SAlex Deucher default: 1359a3b08294SAlex Deucher DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 1360a3b08294SAlex Deucher break; 13613f03ced8SAlex Deucher } 13623f03ced8SAlex Deucher 13633f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 13643f03ced8SAlex Deucher } 13653f03ced8SAlex Deucher 1366bf071900SDave Airlie void 1367bf071900SDave Airlie atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t lane_num, uint8_t lane_set) 1368bf071900SDave Airlie { 1369bf071900SDave Airlie atombios_dig_transmitter_setup2(encoder, action, lane_num, lane_set, -1); 1370bf071900SDave Airlie } 1371bf071900SDave Airlie 13723f03ced8SAlex Deucher bool 13733f03ced8SAlex Deucher atombios_set_edp_panel_power(struct drm_connector *connector, int action) 13743f03ced8SAlex Deucher { 13753f03ced8SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 13763f03ced8SAlex Deucher struct drm_device *dev = radeon_connector->base.dev; 13773f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 13783f03ced8SAlex Deucher union dig_transmitter_control args; 13793f03ced8SAlex Deucher int index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl); 13803f03ced8SAlex Deucher uint8_t frev, crev; 13813f03ced8SAlex Deucher 13823f03ced8SAlex Deucher if (connector->connector_type != DRM_MODE_CONNECTOR_eDP) 13833f03ced8SAlex Deucher goto done; 13843f03ced8SAlex Deucher 13853f03ced8SAlex Deucher if (!ASIC_IS_DCE4(rdev)) 13863f03ced8SAlex Deucher goto done; 13873f03ced8SAlex Deucher 13883f03ced8SAlex Deucher if ((action != ATOM_TRANSMITTER_ACTION_POWER_ON) && 13893f03ced8SAlex Deucher (action != ATOM_TRANSMITTER_ACTION_POWER_OFF)) 13903f03ced8SAlex Deucher goto done; 13913f03ced8SAlex Deucher 13923f03ced8SAlex Deucher if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 13933f03ced8SAlex Deucher goto done; 13943f03ced8SAlex Deucher 13953f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 13963f03ced8SAlex Deucher 13973f03ced8SAlex Deucher args.v1.ucAction = action; 13983f03ced8SAlex Deucher 13993f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 14003f03ced8SAlex Deucher 14013f03ced8SAlex Deucher /* wait for the panel to power up */ 14023f03ced8SAlex Deucher if (action == ATOM_TRANSMITTER_ACTION_POWER_ON) { 14033f03ced8SAlex Deucher int i; 14043f03ced8SAlex Deucher 14053f03ced8SAlex Deucher for (i = 0; i < 300; i++) { 14063f03ced8SAlex Deucher if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd)) 14073f03ced8SAlex Deucher return true; 14083f03ced8SAlex Deucher mdelay(1); 14093f03ced8SAlex Deucher } 14103f03ced8SAlex Deucher return false; 14113f03ced8SAlex Deucher } 14123f03ced8SAlex Deucher done: 14133f03ced8SAlex Deucher return true; 14143f03ced8SAlex Deucher } 14153f03ced8SAlex Deucher 14163f03ced8SAlex Deucher union external_encoder_control { 14173f03ced8SAlex Deucher EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1; 14183f03ced8SAlex Deucher EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION_V3 v3; 14193f03ced8SAlex Deucher }; 14203f03ced8SAlex Deucher 14213f03ced8SAlex Deucher static void 14223f03ced8SAlex Deucher atombios_external_encoder_setup(struct drm_encoder *encoder, 14233f03ced8SAlex Deucher struct drm_encoder *ext_encoder, 14243f03ced8SAlex Deucher int action) 14253f03ced8SAlex Deucher { 14263f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 14273f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 14283f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 14293f03ced8SAlex Deucher struct radeon_encoder *ext_radeon_encoder = to_radeon_encoder(ext_encoder); 14303f03ced8SAlex Deucher union external_encoder_control args; 14313f03ced8SAlex Deucher struct drm_connector *connector; 14323f03ced8SAlex Deucher int index = GetIndexIntoMasterTable(COMMAND, ExternalEncoderControl); 14333f03ced8SAlex Deucher u8 frev, crev; 14343f03ced8SAlex Deucher int dp_clock = 0; 14353f03ced8SAlex Deucher int dp_lane_count = 0; 14363f03ced8SAlex Deucher int connector_object_id = 0; 14373f03ced8SAlex Deucher u32 ext_enum = (ext_radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT; 14383f03ced8SAlex Deucher 14393f03ced8SAlex Deucher if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT) 14403f03ced8SAlex Deucher connector = radeon_get_connector_for_encoder_init(encoder); 14413f03ced8SAlex Deucher else 14423f03ced8SAlex Deucher connector = radeon_get_connector_for_encoder(encoder); 14433f03ced8SAlex Deucher 14443f03ced8SAlex Deucher if (connector) { 14453f03ced8SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 14463f03ced8SAlex Deucher struct radeon_connector_atom_dig *dig_connector = 14473f03ced8SAlex Deucher radeon_connector->con_priv; 14483f03ced8SAlex Deucher 14493f03ced8SAlex Deucher dp_clock = dig_connector->dp_clock; 14503f03ced8SAlex Deucher dp_lane_count = dig_connector->dp_lane_count; 14513f03ced8SAlex Deucher connector_object_id = 14523f03ced8SAlex Deucher (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; 14533f03ced8SAlex Deucher } 14543f03ced8SAlex Deucher 14553f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 14563f03ced8SAlex Deucher 14573f03ced8SAlex Deucher if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 14583f03ced8SAlex Deucher return; 14593f03ced8SAlex Deucher 14603f03ced8SAlex Deucher switch (frev) { 14613f03ced8SAlex Deucher case 1: 14623f03ced8SAlex Deucher /* no params on frev 1 */ 14633f03ced8SAlex Deucher break; 14643f03ced8SAlex Deucher case 2: 14653f03ced8SAlex Deucher switch (crev) { 14663f03ced8SAlex Deucher case 1: 14673f03ced8SAlex Deucher case 2: 14683f03ced8SAlex Deucher args.v1.sDigEncoder.ucAction = action; 14693f03ced8SAlex Deucher args.v1.sDigEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 14703f03ced8SAlex Deucher args.v1.sDigEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder); 14713f03ced8SAlex Deucher 14723f03ced8SAlex Deucher if (ENCODER_MODE_IS_DP(args.v1.sDigEncoder.ucEncoderMode)) { 14733f03ced8SAlex Deucher if (dp_clock == 270000) 14743f03ced8SAlex Deucher args.v1.sDigEncoder.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ; 14753f03ced8SAlex Deucher args.v1.sDigEncoder.ucLaneNum = dp_lane_count; 14769aa59993SAlex Deucher } else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 14773f03ced8SAlex Deucher args.v1.sDigEncoder.ucLaneNum = 8; 14783f03ced8SAlex Deucher else 14793f03ced8SAlex Deucher args.v1.sDigEncoder.ucLaneNum = 4; 14803f03ced8SAlex Deucher break; 14813f03ced8SAlex Deucher case 3: 14823f03ced8SAlex Deucher args.v3.sExtEncoder.ucAction = action; 14833f03ced8SAlex Deucher if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT) 14843f03ced8SAlex Deucher args.v3.sExtEncoder.usConnectorId = cpu_to_le16(connector_object_id); 14853f03ced8SAlex Deucher else 14863f03ced8SAlex Deucher args.v3.sExtEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 14873f03ced8SAlex Deucher args.v3.sExtEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder); 14883f03ced8SAlex Deucher 14893f03ced8SAlex Deucher if (ENCODER_MODE_IS_DP(args.v3.sExtEncoder.ucEncoderMode)) { 14903f03ced8SAlex Deucher if (dp_clock == 270000) 14913f03ced8SAlex Deucher args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ; 14923f03ced8SAlex Deucher else if (dp_clock == 540000) 14933f03ced8SAlex Deucher args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_5_40GHZ; 14943f03ced8SAlex Deucher args.v3.sExtEncoder.ucLaneNum = dp_lane_count; 14959aa59993SAlex Deucher } else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) 14963f03ced8SAlex Deucher args.v3.sExtEncoder.ucLaneNum = 8; 14973f03ced8SAlex Deucher else 14983f03ced8SAlex Deucher args.v3.sExtEncoder.ucLaneNum = 4; 14993f03ced8SAlex Deucher switch (ext_enum) { 15003f03ced8SAlex Deucher case GRAPH_OBJECT_ENUM_ID1: 15013f03ced8SAlex Deucher args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER1; 15023f03ced8SAlex Deucher break; 15033f03ced8SAlex Deucher case GRAPH_OBJECT_ENUM_ID2: 15043f03ced8SAlex Deucher args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER2; 15053f03ced8SAlex Deucher break; 15063f03ced8SAlex Deucher case GRAPH_OBJECT_ENUM_ID3: 15073f03ced8SAlex Deucher args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER3; 15083f03ced8SAlex Deucher break; 15093f03ced8SAlex Deucher } 15101f0e2943SAlex Deucher args.v3.sExtEncoder.ucBitPerColor = radeon_atom_get_bpc(encoder); 15113f03ced8SAlex Deucher break; 15123f03ced8SAlex Deucher default: 15133f03ced8SAlex Deucher DRM_ERROR("Unknown table version: %d, %d\n", frev, crev); 15143f03ced8SAlex Deucher return; 15153f03ced8SAlex Deucher } 15163f03ced8SAlex Deucher break; 15173f03ced8SAlex Deucher default: 15183f03ced8SAlex Deucher DRM_ERROR("Unknown table version: %d, %d\n", frev, crev); 15193f03ced8SAlex Deucher return; 15203f03ced8SAlex Deucher } 15213f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 15223f03ced8SAlex Deucher } 15233f03ced8SAlex Deucher 15243f03ced8SAlex Deucher static void 15253f03ced8SAlex Deucher atombios_yuv_setup(struct drm_encoder *encoder, bool enable) 15263f03ced8SAlex Deucher { 15273f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 15283f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 15293f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 15303f03ced8SAlex Deucher struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 15313f03ced8SAlex Deucher ENABLE_YUV_PS_ALLOCATION args; 15323f03ced8SAlex Deucher int index = GetIndexIntoMasterTable(COMMAND, EnableYUV); 15333f03ced8SAlex Deucher uint32_t temp, reg; 15343f03ced8SAlex Deucher 15353f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 15363f03ced8SAlex Deucher 15373f03ced8SAlex Deucher if (rdev->family >= CHIP_R600) 15383f03ced8SAlex Deucher reg = R600_BIOS_3_SCRATCH; 15393f03ced8SAlex Deucher else 15403f03ced8SAlex Deucher reg = RADEON_BIOS_3_SCRATCH; 15413f03ced8SAlex Deucher 15423f03ced8SAlex Deucher /* XXX: fix up scratch reg handling */ 15433f03ced8SAlex Deucher temp = RREG32(reg); 15443f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 15453f03ced8SAlex Deucher WREG32(reg, (ATOM_S3_TV1_ACTIVE | 15463f03ced8SAlex Deucher (radeon_crtc->crtc_id << 18))); 15473f03ced8SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 15483f03ced8SAlex Deucher WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24))); 15493f03ced8SAlex Deucher else 15503f03ced8SAlex Deucher WREG32(reg, 0); 15513f03ced8SAlex Deucher 15523f03ced8SAlex Deucher if (enable) 15533f03ced8SAlex Deucher args.ucEnable = ATOM_ENABLE; 15543f03ced8SAlex Deucher args.ucCRTC = radeon_crtc->crtc_id; 15553f03ced8SAlex Deucher 15563f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 15573f03ced8SAlex Deucher 15583f03ced8SAlex Deucher WREG32(reg, temp); 15593f03ced8SAlex Deucher } 15603f03ced8SAlex Deucher 15613f03ced8SAlex Deucher static void 15623f03ced8SAlex Deucher radeon_atom_encoder_dpms_avivo(struct drm_encoder *encoder, int mode) 15633f03ced8SAlex Deucher { 15643f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 15653f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 15663f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 15673f03ced8SAlex Deucher DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args; 15683f03ced8SAlex Deucher int index = 0; 15693f03ced8SAlex Deucher 15703f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 15713f03ced8SAlex Deucher 15723f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 15733f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 15743f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 15753f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl); 15763f03ced8SAlex Deucher break; 15773f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DVO1: 15783f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DDI: 15793f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 15803f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl); 15813f03ced8SAlex Deucher break; 15823f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVDS: 15833f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); 15843f03ced8SAlex Deucher break; 15853f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 15863f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 15873f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); 15883f03ced8SAlex Deucher else 15893f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl); 15903f03ced8SAlex Deucher break; 15913f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC1: 15923f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 15933f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 15943f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl); 15953f03ced8SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 15963f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl); 15973f03ced8SAlex Deucher else 15983f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl); 15993f03ced8SAlex Deucher break; 16003f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC2: 16013f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 16023f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 16033f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl); 16043f03ced8SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 16053f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl); 16063f03ced8SAlex Deucher else 16073f03ced8SAlex Deucher index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl); 16083f03ced8SAlex Deucher break; 16093f03ced8SAlex Deucher default: 16103f03ced8SAlex Deucher return; 16113f03ced8SAlex Deucher } 16123f03ced8SAlex Deucher 16133f03ced8SAlex Deucher switch (mode) { 16143f03ced8SAlex Deucher case DRM_MODE_DPMS_ON: 16153f03ced8SAlex Deucher args.ucAction = ATOM_ENABLE; 16163f03ced8SAlex Deucher /* workaround for DVOOutputControl on some RS690 systems */ 16173f03ced8SAlex Deucher if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DDI) { 16183f03ced8SAlex Deucher u32 reg = RREG32(RADEON_BIOS_3_SCRATCH); 16193f03ced8SAlex Deucher WREG32(RADEON_BIOS_3_SCRATCH, reg & ~ATOM_S3_DFP2I_ACTIVE); 16203f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 16213f03ced8SAlex Deucher WREG32(RADEON_BIOS_3_SCRATCH, reg); 16223f03ced8SAlex Deucher } else 16233f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 16243f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 1625ae93580eSAlex Deucher if (rdev->mode_info.bl_encoder) { 16264281f46eSMichel Dänzer struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 16274281f46eSMichel Dänzer 16284281f46eSMichel Dänzer atombios_set_backlight_level(radeon_encoder, dig->backlight_level); 1629ae93580eSAlex Deucher } else { 1630ae93580eSAlex Deucher args.ucAction = ATOM_LCD_BLON; 1631ae93580eSAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 1632ae93580eSAlex Deucher } 16333f03ced8SAlex Deucher } 16343f03ced8SAlex Deucher break; 16353f03ced8SAlex Deucher case DRM_MODE_DPMS_STANDBY: 16363f03ced8SAlex Deucher case DRM_MODE_DPMS_SUSPEND: 16373f03ced8SAlex Deucher case DRM_MODE_DPMS_OFF: 16383f03ced8SAlex Deucher args.ucAction = ATOM_DISABLE; 16393f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 16403f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 16413f03ced8SAlex Deucher args.ucAction = ATOM_LCD_BLOFF; 16423f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 16433f03ced8SAlex Deucher } 16443f03ced8SAlex Deucher break; 16453f03ced8SAlex Deucher } 16463f03ced8SAlex Deucher } 16473f03ced8SAlex Deucher 16483f03ced8SAlex Deucher static void 16493f03ced8SAlex Deucher radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode) 16503f03ced8SAlex Deucher { 16513f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 16523f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 16533f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 16548d1af57aSAlex Deucher struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder); 16558d1af57aSAlex Deucher struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 16563f03ced8SAlex Deucher struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 16573f03ced8SAlex Deucher struct radeon_connector *radeon_connector = NULL; 16583f03ced8SAlex Deucher struct radeon_connector_atom_dig *radeon_dig_connector = NULL; 16596f50e075SAlex Deucher bool travis_quirk = false; 16603f03ced8SAlex Deucher 16613f03ced8SAlex Deucher if (connector) { 16623f03ced8SAlex Deucher radeon_connector = to_radeon_connector(connector); 16633f03ced8SAlex Deucher radeon_dig_connector = radeon_connector->con_priv; 16646f50e075SAlex Deucher if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) == 16656f50e075SAlex Deucher ENCODER_OBJECT_ID_TRAVIS) && 16666f50e075SAlex Deucher (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) && 16676f50e075SAlex Deucher !ASIC_IS_DCE5(rdev)) 16686f50e075SAlex Deucher travis_quirk = true; 16693f03ced8SAlex Deucher } 16703f03ced8SAlex Deucher 16713f03ced8SAlex Deucher switch (mode) { 16723f03ced8SAlex Deucher case DRM_MODE_DPMS_ON: 16738d1af57aSAlex Deucher if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) { 16748d1af57aSAlex Deucher if (!connector) 16758d1af57aSAlex Deucher dig->panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE; 16768d1af57aSAlex Deucher else 16778d1af57aSAlex Deucher dig->panel_mode = radeon_dp_get_panel_mode(encoder, connector); 16788d1af57aSAlex Deucher 16798d1af57aSAlex Deucher /* setup and enable the encoder */ 1680fcedac67SJerome Glisse atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0); 16818d1af57aSAlex Deucher atombios_dig_encoder_setup(encoder, 16828d1af57aSAlex Deucher ATOM_ENCODER_CMD_SETUP_PANEL_MODE, 16838d1af57aSAlex Deucher dig->panel_mode); 16848d1af57aSAlex Deucher if (ext_encoder) { 16858d1af57aSAlex Deucher if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)) 16868d1af57aSAlex Deucher atombios_external_encoder_setup(encoder, ext_encoder, 16878d1af57aSAlex Deucher EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP); 1688fcedac67SJerome Glisse } 16898d1af57aSAlex Deucher } else if (ASIC_IS_DCE4(rdev)) { 16908d1af57aSAlex Deucher /* setup and enable the encoder */ 16918d1af57aSAlex Deucher atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0); 1692fcedac67SJerome Glisse } else { 16938d1af57aSAlex Deucher /* setup and enable the encoder and transmitter */ 16948d1af57aSAlex Deucher atombios_dig_encoder_setup(encoder, ATOM_ENABLE, 0); 16958d1af57aSAlex Deucher atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0); 1696fcedac67SJerome Glisse } 16973f03ced8SAlex Deucher if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) { 16983f03ced8SAlex Deucher if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) { 16993f03ced8SAlex Deucher atombios_set_edp_panel_power(connector, 17003f03ced8SAlex Deucher ATOM_TRANSMITTER_ACTION_POWER_ON); 17013f03ced8SAlex Deucher radeon_dig_connector->edp_on = true; 17023f03ced8SAlex Deucher } 17036f50e075SAlex Deucher } 17046f50e075SAlex Deucher /* enable the transmitter */ 17056f50e075SAlex Deucher atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); 17066f50e075SAlex Deucher if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) { 17076f50e075SAlex Deucher /* DP_SET_POWER_D0 is set in radeon_dp_link_train */ 17083f03ced8SAlex Deucher radeon_dp_link_train(encoder, connector); 17093f03ced8SAlex Deucher if (ASIC_IS_DCE4(rdev)) 17103f03ced8SAlex Deucher atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON, 0); 17113f03ced8SAlex Deucher } 1712ae93580eSAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 1713ae93580eSAlex Deucher if (rdev->mode_info.bl_encoder) 17144281f46eSMichel Dänzer atombios_set_backlight_level(radeon_encoder, dig->backlight_level); 1715ae93580eSAlex Deucher else 1716ae93580eSAlex Deucher atombios_dig_transmitter_setup(encoder, 1717ae93580eSAlex Deucher ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0); 1718ae93580eSAlex Deucher } 17196f50e075SAlex Deucher if (ext_encoder) 17206f50e075SAlex Deucher atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE); 17213f03ced8SAlex Deucher break; 17223f03ced8SAlex Deucher case DRM_MODE_DPMS_STANDBY: 17233f03ced8SAlex Deucher case DRM_MODE_DPMS_SUSPEND: 17243f03ced8SAlex Deucher case DRM_MODE_DPMS_OFF: 17259843ead0SDave Airlie 172640390961SAlex Deucher if (ASIC_IS_DCE4(rdev)) { 17276f50e075SAlex Deucher if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) 17286f50e075SAlex Deucher atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0); 17296f50e075SAlex Deucher } 17306f50e075SAlex Deucher if (ext_encoder) 17316f50e075SAlex Deucher atombios_external_encoder_setup(encoder, ext_encoder, ATOM_DISABLE); 17326f50e075SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 17336f50e075SAlex Deucher atombios_dig_transmitter_setup(encoder, 17346f50e075SAlex Deucher ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0); 17356f50e075SAlex Deucher 17366f50e075SAlex Deucher if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && 17376f50e075SAlex Deucher connector && !travis_quirk) 17386f50e075SAlex Deucher radeon_dp_set_rx_power_state(connector, DP_SET_POWER_D3); 17396f50e075SAlex Deucher if (ASIC_IS_DCE4(rdev)) { 17408d1af57aSAlex Deucher /* disable the transmitter */ 17416f50e075SAlex Deucher atombios_dig_transmitter_setup(encoder, 17426f50e075SAlex Deucher ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); 17438d1af57aSAlex Deucher } else { 17448d1af57aSAlex Deucher /* disable the encoder and transmitter */ 17456f50e075SAlex Deucher atombios_dig_transmitter_setup(encoder, 17466f50e075SAlex Deucher ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); 17478d1af57aSAlex Deucher atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0); 17488d1af57aSAlex Deucher } 17493f03ced8SAlex Deucher if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) { 17506f50e075SAlex Deucher if (travis_quirk) 17516f50e075SAlex Deucher radeon_dp_set_rx_power_state(connector, DP_SET_POWER_D3); 17523f03ced8SAlex Deucher if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) { 17533f03ced8SAlex Deucher atombios_set_edp_panel_power(connector, 17543f03ced8SAlex Deucher ATOM_TRANSMITTER_ACTION_POWER_OFF); 17553f03ced8SAlex Deucher radeon_dig_connector->edp_on = false; 17563f03ced8SAlex Deucher } 17573f03ced8SAlex Deucher } 17583f03ced8SAlex Deucher break; 17593f03ced8SAlex Deucher } 17603f03ced8SAlex Deucher } 17613f03ced8SAlex Deucher 17623f03ced8SAlex Deucher static void 17633f03ced8SAlex Deucher radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode) 17643f03ced8SAlex Deucher { 17653f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 17663f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 17673f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 17685c046a57SAlex Deucher int encoder_mode = atombios_get_encoder_mode(encoder); 17693f03ced8SAlex Deucher 17703f03ced8SAlex Deucher DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n", 17713f03ced8SAlex Deucher radeon_encoder->encoder_id, mode, radeon_encoder->devices, 17723f03ced8SAlex Deucher radeon_encoder->active_device); 17735c046a57SAlex Deucher 177438aef154SAlex Deucher if ((radeon_audio != 0) && 17755c046a57SAlex Deucher ((encoder_mode == ATOM_ENCODER_MODE_HDMI) || 177638aef154SAlex Deucher ENCODER_MODE_IS_DP(encoder_mode))) 17775c046a57SAlex Deucher radeon_audio_dpms(encoder, mode); 17785c046a57SAlex Deucher 17793f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 17803f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 17813f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 17823f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVDS: 17833f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 17843f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DVO1: 17853f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DDI: 17863f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC2: 17873f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 17883f03ced8SAlex Deucher radeon_atom_encoder_dpms_avivo(encoder, mode); 17893f03ced8SAlex Deucher break; 17903f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 17913f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 17923f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1793e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 17943f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 17953f03ced8SAlex Deucher radeon_atom_encoder_dpms_dig(encoder, mode); 17963f03ced8SAlex Deucher break; 17973f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 17983f03ced8SAlex Deucher if (ASIC_IS_DCE5(rdev)) { 17993f03ced8SAlex Deucher switch (mode) { 18003f03ced8SAlex Deucher case DRM_MODE_DPMS_ON: 18013f03ced8SAlex Deucher atombios_dvo_setup(encoder, ATOM_ENABLE); 18023f03ced8SAlex Deucher break; 18033f03ced8SAlex Deucher case DRM_MODE_DPMS_STANDBY: 18043f03ced8SAlex Deucher case DRM_MODE_DPMS_SUSPEND: 18053f03ced8SAlex Deucher case DRM_MODE_DPMS_OFF: 18063f03ced8SAlex Deucher atombios_dvo_setup(encoder, ATOM_DISABLE); 18073f03ced8SAlex Deucher break; 18083f03ced8SAlex Deucher } 18093f03ced8SAlex Deucher } else if (ASIC_IS_DCE3(rdev)) 18103f03ced8SAlex Deucher radeon_atom_encoder_dpms_dig(encoder, mode); 18113f03ced8SAlex Deucher else 18123f03ced8SAlex Deucher radeon_atom_encoder_dpms_avivo(encoder, mode); 18133f03ced8SAlex Deucher break; 18143f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC1: 18153f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 18163f03ced8SAlex Deucher if (ASIC_IS_DCE5(rdev)) { 18173f03ced8SAlex Deucher switch (mode) { 18183f03ced8SAlex Deucher case DRM_MODE_DPMS_ON: 18193f03ced8SAlex Deucher atombios_dac_setup(encoder, ATOM_ENABLE); 18203f03ced8SAlex Deucher break; 18213f03ced8SAlex Deucher case DRM_MODE_DPMS_STANDBY: 18223f03ced8SAlex Deucher case DRM_MODE_DPMS_SUSPEND: 18233f03ced8SAlex Deucher case DRM_MODE_DPMS_OFF: 18243f03ced8SAlex Deucher atombios_dac_setup(encoder, ATOM_DISABLE); 18253f03ced8SAlex Deucher break; 18263f03ced8SAlex Deucher } 18273f03ced8SAlex Deucher } else 18283f03ced8SAlex Deucher radeon_atom_encoder_dpms_avivo(encoder, mode); 18293f03ced8SAlex Deucher break; 18303f03ced8SAlex Deucher default: 18313f03ced8SAlex Deucher return; 18323f03ced8SAlex Deucher } 18333f03ced8SAlex Deucher 18343f03ced8SAlex Deucher radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 18353f03ced8SAlex Deucher 18363f03ced8SAlex Deucher } 18373f03ced8SAlex Deucher 18383f03ced8SAlex Deucher union crtc_source_param { 18393f03ced8SAlex Deucher SELECT_CRTC_SOURCE_PS_ALLOCATION v1; 18403f03ced8SAlex Deucher SELECT_CRTC_SOURCE_PARAMETERS_V2 v2; 18413f03ced8SAlex Deucher }; 18423f03ced8SAlex Deucher 18433f03ced8SAlex Deucher static void 18443f03ced8SAlex Deucher atombios_set_encoder_crtc_source(struct drm_encoder *encoder) 18453f03ced8SAlex Deucher { 18463f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 18473f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 18483f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 18493f03ced8SAlex Deucher struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 18503f03ced8SAlex Deucher union crtc_source_param args; 18513f03ced8SAlex Deucher int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source); 18523f03ced8SAlex Deucher uint8_t frev, crev; 18533f03ced8SAlex Deucher struct radeon_encoder_atom_dig *dig; 18543f03ced8SAlex Deucher 18553f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 18563f03ced8SAlex Deucher 18573f03ced8SAlex Deucher if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 18583f03ced8SAlex Deucher return; 18593f03ced8SAlex Deucher 18603f03ced8SAlex Deucher switch (frev) { 18613f03ced8SAlex Deucher case 1: 18623f03ced8SAlex Deucher switch (crev) { 18633f03ced8SAlex Deucher case 1: 18643f03ced8SAlex Deucher default: 18653f03ced8SAlex Deucher if (ASIC_IS_AVIVO(rdev)) 18663f03ced8SAlex Deucher args.v1.ucCRTC = radeon_crtc->crtc_id; 18673f03ced8SAlex Deucher else { 18683c20d544SWambui Karuga if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) 18693f03ced8SAlex Deucher args.v1.ucCRTC = radeon_crtc->crtc_id; 18703c20d544SWambui Karuga else 18713f03ced8SAlex Deucher args.v1.ucCRTC = radeon_crtc->crtc_id << 2; 18723f03ced8SAlex Deucher } 18733f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 18743f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 18753f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 18763f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX; 18773f03ced8SAlex Deucher break; 18783f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVDS: 18793f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 18803f03ced8SAlex Deucher if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) 18813f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX; 18823f03ced8SAlex Deucher else 18833f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX; 18843f03ced8SAlex Deucher break; 18853f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DVO1: 18863f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DDI: 18873f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 18883f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX; 18893f03ced8SAlex Deucher break; 18903f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC1: 18913f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 18923f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 18933f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX; 18943f03ced8SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 18953f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_CV_INDEX; 18963f03ced8SAlex Deucher else 18973f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX; 18983f03ced8SAlex Deucher break; 18993f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC2: 19003f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 19013f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 19023f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX; 19033f03ced8SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 19043f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_CV_INDEX; 19053f03ced8SAlex Deucher else 19063f03ced8SAlex Deucher args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX; 19073f03ced8SAlex Deucher break; 19083f03ced8SAlex Deucher } 19093f03ced8SAlex Deucher break; 19103f03ced8SAlex Deucher case 2: 19113f03ced8SAlex Deucher args.v2.ucCRTC = radeon_crtc->crtc_id; 19123f03ced8SAlex Deucher if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE) { 19133f03ced8SAlex Deucher struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 19143f03ced8SAlex Deucher 19153f03ced8SAlex Deucher if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) 19163f03ced8SAlex Deucher args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS; 19173f03ced8SAlex Deucher else if (connector->connector_type == DRM_MODE_CONNECTOR_VGA) 19183f03ced8SAlex Deucher args.v2.ucEncodeMode = ATOM_ENCODER_MODE_CRT; 19193f03ced8SAlex Deucher else 19203f03ced8SAlex Deucher args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder); 192164252835SAlex Deucher } else if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 192264252835SAlex Deucher args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS; 192364252835SAlex Deucher } else { 19243f03ced8SAlex Deucher args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder); 192564252835SAlex Deucher } 19263f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 19273f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 19283f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 19293f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1930e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 19313f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 19323f03ced8SAlex Deucher dig = radeon_encoder->enc_priv; 19333f03ced8SAlex Deucher switch (dig->dig_encoder) { 19343f03ced8SAlex Deucher case 0: 19353f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID; 19363f03ced8SAlex Deucher break; 19373f03ced8SAlex Deucher case 1: 19383f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; 19393f03ced8SAlex Deucher break; 19403f03ced8SAlex Deucher case 2: 19413f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DIG3_ENCODER_ID; 19423f03ced8SAlex Deucher break; 19433f03ced8SAlex Deucher case 3: 19443f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DIG4_ENCODER_ID; 19453f03ced8SAlex Deucher break; 19463f03ced8SAlex Deucher case 4: 19473f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DIG5_ENCODER_ID; 19483f03ced8SAlex Deucher break; 19493f03ced8SAlex Deucher case 5: 19503f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DIG6_ENCODER_ID; 19513f03ced8SAlex Deucher break; 1952e68adef8SAlex Deucher case 6: 1953e68adef8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DIG7_ENCODER_ID; 1954e68adef8SAlex Deucher break; 19553f03ced8SAlex Deucher } 19563f03ced8SAlex Deucher break; 19573f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 19583f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID; 19593f03ced8SAlex Deucher break; 19603f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 19613f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 19623f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 19633f03ced8SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 19643f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 19653f03ced8SAlex Deucher else 19663f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID; 19673f03ced8SAlex Deucher break; 19683f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 19693f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 19703f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 19713f03ced8SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 19723f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 19733f03ced8SAlex Deucher else 19743f03ced8SAlex Deucher args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID; 19753f03ced8SAlex Deucher break; 19763f03ced8SAlex Deucher } 19773f03ced8SAlex Deucher break; 19783f03ced8SAlex Deucher } 19793f03ced8SAlex Deucher break; 19803f03ced8SAlex Deucher default: 19813f03ced8SAlex Deucher DRM_ERROR("Unknown table version: %d, %d\n", frev, crev); 19823f03ced8SAlex Deucher return; 19833f03ced8SAlex Deucher } 19843f03ced8SAlex Deucher 19853f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 19863f03ced8SAlex Deucher 19873f03ced8SAlex Deucher /* update scratch regs with new routing */ 19883f03ced8SAlex Deucher radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 19893f03ced8SAlex Deucher } 19903f03ced8SAlex Deucher 19913f03ced8SAlex Deucher static void 19923f03ced8SAlex Deucher atombios_apply_encoder_quirks(struct drm_encoder *encoder, 19933f03ced8SAlex Deucher struct drm_display_mode *mode) 19943f03ced8SAlex Deucher { 19953f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 19963f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 19973f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 19983f03ced8SAlex Deucher struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 19993f03ced8SAlex Deucher 20003f03ced8SAlex Deucher /* Funky macbooks */ 2001d86a4126SThomas Zimmermann if ((rdev->pdev->device == 0x71C5) && 2002d86a4126SThomas Zimmermann (rdev->pdev->subsystem_vendor == 0x106b) && 2003d86a4126SThomas Zimmermann (rdev->pdev->subsystem_device == 0x0080)) { 20043f03ced8SAlex Deucher if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) { 20053f03ced8SAlex Deucher uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL); 20063f03ced8SAlex Deucher 20073f03ced8SAlex Deucher lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN; 20083f03ced8SAlex Deucher lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN; 20093f03ced8SAlex Deucher 20103f03ced8SAlex Deucher WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control); 20113f03ced8SAlex Deucher } 20123f03ced8SAlex Deucher } 20133f03ced8SAlex Deucher 20143f03ced8SAlex Deucher /* set scaler clears this on some chips */ 20153f03ced8SAlex Deucher if (ASIC_IS_AVIVO(rdev) && 20163f03ced8SAlex Deucher (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)))) { 2017d798f2f2SAlex Deucher if (ASIC_IS_DCE8(rdev)) { 2018d798f2f2SAlex Deucher if (mode->flags & DRM_MODE_FLAG_INTERLACE) 2019d798f2f2SAlex Deucher WREG32(CIK_LB_DATA_FORMAT + radeon_crtc->crtc_offset, 2020d798f2f2SAlex Deucher CIK_INTERLEAVE_EN); 2021d798f2f2SAlex Deucher else 2022d798f2f2SAlex Deucher WREG32(CIK_LB_DATA_FORMAT + radeon_crtc->crtc_offset, 0); 2023d798f2f2SAlex Deucher } else if (ASIC_IS_DCE4(rdev)) { 20243f03ced8SAlex Deucher if (mode->flags & DRM_MODE_FLAG_INTERLACE) 20253f03ced8SAlex Deucher WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 20263f03ced8SAlex Deucher EVERGREEN_INTERLEAVE_EN); 20273f03ced8SAlex Deucher else 20283f03ced8SAlex Deucher WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0); 20293f03ced8SAlex Deucher } else { 20303f03ced8SAlex Deucher if (mode->flags & DRM_MODE_FLAG_INTERLACE) 20313f03ced8SAlex Deucher WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 20323f03ced8SAlex Deucher AVIVO_D1MODE_INTERLEAVE_EN); 20333f03ced8SAlex Deucher else 20343f03ced8SAlex Deucher WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 0); 20353f03ced8SAlex Deucher } 20363f03ced8SAlex Deucher } 20373f03ced8SAlex Deucher } 20383f03ced8SAlex Deucher 20398f0fc088SDave Airlie void radeon_atom_release_dig_encoder(struct radeon_device *rdev, int enc_idx) 20408f0fc088SDave Airlie { 20418f0fc088SDave Airlie if (enc_idx < 0) 20428f0fc088SDave Airlie return; 20438f0fc088SDave Airlie rdev->mode_info.active_encoders &= ~(1 << enc_idx); 20448f0fc088SDave Airlie } 20458f0fc088SDave Airlie 20468f0fc088SDave Airlie int radeon_atom_pick_dig_encoder(struct drm_encoder *encoder, int fe_idx) 20473f03ced8SAlex Deucher { 20483f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 20493f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 20503f03ced8SAlex Deucher struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 20513f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 20523f03ced8SAlex Deucher struct drm_encoder *test_encoder; 205341fa5437SAlex Deucher struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 20543f03ced8SAlex Deucher uint32_t dig_enc_in_use = 0; 20558f0fc088SDave Airlie int enc_idx = -1; 20563f03ced8SAlex Deucher 20578f0fc088SDave Airlie if (fe_idx >= 0) { 20588f0fc088SDave Airlie enc_idx = fe_idx; 20598f0fc088SDave Airlie goto assigned; 20608f0fc088SDave Airlie } 206141fa5437SAlex Deucher if (ASIC_IS_DCE6(rdev)) { 206241fa5437SAlex Deucher /* DCE6 */ 206341fa5437SAlex Deucher switch (radeon_encoder->encoder_id) { 206441fa5437SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 206541fa5437SAlex Deucher if (dig->linkb) 20668f0fc088SDave Airlie enc_idx = 1; 206741fa5437SAlex Deucher else 20688f0fc088SDave Airlie enc_idx = 0; 206941fa5437SAlex Deucher break; 207041fa5437SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 207141fa5437SAlex Deucher if (dig->linkb) 20728f0fc088SDave Airlie enc_idx = 3; 207341fa5437SAlex Deucher else 20748f0fc088SDave Airlie enc_idx = 2; 207541fa5437SAlex Deucher break; 207641fa5437SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 207741fa5437SAlex Deucher if (dig->linkb) 20788f0fc088SDave Airlie enc_idx = 5; 207941fa5437SAlex Deucher else 20808f0fc088SDave Airlie enc_idx = 4; 208141fa5437SAlex Deucher break; 2082e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 20838f0fc088SDave Airlie enc_idx = 6; 2084e68adef8SAlex Deucher break; 208541fa5437SAlex Deucher } 20868f0fc088SDave Airlie goto assigned; 208741fa5437SAlex Deucher } else if (ASIC_IS_DCE4(rdev)) { 20883f03ced8SAlex Deucher /* DCE4/5 */ 208941fa5437SAlex Deucher if (ASIC_IS_DCE41(rdev) && !ASIC_IS_DCE61(rdev)) { 20903f03ced8SAlex Deucher /* ontario follows DCE4 */ 20913f03ced8SAlex Deucher if (rdev->family == CHIP_PALM) { 20923f03ced8SAlex Deucher if (dig->linkb) 20938f0fc088SDave Airlie enc_idx = 1; 20943f03ced8SAlex Deucher else 20958f0fc088SDave Airlie enc_idx = 0; 20963f03ced8SAlex Deucher } else 20973f03ced8SAlex Deucher /* llano follows DCE3.2 */ 20988f0fc088SDave Airlie enc_idx = radeon_crtc->crtc_id; 20993f03ced8SAlex Deucher } else { 21003f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 21013f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 21023f03ced8SAlex Deucher if (dig->linkb) 21038f0fc088SDave Airlie enc_idx = 1; 21043f03ced8SAlex Deucher else 21058f0fc088SDave Airlie enc_idx = 0; 21063f03ced8SAlex Deucher break; 21073f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 21083f03ced8SAlex Deucher if (dig->linkb) 21098f0fc088SDave Airlie enc_idx = 3; 21103f03ced8SAlex Deucher else 21118f0fc088SDave Airlie enc_idx = 2; 21123f03ced8SAlex Deucher break; 21133f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 21143f03ced8SAlex Deucher if (dig->linkb) 21158f0fc088SDave Airlie enc_idx = 5; 21163f03ced8SAlex Deucher else 21178f0fc088SDave Airlie enc_idx = 4; 21183f03ced8SAlex Deucher break; 21193f03ced8SAlex Deucher } 21203f03ced8SAlex Deucher } 21218f0fc088SDave Airlie goto assigned; 21223f03ced8SAlex Deucher } 21233f03ced8SAlex Deucher 2124564d8a2cSMario Kleiner /* 2125564d8a2cSMario Kleiner * On DCE32 any encoder can drive any block so usually just use crtc id, 2126*05eacc19SMark Hawrylak * but Apple thinks different at least on iMac10,1 and iMac11,2, so there use linkb, 2127564d8a2cSMario Kleiner * otherwise the internal eDP panel will stay dark. 2128564d8a2cSMario Kleiner */ 21293f03ced8SAlex Deucher if (ASIC_IS_DCE32(rdev)) { 2130*05eacc19SMark Hawrylak if (dmi_match(DMI_PRODUCT_NAME, "iMac10,1") || 2131*05eacc19SMark Hawrylak dmi_match(DMI_PRODUCT_NAME, "iMac11,2")) 2132564d8a2cSMario Kleiner enc_idx = (dig->linkb) ? 1 : 0; 2133564d8a2cSMario Kleiner else 21348f0fc088SDave Airlie enc_idx = radeon_crtc->crtc_id; 2135564d8a2cSMario Kleiner 21368f0fc088SDave Airlie goto assigned; 21373f03ced8SAlex Deucher } 21383f03ced8SAlex Deucher 21393f03ced8SAlex Deucher /* on DCE3 - LVTMA can only be driven by DIGB */ 21403f03ced8SAlex Deucher list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) { 21413f03ced8SAlex Deucher struct radeon_encoder *radeon_test_encoder; 21423f03ced8SAlex Deucher 21433f03ced8SAlex Deucher if (encoder == test_encoder) 21443f03ced8SAlex Deucher continue; 21453f03ced8SAlex Deucher 21463f03ced8SAlex Deucher if (!radeon_encoder_is_digital(test_encoder)) 21473f03ced8SAlex Deucher continue; 21483f03ced8SAlex Deucher 21493f03ced8SAlex Deucher radeon_test_encoder = to_radeon_encoder(test_encoder); 21503f03ced8SAlex Deucher dig = radeon_test_encoder->enc_priv; 21513f03ced8SAlex Deucher 21523f03ced8SAlex Deucher if (dig->dig_encoder >= 0) 21533f03ced8SAlex Deucher dig_enc_in_use |= (1 << dig->dig_encoder); 21543f03ced8SAlex Deucher } 21553f03ced8SAlex Deucher 21563f03ced8SAlex Deucher if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA) { 21573f03ced8SAlex Deucher if (dig_enc_in_use & 0x2) 21583f03ced8SAlex Deucher DRM_ERROR("LVDS required digital encoder 2 but it was in use - stealing\n"); 21593f03ced8SAlex Deucher return 1; 21603f03ced8SAlex Deucher } 21613f03ced8SAlex Deucher if (!(dig_enc_in_use & 1)) 21623f03ced8SAlex Deucher return 0; 21633f03ced8SAlex Deucher return 1; 21648f0fc088SDave Airlie 21658f0fc088SDave Airlie assigned: 21668f0fc088SDave Airlie if (enc_idx == -1) { 21678f0fc088SDave Airlie DRM_ERROR("Got encoder index incorrect - returning 0\n"); 21688f0fc088SDave Airlie return 0; 21698f0fc088SDave Airlie } 21703c20d544SWambui Karuga if (rdev->mode_info.active_encoders & (1 << enc_idx)) 21718f0fc088SDave Airlie DRM_ERROR("chosen encoder in use %d\n", enc_idx); 21723c20d544SWambui Karuga 21738f0fc088SDave Airlie rdev->mode_info.active_encoders |= (1 << enc_idx); 21748f0fc088SDave Airlie return enc_idx; 21753f03ced8SAlex Deucher } 21763f03ced8SAlex Deucher 21773f03ced8SAlex Deucher /* This only needs to be called once at startup */ 21783f03ced8SAlex Deucher void 21793f03ced8SAlex Deucher radeon_atom_encoder_init(struct radeon_device *rdev) 21803f03ced8SAlex Deucher { 21813f03ced8SAlex Deucher struct drm_device *dev = rdev->ddev; 21823f03ced8SAlex Deucher struct drm_encoder *encoder; 21833f03ced8SAlex Deucher 21843f03ced8SAlex Deucher list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 21853f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 21863f03ced8SAlex Deucher struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder); 21873f03ced8SAlex Deucher 21883f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 21893f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 21903f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 21913f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 2192e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 21933f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 21943f03ced8SAlex Deucher atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0); 21953f03ced8SAlex Deucher break; 21963f03ced8SAlex Deucher default: 21973f03ced8SAlex Deucher break; 21983f03ced8SAlex Deucher } 21993f03ced8SAlex Deucher 22001d3949c4SAlex Deucher if (ext_encoder && (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev))) 22013f03ced8SAlex Deucher atombios_external_encoder_setup(encoder, ext_encoder, 22023f03ced8SAlex Deucher EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT); 22033f03ced8SAlex Deucher } 22043f03ced8SAlex Deucher } 22053f03ced8SAlex Deucher 22063f03ced8SAlex Deucher static void 22073f03ced8SAlex Deucher radeon_atom_encoder_mode_set(struct drm_encoder *encoder, 22083f03ced8SAlex Deucher struct drm_display_mode *mode, 22093f03ced8SAlex Deucher struct drm_display_mode *adjusted_mode) 22103f03ced8SAlex Deucher { 22113f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 22123f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 22133f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 22143473f542SAlex Deucher struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 22156f945693SSlava Grigorev int encoder_mode; 22163f03ced8SAlex Deucher 22173f03ced8SAlex Deucher radeon_encoder->pixel_clock = adjusted_mode->clock; 22183f03ced8SAlex Deucher 22198d1af57aSAlex Deucher /* need to call this here rather than in prepare() since we need some crtc info */ 22208d1af57aSAlex Deucher radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 22218d1af57aSAlex Deucher 22223f03ced8SAlex Deucher if (ASIC_IS_AVIVO(rdev) && !ASIC_IS_DCE4(rdev)) { 22233f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT)) 22243f03ced8SAlex Deucher atombios_yuv_setup(encoder, true); 22253f03ced8SAlex Deucher else 22263f03ced8SAlex Deucher atombios_yuv_setup(encoder, false); 22273f03ced8SAlex Deucher } 22283f03ced8SAlex Deucher 22293f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 22303f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 22313f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 22323f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVDS: 22333f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 22343f03ced8SAlex Deucher atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE); 22353f03ced8SAlex Deucher break; 22363f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 22373f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 22383f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 2239e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 22403f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 22418d1af57aSAlex Deucher /* handled in dpms */ 22423f03ced8SAlex Deucher break; 22433f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DDI: 22443f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DVO1: 22453f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 22463f03ced8SAlex Deucher atombios_dvo_setup(encoder, ATOM_ENABLE); 22473f03ced8SAlex Deucher break; 22483f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC1: 22493f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 22503f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC2: 22513f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 22523f03ced8SAlex Deucher atombios_dac_setup(encoder, ATOM_ENABLE); 22533f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) { 22543f03ced8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) 22553f03ced8SAlex Deucher atombios_tv_setup(encoder, ATOM_ENABLE); 22563f03ced8SAlex Deucher else 22573f03ced8SAlex Deucher atombios_tv_setup(encoder, ATOM_DISABLE); 22583f03ced8SAlex Deucher } 22593f03ced8SAlex Deucher break; 22603f03ced8SAlex Deucher } 22613f03ced8SAlex Deucher 22623f03ced8SAlex Deucher atombios_apply_encoder_quirks(encoder, adjusted_mode); 22635c046a57SAlex Deucher 22645c046a57SAlex Deucher encoder_mode = atombios_get_encoder_mode(encoder); 22655c046a57SAlex Deucher if (connector && (radeon_audio != 0) && 22665c046a57SAlex Deucher ((encoder_mode == ATOM_ENCODER_MODE_HDMI) || 22677726e72bSAlex Deucher ENCODER_MODE_IS_DP(encoder_mode))) 22685c046a57SAlex Deucher radeon_audio_mode_set(encoder, adjusted_mode); 22693f03ced8SAlex Deucher } 22703f03ced8SAlex Deucher 22713f03ced8SAlex Deucher static bool 22723f03ced8SAlex Deucher atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector) 22733f03ced8SAlex Deucher { 22743f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 22753f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 22763f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 22773f03ced8SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 22783f03ced8SAlex Deucher 22793f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | 22803f03ced8SAlex Deucher ATOM_DEVICE_CV_SUPPORT | 22813f03ced8SAlex Deucher ATOM_DEVICE_CRT_SUPPORT)) { 22823f03ced8SAlex Deucher DAC_LOAD_DETECTION_PS_ALLOCATION args; 22833f03ced8SAlex Deucher int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection); 22843f03ced8SAlex Deucher uint8_t frev, crev; 22853f03ced8SAlex Deucher 22863f03ced8SAlex Deucher memset(&args, 0, sizeof(args)); 22873f03ced8SAlex Deucher 22883f03ced8SAlex Deucher if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) 22893f03ced8SAlex Deucher return false; 22903f03ced8SAlex Deucher 22913f03ced8SAlex Deucher args.sDacload.ucMisc = 0; 22923f03ced8SAlex Deucher 22933f03ced8SAlex Deucher if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) || 22943f03ced8SAlex Deucher (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1)) 22953f03ced8SAlex Deucher args.sDacload.ucDacType = ATOM_DAC_A; 22963f03ced8SAlex Deucher else 22973f03ced8SAlex Deucher args.sDacload.ucDacType = ATOM_DAC_B; 22983f03ced8SAlex Deucher 22993f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) 23003f03ced8SAlex Deucher args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT); 23013f03ced8SAlex Deucher else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) 23023f03ced8SAlex Deucher args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT); 23033f03ced8SAlex Deucher else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { 23043f03ced8SAlex Deucher args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT); 23053f03ced8SAlex Deucher if (crev >= 3) 23063f03ced8SAlex Deucher args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb; 23073f03ced8SAlex Deucher } else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { 23083f03ced8SAlex Deucher args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT); 23093f03ced8SAlex Deucher if (crev >= 3) 23103f03ced8SAlex Deucher args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb; 23113f03ced8SAlex Deucher } 23123f03ced8SAlex Deucher 23133f03ced8SAlex Deucher atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 23143f03ced8SAlex Deucher 23153f03ced8SAlex Deucher return true; 23163f03ced8SAlex Deucher } else 23173f03ced8SAlex Deucher return false; 23183f03ced8SAlex Deucher } 23193f03ced8SAlex Deucher 23203f03ced8SAlex Deucher static enum drm_connector_status 23213f03ced8SAlex Deucher radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) 23223f03ced8SAlex Deucher { 23233f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 23243f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 23253f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 23263f03ced8SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 23273f03ced8SAlex Deucher uint32_t bios_0_scratch; 23283f03ced8SAlex Deucher 23293f03ced8SAlex Deucher if (!atombios_dac_load_detect(encoder, connector)) { 23303f03ced8SAlex Deucher DRM_DEBUG_KMS("detect returned false \n"); 23313f03ced8SAlex Deucher return connector_status_unknown; 23323f03ced8SAlex Deucher } 23333f03ced8SAlex Deucher 23343f03ced8SAlex Deucher if (rdev->family >= CHIP_R600) 23353f03ced8SAlex Deucher bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH); 23363f03ced8SAlex Deucher else 23373f03ced8SAlex Deucher bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH); 23383f03ced8SAlex Deucher 23393f03ced8SAlex Deucher DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices); 23403f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) { 23413f03ced8SAlex Deucher if (bios_0_scratch & ATOM_S0_CRT1_MASK) 23423f03ced8SAlex Deucher return connector_status_connected; 23433f03ced8SAlex Deucher } 23443f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) { 23453f03ced8SAlex Deucher if (bios_0_scratch & ATOM_S0_CRT2_MASK) 23463f03ced8SAlex Deucher return connector_status_connected; 23473f03ced8SAlex Deucher } 23483f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { 23493f03ced8SAlex Deucher if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A)) 23503f03ced8SAlex Deucher return connector_status_connected; 23513f03ced8SAlex Deucher } 23523f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { 23533f03ced8SAlex Deucher if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A)) 23543f03ced8SAlex Deucher return connector_status_connected; /* CTV */ 23553f03ced8SAlex Deucher else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A)) 23563f03ced8SAlex Deucher return connector_status_connected; /* STV */ 23573f03ced8SAlex Deucher } 23583f03ced8SAlex Deucher return connector_status_disconnected; 23593f03ced8SAlex Deucher } 23603f03ced8SAlex Deucher 23613f03ced8SAlex Deucher static enum drm_connector_status 23623f03ced8SAlex Deucher radeon_atom_dig_detect(struct drm_encoder *encoder, struct drm_connector *connector) 23633f03ced8SAlex Deucher { 23643f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 23653f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 23663f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 23673f03ced8SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 23683f03ced8SAlex Deucher struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder); 23693f03ced8SAlex Deucher u32 bios_0_scratch; 23703f03ced8SAlex Deucher 23713f03ced8SAlex Deucher if (!ASIC_IS_DCE4(rdev)) 23723f03ced8SAlex Deucher return connector_status_unknown; 23733f03ced8SAlex Deucher 23743f03ced8SAlex Deucher if (!ext_encoder) 23753f03ced8SAlex Deucher return connector_status_unknown; 23763f03ced8SAlex Deucher 23773f03ced8SAlex Deucher if ((radeon_connector->devices & ATOM_DEVICE_CRT_SUPPORT) == 0) 23783f03ced8SAlex Deucher return connector_status_unknown; 23793f03ced8SAlex Deucher 23803f03ced8SAlex Deucher /* load detect on the dp bridge */ 23813f03ced8SAlex Deucher atombios_external_encoder_setup(encoder, ext_encoder, 23823f03ced8SAlex Deucher EXTERNAL_ENCODER_ACTION_V3_DACLOAD_DETECTION); 23833f03ced8SAlex Deucher 23843f03ced8SAlex Deucher bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH); 23853f03ced8SAlex Deucher 23863f03ced8SAlex Deucher DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices); 23873f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) { 23883f03ced8SAlex Deucher if (bios_0_scratch & ATOM_S0_CRT1_MASK) 23893f03ced8SAlex Deucher return connector_status_connected; 23903f03ced8SAlex Deucher } 23913f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) { 23923f03ced8SAlex Deucher if (bios_0_scratch & ATOM_S0_CRT2_MASK) 23933f03ced8SAlex Deucher return connector_status_connected; 23943f03ced8SAlex Deucher } 23953f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { 23963f03ced8SAlex Deucher if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A)) 23973f03ced8SAlex Deucher return connector_status_connected; 23983f03ced8SAlex Deucher } 23993f03ced8SAlex Deucher if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { 24003f03ced8SAlex Deucher if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A)) 24013f03ced8SAlex Deucher return connector_status_connected; /* CTV */ 24023f03ced8SAlex Deucher else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A)) 24033f03ced8SAlex Deucher return connector_status_connected; /* STV */ 24043f03ced8SAlex Deucher } 24053f03ced8SAlex Deucher return connector_status_disconnected; 24063f03ced8SAlex Deucher } 24073f03ced8SAlex Deucher 24083f03ced8SAlex Deucher void 24093f03ced8SAlex Deucher radeon_atom_ext_encoder_setup_ddc(struct drm_encoder *encoder) 24103f03ced8SAlex Deucher { 24113f03ced8SAlex Deucher struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder); 24123f03ced8SAlex Deucher 24133f03ced8SAlex Deucher if (ext_encoder) 24143f03ced8SAlex Deucher /* ddc_setup on the dp bridge */ 24153f03ced8SAlex Deucher atombios_external_encoder_setup(encoder, ext_encoder, 24163f03ced8SAlex Deucher EXTERNAL_ENCODER_ACTION_V3_DDC_SETUP); 24173f03ced8SAlex Deucher 24183f03ced8SAlex Deucher } 24193f03ced8SAlex Deucher 24203f03ced8SAlex Deucher static void radeon_atom_encoder_prepare(struct drm_encoder *encoder) 24213f03ced8SAlex Deucher { 2422cfcbd6d3SRafał Miłecki struct radeon_device *rdev = encoder->dev->dev_private; 24233f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 24243f03ced8SAlex Deucher struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 24253f03ced8SAlex Deucher 24263f03ced8SAlex Deucher if ((radeon_encoder->active_device & 24273f03ced8SAlex Deucher (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) || 24283f03ced8SAlex Deucher (radeon_encoder_get_dp_bridge_encoder_id(encoder) != 24293f03ced8SAlex Deucher ENCODER_OBJECT_ID_NONE)) { 24303f03ced8SAlex Deucher struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 2431cfcbd6d3SRafał Miłecki if (dig) { 24328f0fc088SDave Airlie if (dig->dig_encoder >= 0) 24338f0fc088SDave Airlie radeon_atom_release_dig_encoder(rdev, dig->dig_encoder); 24348f0fc088SDave Airlie dig->dig_encoder = radeon_atom_pick_dig_encoder(encoder, -1); 2435cfcbd6d3SRafał Miłecki if (radeon_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT) { 2436cfcbd6d3SRafał Miłecki if (rdev->family >= CHIP_R600) 2437cfcbd6d3SRafał Miłecki dig->afmt = rdev->mode_info.afmt[dig->dig_encoder]; 2438cfcbd6d3SRafał Miłecki else 2439cfcbd6d3SRafał Miłecki /* RS600/690/740 have only 1 afmt block */ 2440cfcbd6d3SRafał Miłecki dig->afmt = rdev->mode_info.afmt[0]; 2441cfcbd6d3SRafał Miłecki } 2442cfcbd6d3SRafał Miłecki } 24433f03ced8SAlex Deucher } 24443f03ced8SAlex Deucher 24453f03ced8SAlex Deucher radeon_atom_output_lock(encoder, true); 24463f03ced8SAlex Deucher 24473f03ced8SAlex Deucher if (connector) { 24483f03ced8SAlex Deucher struct radeon_connector *radeon_connector = to_radeon_connector(connector); 24493f03ced8SAlex Deucher 24503f03ced8SAlex Deucher /* select the clock/data port if it uses a router */ 24513f03ced8SAlex Deucher if (radeon_connector->router.cd_valid) 24523f03ced8SAlex Deucher radeon_router_select_cd_port(radeon_connector); 24533f03ced8SAlex Deucher 24543f03ced8SAlex Deucher /* turn eDP panel on for mode set */ 24553f03ced8SAlex Deucher if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) 24563f03ced8SAlex Deucher atombios_set_edp_panel_power(connector, 24573f03ced8SAlex Deucher ATOM_TRANSMITTER_ACTION_POWER_ON); 24583f03ced8SAlex Deucher } 24593f03ced8SAlex Deucher 24603f03ced8SAlex Deucher /* this is needed for the pll/ss setup to work correctly in some cases */ 24613f03ced8SAlex Deucher atombios_set_encoder_crtc_source(encoder); 2462134b480fSAlex Deucher /* set up the FMT blocks */ 2463134b480fSAlex Deucher if (ASIC_IS_DCE8(rdev)) 2464134b480fSAlex Deucher dce8_program_fmt(encoder); 2465134b480fSAlex Deucher else if (ASIC_IS_DCE4(rdev)) 2466134b480fSAlex Deucher dce4_program_fmt(encoder); 2467134b480fSAlex Deucher else if (ASIC_IS_DCE3(rdev)) 2468134b480fSAlex Deucher dce3_program_fmt(encoder); 2469134b480fSAlex Deucher else if (ASIC_IS_AVIVO(rdev)) 2470134b480fSAlex Deucher avivo_program_fmt(encoder); 24713f03ced8SAlex Deucher } 24723f03ced8SAlex Deucher 24733f03ced8SAlex Deucher static void radeon_atom_encoder_commit(struct drm_encoder *encoder) 24743f03ced8SAlex Deucher { 24758d1af57aSAlex Deucher /* need to call this here as we need the crtc set up */ 24763f03ced8SAlex Deucher radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON); 24773f03ced8SAlex Deucher radeon_atom_output_lock(encoder, false); 24783f03ced8SAlex Deucher } 24793f03ced8SAlex Deucher 24803f03ced8SAlex Deucher static void radeon_atom_encoder_disable(struct drm_encoder *encoder) 24813f03ced8SAlex Deucher { 24823f03ced8SAlex Deucher struct drm_device *dev = encoder->dev; 24833f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 24843f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 24853f03ced8SAlex Deucher struct radeon_encoder_atom_dig *dig; 24863f03ced8SAlex Deucher 24873f03ced8SAlex Deucher /* check for pre-DCE3 cards with shared encoders; 24883f03ced8SAlex Deucher * can't really use the links individually, so don't disable 24893f03ced8SAlex Deucher * the encoder if it's in use by another connector 24903f03ced8SAlex Deucher */ 24913f03ced8SAlex Deucher if (!ASIC_IS_DCE3(rdev)) { 24923f03ced8SAlex Deucher struct drm_encoder *other_encoder; 24933f03ced8SAlex Deucher struct radeon_encoder *other_radeon_encoder; 24943f03ced8SAlex Deucher 24953f03ced8SAlex Deucher list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) { 24963f03ced8SAlex Deucher other_radeon_encoder = to_radeon_encoder(other_encoder); 24973f03ced8SAlex Deucher if ((radeon_encoder->encoder_id == other_radeon_encoder->encoder_id) && 24983f03ced8SAlex Deucher drm_helper_encoder_in_use(other_encoder)) 24993f03ced8SAlex Deucher goto disable_done; 25003f03ced8SAlex Deucher } 25013f03ced8SAlex Deucher } 25023f03ced8SAlex Deucher 25033f03ced8SAlex Deucher radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 25043f03ced8SAlex Deucher 25053f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 25063f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 25073f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 25083f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVDS: 25093f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 25103f03ced8SAlex Deucher atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_DISABLE); 25113f03ced8SAlex Deucher break; 25123f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 25133f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 25143f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 2515e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 25163f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 25178d1af57aSAlex Deucher /* handled in dpms */ 25183f03ced8SAlex Deucher break; 25193f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DDI: 25203f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DVO1: 25213f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 25223f03ced8SAlex Deucher atombios_dvo_setup(encoder, ATOM_DISABLE); 25233f03ced8SAlex Deucher break; 25243f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC1: 25253f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 25263f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC2: 25273f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 25283f03ced8SAlex Deucher atombios_dac_setup(encoder, ATOM_DISABLE); 25293f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) 25303f03ced8SAlex Deucher atombios_tv_setup(encoder, ATOM_DISABLE); 25313f03ced8SAlex Deucher break; 25323f03ced8SAlex Deucher } 25333f03ced8SAlex Deucher 25343f03ced8SAlex Deucher disable_done: 25353f03ced8SAlex Deucher if (radeon_encoder_is_digital(encoder)) { 25368f0fc088SDave Airlie if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) { 25378f0fc088SDave Airlie if (rdev->asic->display.hdmi_enable) 25388f0fc088SDave Airlie radeon_hdmi_enable(rdev, encoder, false); 25393f03ced8SAlex Deucher } 25408f0fc088SDave Airlie if (atombios_get_encoder_mode(encoder) != ATOM_ENCODER_MODE_DP_MST) { 25418f0fc088SDave Airlie dig = radeon_encoder->enc_priv; 25428f0fc088SDave Airlie radeon_atom_release_dig_encoder(rdev, dig->dig_encoder); 25438f0fc088SDave Airlie dig->dig_encoder = -1; 25448f0fc088SDave Airlie radeon_encoder->active_device = 0; 25458f0fc088SDave Airlie } 25468f0fc088SDave Airlie } else 25473f03ced8SAlex Deucher radeon_encoder->active_device = 0; 25483f03ced8SAlex Deucher } 25493f03ced8SAlex Deucher 25503f03ced8SAlex Deucher /* these are handled by the primary encoders */ 25513f03ced8SAlex Deucher static void radeon_atom_ext_prepare(struct drm_encoder *encoder) 25523f03ced8SAlex Deucher { 25533f03ced8SAlex Deucher 25543f03ced8SAlex Deucher } 25553f03ced8SAlex Deucher 25563f03ced8SAlex Deucher static void radeon_atom_ext_commit(struct drm_encoder *encoder) 25573f03ced8SAlex Deucher { 25583f03ced8SAlex Deucher 25593f03ced8SAlex Deucher } 25603f03ced8SAlex Deucher 25613f03ced8SAlex Deucher static void 25623f03ced8SAlex Deucher radeon_atom_ext_mode_set(struct drm_encoder *encoder, 25633f03ced8SAlex Deucher struct drm_display_mode *mode, 25643f03ced8SAlex Deucher struct drm_display_mode *adjusted_mode) 25653f03ced8SAlex Deucher { 25663f03ced8SAlex Deucher 25673f03ced8SAlex Deucher } 25683f03ced8SAlex Deucher 25693f03ced8SAlex Deucher static void radeon_atom_ext_disable(struct drm_encoder *encoder) 25703f03ced8SAlex Deucher { 25713f03ced8SAlex Deucher 25723f03ced8SAlex Deucher } 25733f03ced8SAlex Deucher 25743f03ced8SAlex Deucher static void 25753f03ced8SAlex Deucher radeon_atom_ext_dpms(struct drm_encoder *encoder, int mode) 25763f03ced8SAlex Deucher { 25773f03ced8SAlex Deucher 25783f03ced8SAlex Deucher } 25793f03ced8SAlex Deucher 25803f03ced8SAlex Deucher static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs = { 25813f03ced8SAlex Deucher .dpms = radeon_atom_ext_dpms, 25823f03ced8SAlex Deucher .prepare = radeon_atom_ext_prepare, 25833f03ced8SAlex Deucher .mode_set = radeon_atom_ext_mode_set, 25843f03ced8SAlex Deucher .commit = radeon_atom_ext_commit, 25853f03ced8SAlex Deucher .disable = radeon_atom_ext_disable, 25863f03ced8SAlex Deucher /* no detect for TMDS/LVDS yet */ 25873f03ced8SAlex Deucher }; 25883f03ced8SAlex Deucher 25893f03ced8SAlex Deucher static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = { 25903f03ced8SAlex Deucher .dpms = radeon_atom_encoder_dpms, 25913f03ced8SAlex Deucher .mode_fixup = radeon_atom_mode_fixup, 25923f03ced8SAlex Deucher .prepare = radeon_atom_encoder_prepare, 25933f03ced8SAlex Deucher .mode_set = radeon_atom_encoder_mode_set, 25943f03ced8SAlex Deucher .commit = radeon_atom_encoder_commit, 25953f03ced8SAlex Deucher .disable = radeon_atom_encoder_disable, 25963f03ced8SAlex Deucher .detect = radeon_atom_dig_detect, 25973f03ced8SAlex Deucher }; 25983f03ced8SAlex Deucher 25993f03ced8SAlex Deucher static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = { 26003f03ced8SAlex Deucher .dpms = radeon_atom_encoder_dpms, 26013f03ced8SAlex Deucher .mode_fixup = radeon_atom_mode_fixup, 26023f03ced8SAlex Deucher .prepare = radeon_atom_encoder_prepare, 26033f03ced8SAlex Deucher .mode_set = radeon_atom_encoder_mode_set, 26043f03ced8SAlex Deucher .commit = radeon_atom_encoder_commit, 26053f03ced8SAlex Deucher .detect = radeon_atom_dac_detect, 26063f03ced8SAlex Deucher }; 26073f03ced8SAlex Deucher 26083f03ced8SAlex Deucher void radeon_enc_destroy(struct drm_encoder *encoder) 26093f03ced8SAlex Deucher { 26103f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 2611f3728734SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 2612f3728734SAlex Deucher radeon_atom_backlight_exit(radeon_encoder); 26133f03ced8SAlex Deucher kfree(radeon_encoder->enc_priv); 26143f03ced8SAlex Deucher drm_encoder_cleanup(encoder); 26153f03ced8SAlex Deucher kfree(radeon_encoder); 26163f03ced8SAlex Deucher } 26173f03ced8SAlex Deucher 26183f03ced8SAlex Deucher static const struct drm_encoder_funcs radeon_atom_enc_funcs = { 26193f03ced8SAlex Deucher .destroy = radeon_enc_destroy, 26203f03ced8SAlex Deucher }; 26213f03ced8SAlex Deucher 26221109ca09SLauri Kasanen static struct radeon_encoder_atom_dac * 26233f03ced8SAlex Deucher radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder) 26243f03ced8SAlex Deucher { 26253f03ced8SAlex Deucher struct drm_device *dev = radeon_encoder->base.dev; 26263f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 26273f03ced8SAlex Deucher struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL); 26283f03ced8SAlex Deucher 26293f03ced8SAlex Deucher if (!dac) 26303f03ced8SAlex Deucher return NULL; 26313f03ced8SAlex Deucher 26323f03ced8SAlex Deucher dac->tv_std = radeon_atombios_get_tv_info(rdev); 26333f03ced8SAlex Deucher return dac; 26343f03ced8SAlex Deucher } 26353f03ced8SAlex Deucher 26361109ca09SLauri Kasanen static struct radeon_encoder_atom_dig * 26373f03ced8SAlex Deucher radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder) 26383f03ced8SAlex Deucher { 26393f03ced8SAlex Deucher int encoder_enum = (radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT; 26403f03ced8SAlex Deucher struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL); 26413f03ced8SAlex Deucher 26423f03ced8SAlex Deucher if (!dig) 26433f03ced8SAlex Deucher return NULL; 26443f03ced8SAlex Deucher 26453f03ced8SAlex Deucher /* coherent mode by default */ 26463f03ced8SAlex Deucher dig->coherent_mode = true; 26473f03ced8SAlex Deucher dig->dig_encoder = -1; 26483f03ced8SAlex Deucher 26493f03ced8SAlex Deucher if (encoder_enum == 2) 26503f03ced8SAlex Deucher dig->linkb = true; 26513f03ced8SAlex Deucher else 26523f03ced8SAlex Deucher dig->linkb = false; 26533f03ced8SAlex Deucher 26543f03ced8SAlex Deucher return dig; 26553f03ced8SAlex Deucher } 26563f03ced8SAlex Deucher 26573f03ced8SAlex Deucher void 26583f03ced8SAlex Deucher radeon_add_atom_encoder(struct drm_device *dev, 26593f03ced8SAlex Deucher uint32_t encoder_enum, 26603f03ced8SAlex Deucher uint32_t supported_device, 26613f03ced8SAlex Deucher u16 caps) 26623f03ced8SAlex Deucher { 26633f03ced8SAlex Deucher struct radeon_device *rdev = dev->dev_private; 26643f03ced8SAlex Deucher struct drm_encoder *encoder; 26653f03ced8SAlex Deucher struct radeon_encoder *radeon_encoder; 26663f03ced8SAlex Deucher 26673f03ced8SAlex Deucher /* see if we already added it */ 26683f03ced8SAlex Deucher list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 26693f03ced8SAlex Deucher radeon_encoder = to_radeon_encoder(encoder); 26703f03ced8SAlex Deucher if (radeon_encoder->encoder_enum == encoder_enum) { 26713f03ced8SAlex Deucher radeon_encoder->devices |= supported_device; 26723f03ced8SAlex Deucher return; 26733f03ced8SAlex Deucher } 26743f03ced8SAlex Deucher 26753f03ced8SAlex Deucher } 26763f03ced8SAlex Deucher 26773f03ced8SAlex Deucher /* add a new one */ 26783f03ced8SAlex Deucher radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL); 26793f03ced8SAlex Deucher if (!radeon_encoder) 26803f03ced8SAlex Deucher return; 26813f03ced8SAlex Deucher 26823f03ced8SAlex Deucher encoder = &radeon_encoder->base; 26833f03ced8SAlex Deucher switch (rdev->num_crtc) { 26843f03ced8SAlex Deucher case 1: 26853f03ced8SAlex Deucher encoder->possible_crtcs = 0x1; 26863f03ced8SAlex Deucher break; 26873f03ced8SAlex Deucher case 2: 26883f03ced8SAlex Deucher default: 26893f03ced8SAlex Deucher encoder->possible_crtcs = 0x3; 26903f03ced8SAlex Deucher break; 26913f03ced8SAlex Deucher case 4: 26923f03ced8SAlex Deucher encoder->possible_crtcs = 0xf; 26933f03ced8SAlex Deucher break; 26943f03ced8SAlex Deucher case 6: 26953f03ced8SAlex Deucher encoder->possible_crtcs = 0x3f; 26963f03ced8SAlex Deucher break; 26973f03ced8SAlex Deucher } 26983f03ced8SAlex Deucher 26993f03ced8SAlex Deucher radeon_encoder->enc_priv = NULL; 27003f03ced8SAlex Deucher 27013f03ced8SAlex Deucher radeon_encoder->encoder_enum = encoder_enum; 27023f03ced8SAlex Deucher radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; 27033f03ced8SAlex Deucher radeon_encoder->devices = supported_device; 27043f03ced8SAlex Deucher radeon_encoder->rmx_type = RMX_OFF; 27053f03ced8SAlex Deucher radeon_encoder->underscan_type = UNDERSCAN_OFF; 27063f03ced8SAlex Deucher radeon_encoder->is_ext_encoder = false; 27073f03ced8SAlex Deucher radeon_encoder->caps = caps; 27083f03ced8SAlex Deucher 27093f03ced8SAlex Deucher switch (radeon_encoder->encoder_id) { 27103f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVDS: 27113f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 27123f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 27133f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 27143f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 27153f03ced8SAlex Deucher radeon_encoder->rmx_type = RMX_FULL; 271613a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 271713a3d91fSVille Syrjälä DRM_MODE_ENCODER_LVDS, NULL); 27183f03ced8SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); 27193f03ced8SAlex Deucher } else { 272013a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 272113a3d91fSVille Syrjälä DRM_MODE_ENCODER_TMDS, NULL); 27223f03ced8SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); 27233f03ced8SAlex Deucher } 27243f03ced8SAlex Deucher drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); 27253f03ced8SAlex Deucher break; 27263f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC1: 272713a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 272813a3d91fSVille Syrjälä DRM_MODE_ENCODER_DAC, NULL); 27293f03ced8SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder); 27303f03ced8SAlex Deucher drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs); 27313f03ced8SAlex Deucher break; 27323f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DAC2: 27333f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 27343f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 273513a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 273613a3d91fSVille Syrjälä DRM_MODE_ENCODER_TVDAC, NULL); 27373f03ced8SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder); 27383f03ced8SAlex Deucher drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs); 27393f03ced8SAlex Deucher break; 27403f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DVO1: 27413f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 27423f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_DDI: 27433f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 27443f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 27453f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 27463f03ced8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 2747e68adef8SAlex Deucher case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 27483f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 27493f03ced8SAlex Deucher radeon_encoder->rmx_type = RMX_FULL; 275013a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 275113a3d91fSVille Syrjälä DRM_MODE_ENCODER_LVDS, NULL); 27523f03ced8SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); 27533f03ced8SAlex Deucher } else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) { 275413a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 275513a3d91fSVille Syrjälä DRM_MODE_ENCODER_DAC, NULL); 27563f03ced8SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); 27573f03ced8SAlex Deucher } else { 275813a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 275913a3d91fSVille Syrjälä DRM_MODE_ENCODER_TMDS, NULL); 27603f03ced8SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); 27613f03ced8SAlex Deucher } 27623f03ced8SAlex Deucher drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); 27633f03ced8SAlex Deucher break; 27643f03ced8SAlex Deucher case ENCODER_OBJECT_ID_SI170B: 27653f03ced8SAlex Deucher case ENCODER_OBJECT_ID_CH7303: 27663f03ced8SAlex Deucher case ENCODER_OBJECT_ID_EXTERNAL_SDVOA: 27673f03ced8SAlex Deucher case ENCODER_OBJECT_ID_EXTERNAL_SDVOB: 27683f03ced8SAlex Deucher case ENCODER_OBJECT_ID_TITFP513: 27693f03ced8SAlex Deucher case ENCODER_OBJECT_ID_VT1623: 27703f03ced8SAlex Deucher case ENCODER_OBJECT_ID_HDMI_SI1930: 27713f03ced8SAlex Deucher case ENCODER_OBJECT_ID_TRAVIS: 27723f03ced8SAlex Deucher case ENCODER_OBJECT_ID_NUTMEG: 27733f03ced8SAlex Deucher /* these are handled by the primary encoders */ 27743f03ced8SAlex Deucher radeon_encoder->is_ext_encoder = true; 27753f03ced8SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 277613a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 277713a3d91fSVille Syrjälä DRM_MODE_ENCODER_LVDS, NULL); 27783f03ced8SAlex Deucher else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) 277913a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 278013a3d91fSVille Syrjälä DRM_MODE_ENCODER_DAC, NULL); 27813f03ced8SAlex Deucher else 278213a3d91fSVille Syrjälä drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, 278313a3d91fSVille Syrjälä DRM_MODE_ENCODER_TMDS, NULL); 27843f03ced8SAlex Deucher drm_encoder_helper_add(encoder, &radeon_atom_ext_helper_funcs); 27853f03ced8SAlex Deucher break; 27863f03ced8SAlex Deucher } 27873f03ced8SAlex Deucher } 2788