1771fe6b9SJerome Glisse /* 2771fe6b9SJerome Glisse * Copyright 2007-8 Advanced Micro Devices, Inc. 3771fe6b9SJerome Glisse * Copyright 2008 Red Hat Inc. 4771fe6b9SJerome Glisse * 5771fe6b9SJerome Glisse * Permission is hereby granted, free of charge, to any person obtaining a 6771fe6b9SJerome Glisse * copy of this software and associated documentation files (the "Software"), 7771fe6b9SJerome Glisse * to deal in the Software without restriction, including without limitation 8771fe6b9SJerome Glisse * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9771fe6b9SJerome Glisse * and/or sell copies of the Software, and to permit persons to whom the 10771fe6b9SJerome Glisse * Software is furnished to do so, subject to the following conditions: 11771fe6b9SJerome Glisse * 12771fe6b9SJerome Glisse * The above copyright notice and this permission notice shall be included in 13771fe6b9SJerome Glisse * all copies or substantial portions of the Software. 14771fe6b9SJerome Glisse * 15771fe6b9SJerome Glisse * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16771fe6b9SJerome Glisse * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17771fe6b9SJerome Glisse * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18771fe6b9SJerome Glisse * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19771fe6b9SJerome Glisse * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20771fe6b9SJerome Glisse * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21771fe6b9SJerome Glisse * OTHER DEALINGS IN THE SOFTWARE. 22771fe6b9SJerome Glisse * 23771fe6b9SJerome Glisse * Authors: Dave Airlie 24771fe6b9SJerome Glisse * Alex Deucher 25771fe6b9SJerome Glisse */ 26771fe6b9SJerome Glisse #include "drmP.h" 27771fe6b9SJerome Glisse #include "drm_crtc_helper.h" 28771fe6b9SJerome Glisse #include "radeon_drm.h" 29771fe6b9SJerome Glisse #include "radeon.h" 30771fe6b9SJerome Glisse #include "atom.h" 31771fe6b9SJerome Glisse 32771fe6b9SJerome Glisse extern int atom_debug; 33771fe6b9SJerome Glisse 345a9bcaccSAlex Deucher /* evil but including atombios.h is much worse */ 355a9bcaccSAlex Deucher bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index, 365a9bcaccSAlex Deucher struct drm_display_mode *mode); 375a9bcaccSAlex Deucher 38*1f3b6a45SDave Airlie static uint32_t radeon_encoder_clones(struct drm_encoder *encoder) 39*1f3b6a45SDave Airlie { 40*1f3b6a45SDave Airlie struct drm_device *dev = encoder->dev; 41*1f3b6a45SDave Airlie struct radeon_device *rdev = dev->dev_private; 42*1f3b6a45SDave Airlie struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 43*1f3b6a45SDave Airlie struct drm_encoder *clone_encoder; 44*1f3b6a45SDave Airlie uint32_t index_mask = 0; 45*1f3b6a45SDave Airlie int count; 46*1f3b6a45SDave Airlie 47*1f3b6a45SDave Airlie /* DIG routing gets problematic */ 48*1f3b6a45SDave Airlie if (rdev->family >= CHIP_R600) 49*1f3b6a45SDave Airlie return index_mask; 50*1f3b6a45SDave Airlie /* LVDS/TV are too wacky */ 51*1f3b6a45SDave Airlie if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT) 52*1f3b6a45SDave Airlie return index_mask; 53*1f3b6a45SDave Airlie /* DVO requires 2x ppll clocks depending on tmds chip */ 54*1f3b6a45SDave Airlie if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) 55*1f3b6a45SDave Airlie return index_mask; 56*1f3b6a45SDave Airlie 57*1f3b6a45SDave Airlie count = -1; 58*1f3b6a45SDave Airlie list_for_each_entry(clone_encoder, &dev->mode_config.encoder_list, head) { 59*1f3b6a45SDave Airlie struct radeon_encoder *radeon_clone = to_radeon_encoder(clone_encoder); 60*1f3b6a45SDave Airlie count++; 61*1f3b6a45SDave Airlie 62*1f3b6a45SDave Airlie if (clone_encoder == encoder) 63*1f3b6a45SDave Airlie continue; 64*1f3b6a45SDave Airlie if (radeon_clone->devices & (ATOM_DEVICE_LCD_SUPPORT)) 65*1f3b6a45SDave Airlie continue; 66*1f3b6a45SDave Airlie if (radeon_clone->devices & ATOM_DEVICE_DFP2_SUPPORT) 67*1f3b6a45SDave Airlie continue; 68*1f3b6a45SDave Airlie else 69*1f3b6a45SDave Airlie index_mask |= (1 << count); 70*1f3b6a45SDave Airlie } 71*1f3b6a45SDave Airlie return index_mask; 72*1f3b6a45SDave Airlie } 73*1f3b6a45SDave Airlie 74*1f3b6a45SDave Airlie void radeon_setup_encoder_clones(struct drm_device *dev) 75*1f3b6a45SDave Airlie { 76*1f3b6a45SDave Airlie struct drm_encoder *encoder; 77*1f3b6a45SDave Airlie 78*1f3b6a45SDave Airlie list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 79*1f3b6a45SDave Airlie encoder->possible_clones = radeon_encoder_clones(encoder); 80*1f3b6a45SDave Airlie } 81*1f3b6a45SDave Airlie } 82*1f3b6a45SDave Airlie 83771fe6b9SJerome Glisse uint32_t 84771fe6b9SJerome Glisse radeon_get_encoder_id(struct drm_device *dev, uint32_t supported_device, uint8_t dac) 85771fe6b9SJerome Glisse { 86771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 87771fe6b9SJerome Glisse uint32_t ret = 0; 88771fe6b9SJerome Glisse 89771fe6b9SJerome Glisse switch (supported_device) { 90771fe6b9SJerome Glisse case ATOM_DEVICE_CRT1_SUPPORT: 91771fe6b9SJerome Glisse case ATOM_DEVICE_TV1_SUPPORT: 92771fe6b9SJerome Glisse case ATOM_DEVICE_TV2_SUPPORT: 93771fe6b9SJerome Glisse case ATOM_DEVICE_CRT2_SUPPORT: 94771fe6b9SJerome Glisse case ATOM_DEVICE_CV_SUPPORT: 95771fe6b9SJerome Glisse switch (dac) { 96771fe6b9SJerome Glisse case 1: /* dac a */ 97771fe6b9SJerome Glisse if ((rdev->family == CHIP_RS300) || 98771fe6b9SJerome Glisse (rdev->family == CHIP_RS400) || 99771fe6b9SJerome Glisse (rdev->family == CHIP_RS480)) 100771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DAC2; 101771fe6b9SJerome Glisse else if (ASIC_IS_AVIVO(rdev)) 102771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1; 103771fe6b9SJerome Glisse else 104771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DAC1; 105771fe6b9SJerome Glisse break; 106771fe6b9SJerome Glisse case 2: /* dac b */ 107771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 108771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2; 109771fe6b9SJerome Glisse else { 110771fe6b9SJerome Glisse /*if (rdev->family == CHIP_R200) 111771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; 112771fe6b9SJerome Glisse else*/ 113771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DAC2; 114771fe6b9SJerome Glisse } 115771fe6b9SJerome Glisse break; 116771fe6b9SJerome Glisse case 3: /* external dac */ 117771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 118771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1; 119771fe6b9SJerome Glisse else 120771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; 121771fe6b9SJerome Glisse break; 122771fe6b9SJerome Glisse } 123771fe6b9SJerome Glisse break; 124771fe6b9SJerome Glisse case ATOM_DEVICE_LCD1_SUPPORT: 125771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 126771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_LVTM1; 127771fe6b9SJerome Glisse else 128771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_LVDS; 129771fe6b9SJerome Glisse break; 130771fe6b9SJerome Glisse case ATOM_DEVICE_DFP1_SUPPORT: 131771fe6b9SJerome Glisse if ((rdev->family == CHIP_RS300) || 132771fe6b9SJerome Glisse (rdev->family == CHIP_RS400) || 133771fe6b9SJerome Glisse (rdev->family == CHIP_RS480)) 134771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; 135771fe6b9SJerome Glisse else if (ASIC_IS_AVIVO(rdev)) 136771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1; 137771fe6b9SJerome Glisse else 138771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_TMDS1; 139771fe6b9SJerome Glisse break; 140771fe6b9SJerome Glisse case ATOM_DEVICE_LCD2_SUPPORT: 141771fe6b9SJerome Glisse case ATOM_DEVICE_DFP2_SUPPORT: 142771fe6b9SJerome Glisse if ((rdev->family == CHIP_RS600) || 143771fe6b9SJerome Glisse (rdev->family == CHIP_RS690) || 144771fe6b9SJerome Glisse (rdev->family == CHIP_RS740)) 145771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DDI; 146771fe6b9SJerome Glisse else if (ASIC_IS_AVIVO(rdev)) 147771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1; 148771fe6b9SJerome Glisse else 149771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; 150771fe6b9SJerome Glisse break; 151771fe6b9SJerome Glisse case ATOM_DEVICE_DFP3_SUPPORT: 152771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_LVTM1; 153771fe6b9SJerome Glisse break; 154771fe6b9SJerome Glisse } 155771fe6b9SJerome Glisse 156771fe6b9SJerome Glisse return ret; 157771fe6b9SJerome Glisse } 158771fe6b9SJerome Glisse 159771fe6b9SJerome Glisse void 160771fe6b9SJerome Glisse radeon_link_encoder_connector(struct drm_device *dev) 161771fe6b9SJerome Glisse { 162771fe6b9SJerome Glisse struct drm_connector *connector; 163771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 164771fe6b9SJerome Glisse struct drm_encoder *encoder; 165771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder; 166771fe6b9SJerome Glisse 167771fe6b9SJerome Glisse /* walk the list and link encoders to connectors */ 168771fe6b9SJerome Glisse list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 169771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 170771fe6b9SJerome Glisse list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 171771fe6b9SJerome Glisse radeon_encoder = to_radeon_encoder(encoder); 172771fe6b9SJerome Glisse if (radeon_encoder->devices & radeon_connector->devices) 173771fe6b9SJerome Glisse drm_mode_connector_attach_encoder(connector, encoder); 174771fe6b9SJerome Glisse } 175771fe6b9SJerome Glisse } 176771fe6b9SJerome Glisse } 177771fe6b9SJerome Glisse 1784ce001abSDave Airlie void radeon_encoder_set_active_device(struct drm_encoder *encoder) 1794ce001abSDave Airlie { 1804ce001abSDave Airlie struct drm_device *dev = encoder->dev; 1814ce001abSDave Airlie struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1824ce001abSDave Airlie struct drm_connector *connector; 1834ce001abSDave Airlie 1844ce001abSDave Airlie list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 1854ce001abSDave Airlie if (connector->encoder == encoder) { 1864ce001abSDave Airlie struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1874ce001abSDave Airlie radeon_encoder->active_device = radeon_encoder->devices & radeon_connector->devices; 188f641e51eSDave Airlie DRM_DEBUG("setting active device to %08x from %08x %08x for encoder %d\n", 1894ce001abSDave Airlie radeon_encoder->active_device, radeon_encoder->devices, 1904ce001abSDave Airlie radeon_connector->devices, encoder->encoder_type); 1914ce001abSDave Airlie } 1924ce001abSDave Airlie } 1934ce001abSDave Airlie } 1944ce001abSDave Airlie 195771fe6b9SJerome Glisse static struct drm_connector * 196771fe6b9SJerome Glisse radeon_get_connector_for_encoder(struct drm_encoder *encoder) 197771fe6b9SJerome Glisse { 198771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 199771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 200771fe6b9SJerome Glisse struct drm_connector *connector; 201771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 202771fe6b9SJerome Glisse 203771fe6b9SJerome Glisse list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 204771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 205771fe6b9SJerome Glisse if (radeon_encoder->devices & radeon_connector->devices) 206771fe6b9SJerome Glisse return connector; 207771fe6b9SJerome Glisse } 208771fe6b9SJerome Glisse return NULL; 209771fe6b9SJerome Glisse } 210771fe6b9SJerome Glisse 211771fe6b9SJerome Glisse static bool radeon_atom_mode_fixup(struct drm_encoder *encoder, 212771fe6b9SJerome Glisse struct drm_display_mode *mode, 213771fe6b9SJerome Glisse struct drm_display_mode *adjusted_mode) 214771fe6b9SJerome Glisse { 215771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 2165a9bcaccSAlex Deucher struct drm_device *dev = encoder->dev; 2175a9bcaccSAlex Deucher struct radeon_device *rdev = dev->dev_private; 218771fe6b9SJerome Glisse 2198c2a6d73SAlex Deucher /* set the active encoder to connector routing */ 2208c2a6d73SAlex Deucher radeon_encoder_set_active_device(encoder); 221771fe6b9SJerome Glisse drm_mode_set_crtcinfo(adjusted_mode, 0); 222771fe6b9SJerome Glisse 223771fe6b9SJerome Glisse /* hw bug */ 224771fe6b9SJerome Glisse if ((mode->flags & DRM_MODE_FLAG_INTERLACE) 225771fe6b9SJerome Glisse && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2))) 226771fe6b9SJerome Glisse adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2; 227771fe6b9SJerome Glisse 22880297e87SAlex Deucher /* get the native mode for LVDS */ 22980297e87SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) { 23080297e87SAlex Deucher struct drm_display_mode *native_mode = &radeon_encoder->native_mode; 23180297e87SAlex Deucher int mode_id = adjusted_mode->base.id; 23280297e87SAlex Deucher *adjusted_mode = *native_mode; 23380297e87SAlex Deucher if (!ASIC_IS_AVIVO(rdev)) { 23480297e87SAlex Deucher adjusted_mode->hdisplay = mode->hdisplay; 23580297e87SAlex Deucher adjusted_mode->vdisplay = mode->vdisplay; 23680297e87SAlex Deucher } 23780297e87SAlex Deucher adjusted_mode->base.id = mode_id; 23880297e87SAlex Deucher } 23980297e87SAlex Deucher 24080297e87SAlex Deucher /* get the native mode for TV */ 241ceefedd8SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) { 2425a9bcaccSAlex Deucher struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv; 2435a9bcaccSAlex Deucher if (tv_dac) { 2445a9bcaccSAlex Deucher if (tv_dac->tv_std == TV_STD_NTSC || 2455a9bcaccSAlex Deucher tv_dac->tv_std == TV_STD_NTSC_J || 2465a9bcaccSAlex Deucher tv_dac->tv_std == TV_STD_PAL_M) 2475a9bcaccSAlex Deucher radeon_atom_get_tv_timings(rdev, 0, adjusted_mode); 2485a9bcaccSAlex Deucher else 2495a9bcaccSAlex Deucher radeon_atom_get_tv_timings(rdev, 1, adjusted_mode); 2505a9bcaccSAlex Deucher } 2515a9bcaccSAlex Deucher } 2525a9bcaccSAlex Deucher 253771fe6b9SJerome Glisse return true; 254771fe6b9SJerome Glisse } 255771fe6b9SJerome Glisse 256771fe6b9SJerome Glisse static void 257771fe6b9SJerome Glisse atombios_dac_setup(struct drm_encoder *encoder, int action) 258771fe6b9SJerome Glisse { 259771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 260771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 261771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 262771fe6b9SJerome Glisse DAC_ENCODER_CONTROL_PS_ALLOCATION args; 263771fe6b9SJerome Glisse int index = 0, num = 0; 264445282dbSDave Airlie struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv; 265771fe6b9SJerome Glisse enum radeon_tv_std tv_std = TV_STD_NTSC; 266771fe6b9SJerome Glisse 267445282dbSDave Airlie if (dac_info->tv_std) 268445282dbSDave Airlie tv_std = dac_info->tv_std; 269445282dbSDave Airlie 270771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 271771fe6b9SJerome Glisse 272771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 273771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 274771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 275771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl); 276771fe6b9SJerome Glisse num = 1; 277771fe6b9SJerome Glisse break; 278771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 279771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 280771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl); 281771fe6b9SJerome Glisse num = 2; 282771fe6b9SJerome Glisse break; 283771fe6b9SJerome Glisse } 284771fe6b9SJerome Glisse 285771fe6b9SJerome Glisse args.ucAction = action; 286771fe6b9SJerome Glisse 2874ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT)) 288771fe6b9SJerome Glisse args.ucDacStandard = ATOM_DAC1_PS2; 2894ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 290771fe6b9SJerome Glisse args.ucDacStandard = ATOM_DAC1_CV; 291771fe6b9SJerome Glisse else { 292771fe6b9SJerome Glisse switch (tv_std) { 293771fe6b9SJerome Glisse case TV_STD_PAL: 294771fe6b9SJerome Glisse case TV_STD_PAL_M: 295771fe6b9SJerome Glisse case TV_STD_SCART_PAL: 296771fe6b9SJerome Glisse case TV_STD_SECAM: 297771fe6b9SJerome Glisse case TV_STD_PAL_CN: 298771fe6b9SJerome Glisse args.ucDacStandard = ATOM_DAC1_PAL; 299771fe6b9SJerome Glisse break; 300771fe6b9SJerome Glisse case TV_STD_NTSC: 301771fe6b9SJerome Glisse case TV_STD_NTSC_J: 302771fe6b9SJerome Glisse case TV_STD_PAL_60: 303771fe6b9SJerome Glisse default: 304771fe6b9SJerome Glisse args.ucDacStandard = ATOM_DAC1_NTSC; 305771fe6b9SJerome Glisse break; 306771fe6b9SJerome Glisse } 307771fe6b9SJerome Glisse } 308771fe6b9SJerome Glisse args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 309771fe6b9SJerome Glisse 310771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 311771fe6b9SJerome Glisse 312771fe6b9SJerome Glisse } 313771fe6b9SJerome Glisse 314771fe6b9SJerome Glisse static void 315771fe6b9SJerome Glisse atombios_tv_setup(struct drm_encoder *encoder, int action) 316771fe6b9SJerome Glisse { 317771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 318771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 319771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 320771fe6b9SJerome Glisse TV_ENCODER_CONTROL_PS_ALLOCATION args; 321771fe6b9SJerome Glisse int index = 0; 322445282dbSDave Airlie struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv; 323771fe6b9SJerome Glisse enum radeon_tv_std tv_std = TV_STD_NTSC; 324771fe6b9SJerome Glisse 325445282dbSDave Airlie if (dac_info->tv_std) 326445282dbSDave Airlie tv_std = dac_info->tv_std; 327445282dbSDave Airlie 328771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 329771fe6b9SJerome Glisse 330771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl); 331771fe6b9SJerome Glisse 332771fe6b9SJerome Glisse args.sTVEncoder.ucAction = action; 333771fe6b9SJerome Glisse 3344ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 335771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_CV; 336771fe6b9SJerome Glisse else { 337771fe6b9SJerome Glisse switch (tv_std) { 338771fe6b9SJerome Glisse case TV_STD_NTSC: 339771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC; 340771fe6b9SJerome Glisse break; 341771fe6b9SJerome Glisse case TV_STD_PAL: 342771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; 343771fe6b9SJerome Glisse break; 344771fe6b9SJerome Glisse case TV_STD_PAL_M: 345771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PALM; 346771fe6b9SJerome Glisse break; 347771fe6b9SJerome Glisse case TV_STD_PAL_60: 348771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60; 349771fe6b9SJerome Glisse break; 350771fe6b9SJerome Glisse case TV_STD_NTSC_J: 351771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ; 352771fe6b9SJerome Glisse break; 353771fe6b9SJerome Glisse case TV_STD_SCART_PAL: 354771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */ 355771fe6b9SJerome Glisse break; 356771fe6b9SJerome Glisse case TV_STD_SECAM: 357771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM; 358771fe6b9SJerome Glisse break; 359771fe6b9SJerome Glisse case TV_STD_PAL_CN: 360771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN; 361771fe6b9SJerome Glisse break; 362771fe6b9SJerome Glisse default: 363771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC; 364771fe6b9SJerome Glisse break; 365771fe6b9SJerome Glisse } 366771fe6b9SJerome Glisse } 367771fe6b9SJerome Glisse 368771fe6b9SJerome Glisse args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 369771fe6b9SJerome Glisse 370771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 371771fe6b9SJerome Glisse 372771fe6b9SJerome Glisse } 373771fe6b9SJerome Glisse 374771fe6b9SJerome Glisse void 375771fe6b9SJerome Glisse atombios_external_tmds_setup(struct drm_encoder *encoder, int action) 376771fe6b9SJerome Glisse { 377771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 378771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 379771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 380771fe6b9SJerome Glisse ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION args; 381771fe6b9SJerome Glisse int index = 0; 382771fe6b9SJerome Glisse 383771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 384771fe6b9SJerome Glisse 385771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl); 386771fe6b9SJerome Glisse 387771fe6b9SJerome Glisse args.sXTmdsEncoder.ucEnable = action; 388771fe6b9SJerome Glisse 389771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 390771fe6b9SJerome Glisse args.sXTmdsEncoder.ucMisc = PANEL_ENCODER_MISC_DUAL; 391771fe6b9SJerome Glisse 392771fe6b9SJerome Glisse /*if (pScrn->rgbBits == 8)*/ 393771fe6b9SJerome Glisse args.sXTmdsEncoder.ucMisc |= (1 << 1); 394771fe6b9SJerome Glisse 395771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 396771fe6b9SJerome Glisse 397771fe6b9SJerome Glisse } 398771fe6b9SJerome Glisse 399771fe6b9SJerome Glisse static void 400771fe6b9SJerome Glisse atombios_ddia_setup(struct drm_encoder *encoder, int action) 401771fe6b9SJerome Glisse { 402771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 403771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 404771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 405771fe6b9SJerome Glisse DVO_ENCODER_CONTROL_PS_ALLOCATION args; 406771fe6b9SJerome Glisse int index = 0; 407771fe6b9SJerome Glisse 408771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 409771fe6b9SJerome Glisse 410771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl); 411771fe6b9SJerome Glisse 412771fe6b9SJerome Glisse args.sDVOEncoder.ucAction = action; 413771fe6b9SJerome Glisse args.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 414771fe6b9SJerome Glisse 415771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 416771fe6b9SJerome Glisse args.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute = PANEL_ENCODER_MISC_DUAL; 417771fe6b9SJerome Glisse 418771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 419771fe6b9SJerome Glisse 420771fe6b9SJerome Glisse } 421771fe6b9SJerome Glisse 422771fe6b9SJerome Glisse union lvds_encoder_control { 423771fe6b9SJerome Glisse LVDS_ENCODER_CONTROL_PS_ALLOCATION v1; 424771fe6b9SJerome Glisse LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2; 425771fe6b9SJerome Glisse }; 426771fe6b9SJerome Glisse 427771fe6b9SJerome Glisse static void 428771fe6b9SJerome Glisse atombios_digital_setup(struct drm_encoder *encoder, int action) 429771fe6b9SJerome Glisse { 430771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 431771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 432771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 433771fe6b9SJerome Glisse union lvds_encoder_control args; 434771fe6b9SJerome Glisse int index = 0; 435771fe6b9SJerome Glisse uint8_t frev, crev; 436771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig; 437771fe6b9SJerome Glisse struct drm_connector *connector; 438771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 439771fe6b9SJerome Glisse struct radeon_connector_atom_dig *dig_connector; 440771fe6b9SJerome Glisse 441771fe6b9SJerome Glisse connector = radeon_get_connector_for_encoder(encoder); 442771fe6b9SJerome Glisse if (!connector) 443771fe6b9SJerome Glisse return; 444771fe6b9SJerome Glisse 445771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 446771fe6b9SJerome Glisse 447771fe6b9SJerome Glisse if (!radeon_encoder->enc_priv) 448771fe6b9SJerome Glisse return; 449771fe6b9SJerome Glisse 450771fe6b9SJerome Glisse dig = radeon_encoder->enc_priv; 451771fe6b9SJerome Glisse 452771fe6b9SJerome Glisse if (!radeon_connector->con_priv) 453771fe6b9SJerome Glisse return; 454771fe6b9SJerome Glisse 455771fe6b9SJerome Glisse dig_connector = radeon_connector->con_priv; 456771fe6b9SJerome Glisse 457771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 458771fe6b9SJerome Glisse 459771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 460771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 461771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl); 462771fe6b9SJerome Glisse break; 463771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 464771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 465771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl); 466771fe6b9SJerome Glisse break; 467771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 468771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 469771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl); 470771fe6b9SJerome Glisse else 471771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl); 472771fe6b9SJerome Glisse break; 473771fe6b9SJerome Glisse } 474771fe6b9SJerome Glisse 475771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 476771fe6b9SJerome Glisse 477771fe6b9SJerome Glisse switch (frev) { 478771fe6b9SJerome Glisse case 1: 479771fe6b9SJerome Glisse case 2: 480771fe6b9SJerome Glisse switch (crev) { 481771fe6b9SJerome Glisse case 1: 482771fe6b9SJerome Glisse args.v1.ucMisc = 0; 483771fe6b9SJerome Glisse args.v1.ucAction = action; 4840294cf4fSAlex Deucher if (drm_detect_hdmi_monitor(radeon_connector->edid)) 485771fe6b9SJerome Glisse args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE; 486771fe6b9SJerome Glisse args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 487771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 488771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 0)) 489771fe6b9SJerome Glisse args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; 490771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 1)) 491771fe6b9SJerome Glisse args.v1.ucMisc |= (1 << 1); 492771fe6b9SJerome Glisse } else { 493771fe6b9SJerome Glisse if (dig_connector->linkb) 494771fe6b9SJerome Glisse args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; 495771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 496771fe6b9SJerome Glisse args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; 497771fe6b9SJerome Glisse /*if (pScrn->rgbBits == 8) */ 498771fe6b9SJerome Glisse args.v1.ucMisc |= (1 << 1); 499771fe6b9SJerome Glisse } 500771fe6b9SJerome Glisse break; 501771fe6b9SJerome Glisse case 2: 502771fe6b9SJerome Glisse case 3: 503771fe6b9SJerome Glisse args.v2.ucMisc = 0; 504771fe6b9SJerome Glisse args.v2.ucAction = action; 505771fe6b9SJerome Glisse if (crev == 3) { 506771fe6b9SJerome Glisse if (dig->coherent_mode) 507771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT; 508771fe6b9SJerome Glisse } 5090294cf4fSAlex Deucher if (drm_detect_hdmi_monitor(radeon_connector->edid)) 510771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE; 511771fe6b9SJerome Glisse args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 512771fe6b9SJerome Glisse args.v2.ucTruncate = 0; 513771fe6b9SJerome Glisse args.v2.ucSpatial = 0; 514771fe6b9SJerome Glisse args.v2.ucTemporal = 0; 515771fe6b9SJerome Glisse args.v2.ucFRC = 0; 516771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 517771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 0)) 518771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL; 519771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 5)) { 520771fe6b9SJerome Glisse args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN; 521771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 1)) 522771fe6b9SJerome Glisse args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH; 523771fe6b9SJerome Glisse } 524771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 6)) { 525771fe6b9SJerome Glisse args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN; 526771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 1)) 527771fe6b9SJerome Glisse args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH; 528771fe6b9SJerome Glisse if (((dig->lvds_misc >> 2) & 0x3) == 2) 529771fe6b9SJerome Glisse args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4; 530771fe6b9SJerome Glisse } 531771fe6b9SJerome Glisse } else { 532771fe6b9SJerome Glisse if (dig_connector->linkb) 533771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; 534771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 535771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL; 536771fe6b9SJerome Glisse } 537771fe6b9SJerome Glisse break; 538771fe6b9SJerome Glisse default: 539771fe6b9SJerome Glisse DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 540771fe6b9SJerome Glisse break; 541771fe6b9SJerome Glisse } 542771fe6b9SJerome Glisse break; 543771fe6b9SJerome Glisse default: 544771fe6b9SJerome Glisse DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 545771fe6b9SJerome Glisse break; 546771fe6b9SJerome Glisse } 547771fe6b9SJerome Glisse 548771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 549771fe6b9SJerome Glisse 550771fe6b9SJerome Glisse } 551771fe6b9SJerome Glisse 552771fe6b9SJerome Glisse int 553771fe6b9SJerome Glisse atombios_get_encoder_mode(struct drm_encoder *encoder) 554771fe6b9SJerome Glisse { 555771fe6b9SJerome Glisse struct drm_connector *connector; 556771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 557771fe6b9SJerome Glisse 558771fe6b9SJerome Glisse connector = radeon_get_connector_for_encoder(encoder); 559771fe6b9SJerome Glisse if (!connector) 560771fe6b9SJerome Glisse return 0; 561771fe6b9SJerome Glisse 562771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 563771fe6b9SJerome Glisse 564771fe6b9SJerome Glisse switch (connector->connector_type) { 565771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_DVII: 566705af9c7SAlex Deucher case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */ 5670294cf4fSAlex Deucher if (drm_detect_hdmi_monitor(radeon_connector->edid)) 568771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_HDMI; 569771fe6b9SJerome Glisse else if (radeon_connector->use_digital) 570771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_DVI; 571771fe6b9SJerome Glisse else 572771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_CRT; 573771fe6b9SJerome Glisse break; 574771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_DVID: 575771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_HDMIA: 576771fe6b9SJerome Glisse default: 5770294cf4fSAlex Deucher if (drm_detect_hdmi_monitor(radeon_connector->edid)) 578771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_HDMI; 579771fe6b9SJerome Glisse else 580771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_DVI; 581771fe6b9SJerome Glisse break; 582771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_LVDS: 583771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_LVDS; 584771fe6b9SJerome Glisse break; 585771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_DisplayPort: 586771fe6b9SJerome Glisse /*if (radeon_output->MonType == MT_DP) 587771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_DP; 588771fe6b9SJerome Glisse else*/ 5890294cf4fSAlex Deucher if (drm_detect_hdmi_monitor(radeon_connector->edid)) 590771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_HDMI; 591771fe6b9SJerome Glisse else 592771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_DVI; 593771fe6b9SJerome Glisse break; 594771fe6b9SJerome Glisse case CONNECTOR_DVI_A: 595771fe6b9SJerome Glisse case CONNECTOR_VGA: 596771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_CRT; 597771fe6b9SJerome Glisse break; 598771fe6b9SJerome Glisse case CONNECTOR_STV: 599771fe6b9SJerome Glisse case CONNECTOR_CTV: 600771fe6b9SJerome Glisse case CONNECTOR_DIN: 601771fe6b9SJerome Glisse /* fix me */ 602771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_TV; 603771fe6b9SJerome Glisse /*return ATOM_ENCODER_MODE_CV;*/ 604771fe6b9SJerome Glisse break; 605771fe6b9SJerome Glisse } 606771fe6b9SJerome Glisse } 607771fe6b9SJerome Glisse 608771fe6b9SJerome Glisse static void 609771fe6b9SJerome Glisse atombios_dig_encoder_setup(struct drm_encoder *encoder, int action) 610771fe6b9SJerome Glisse { 611771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 612771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 613771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 614771fe6b9SJerome Glisse DIG_ENCODER_CONTROL_PS_ALLOCATION args; 615771fe6b9SJerome Glisse int index = 0, num = 0; 616771fe6b9SJerome Glisse uint8_t frev, crev; 617771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig; 618771fe6b9SJerome Glisse struct drm_connector *connector; 619771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 620771fe6b9SJerome Glisse struct radeon_connector_atom_dig *dig_connector; 621771fe6b9SJerome Glisse 622771fe6b9SJerome Glisse connector = radeon_get_connector_for_encoder(encoder); 623771fe6b9SJerome Glisse if (!connector) 624771fe6b9SJerome Glisse return; 625771fe6b9SJerome Glisse 626771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 627771fe6b9SJerome Glisse 628771fe6b9SJerome Glisse if (!radeon_connector->con_priv) 629771fe6b9SJerome Glisse return; 630771fe6b9SJerome Glisse 631771fe6b9SJerome Glisse dig_connector = radeon_connector->con_priv; 632771fe6b9SJerome Glisse 633771fe6b9SJerome Glisse if (!radeon_encoder->enc_priv) 634771fe6b9SJerome Glisse return; 635771fe6b9SJerome Glisse 636771fe6b9SJerome Glisse dig = radeon_encoder->enc_priv; 637771fe6b9SJerome Glisse 638771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 639771fe6b9SJerome Glisse 640771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) { 641771fe6b9SJerome Glisse if (dig->dig_block) 642771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); 643771fe6b9SJerome Glisse else 644771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); 645771fe6b9SJerome Glisse num = dig->dig_block + 1; 646771fe6b9SJerome Glisse } else { 647771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 648771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 649771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); 650771fe6b9SJerome Glisse num = 1; 651771fe6b9SJerome Glisse break; 652771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 653771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); 654771fe6b9SJerome Glisse num = 2; 655771fe6b9SJerome Glisse break; 656771fe6b9SJerome Glisse } 657771fe6b9SJerome Glisse } 658771fe6b9SJerome Glisse 659771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 660771fe6b9SJerome Glisse 661771fe6b9SJerome Glisse args.ucAction = action; 662771fe6b9SJerome Glisse args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 663771fe6b9SJerome Glisse 664771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) { 665771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 666771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 667771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1; 668771fe6b9SJerome Glisse break; 669771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 670771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2; 671771fe6b9SJerome Glisse break; 672771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 673771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3; 674771fe6b9SJerome Glisse break; 675771fe6b9SJerome Glisse } 676771fe6b9SJerome Glisse } else { 677771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 678771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 679771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_TRANSMITTER1; 680771fe6b9SJerome Glisse break; 681771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 682771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_TRANSMITTER2; 683771fe6b9SJerome Glisse break; 684771fe6b9SJerome Glisse } 685771fe6b9SJerome Glisse } 686771fe6b9SJerome Glisse 687771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) { 688771fe6b9SJerome Glisse args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA_B; 689771fe6b9SJerome Glisse args.ucLaneNum = 8; 690771fe6b9SJerome Glisse } else { 691771fe6b9SJerome Glisse if (dig_connector->linkb) 692771fe6b9SJerome Glisse args.ucConfig |= ATOM_ENCODER_CONFIG_LINKB; 693771fe6b9SJerome Glisse else 694771fe6b9SJerome Glisse args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA; 695771fe6b9SJerome Glisse args.ucLaneNum = 4; 696771fe6b9SJerome Glisse } 697771fe6b9SJerome Glisse 698771fe6b9SJerome Glisse args.ucEncoderMode = atombios_get_encoder_mode(encoder); 699771fe6b9SJerome Glisse 700771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 701771fe6b9SJerome Glisse 702771fe6b9SJerome Glisse } 703771fe6b9SJerome Glisse 704771fe6b9SJerome Glisse union dig_transmitter_control { 705771fe6b9SJerome Glisse DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1; 706771fe6b9SJerome Glisse DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2; 707771fe6b9SJerome Glisse }; 708771fe6b9SJerome Glisse 709771fe6b9SJerome Glisse static void 710771fe6b9SJerome Glisse atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action) 711771fe6b9SJerome Glisse { 712771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 713771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 714771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 715771fe6b9SJerome Glisse union dig_transmitter_control args; 716771fe6b9SJerome Glisse int index = 0, num = 0; 717771fe6b9SJerome Glisse uint8_t frev, crev; 718771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig; 719771fe6b9SJerome Glisse struct drm_connector *connector; 720771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 721771fe6b9SJerome Glisse struct radeon_connector_atom_dig *dig_connector; 722771fe6b9SJerome Glisse 723771fe6b9SJerome Glisse connector = radeon_get_connector_for_encoder(encoder); 724771fe6b9SJerome Glisse if (!connector) 725771fe6b9SJerome Glisse return; 726771fe6b9SJerome Glisse 727771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 728771fe6b9SJerome Glisse 729771fe6b9SJerome Glisse if (!radeon_encoder->enc_priv) 730771fe6b9SJerome Glisse return; 731771fe6b9SJerome Glisse 732771fe6b9SJerome Glisse dig = radeon_encoder->enc_priv; 733771fe6b9SJerome Glisse 734771fe6b9SJerome Glisse if (!radeon_connector->con_priv) 735771fe6b9SJerome Glisse return; 736771fe6b9SJerome Glisse 737771fe6b9SJerome Glisse dig_connector = radeon_connector->con_priv; 738771fe6b9SJerome Glisse 739771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 740771fe6b9SJerome Glisse 741771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) 742771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl); 743771fe6b9SJerome Glisse else { 744771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 745771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 746771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG1TransmitterControl); 747771fe6b9SJerome Glisse break; 748771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 749771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG2TransmitterControl); 750771fe6b9SJerome Glisse break; 751771fe6b9SJerome Glisse } 752771fe6b9SJerome Glisse } 753771fe6b9SJerome Glisse 754771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 755771fe6b9SJerome Glisse 756771fe6b9SJerome Glisse args.v1.ucAction = action; 757f95a9f0bSAlex Deucher if (action == ATOM_TRANSMITTER_ACTION_INIT) { 758f95a9f0bSAlex Deucher args.v1.usInitInfo = radeon_connector->connector_object_id; 759771fe6b9SJerome Glisse } else { 760f95a9f0bSAlex Deucher if (radeon_encoder->pixel_clock > 165000) 761f95a9f0bSAlex Deucher args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10); 762f95a9f0bSAlex Deucher else 763f95a9f0bSAlex Deucher args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 764771fe6b9SJerome Glisse } 765f95a9f0bSAlex Deucher if (ASIC_IS_DCE32(rdev)) { 766f95a9f0bSAlex Deucher if (radeon_encoder->pixel_clock > 165000) 767f95a9f0bSAlex Deucher args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10); 768771fe6b9SJerome Glisse if (dig->dig_block) 769771fe6b9SJerome Glisse args.v2.acConfig.ucEncoderSel = 1; 770771fe6b9SJerome Glisse 771771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 772771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 773771fe6b9SJerome Glisse args.v2.acConfig.ucTransmitterSel = 0; 774771fe6b9SJerome Glisse num = 0; 775771fe6b9SJerome Glisse break; 776771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 777771fe6b9SJerome Glisse args.v2.acConfig.ucTransmitterSel = 1; 778771fe6b9SJerome Glisse num = 1; 779771fe6b9SJerome Glisse break; 780771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 781771fe6b9SJerome Glisse args.v2.acConfig.ucTransmitterSel = 2; 782771fe6b9SJerome Glisse num = 2; 783771fe6b9SJerome Glisse break; 784771fe6b9SJerome Glisse } 785771fe6b9SJerome Glisse 786771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 787771fe6b9SJerome Glisse if (dig->coherent_mode) 788771fe6b9SJerome Glisse args.v2.acConfig.fCoherentMode = 1; 789771fe6b9SJerome Glisse } 790771fe6b9SJerome Glisse } else { 791771fe6b9SJerome Glisse args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL; 792771fe6b9SJerome Glisse 793771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 794771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 795771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER; 796771fe6b9SJerome Glisse if (rdev->flags & RADEON_IS_IGP) { 797771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) { 798771fe6b9SJerome Glisse args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | 799771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LINKA_B); 800771fe6b9SJerome Glisse if (dig_connector->igp_lane_info & 0x3) 801771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7; 802771fe6b9SJerome Glisse else if (dig_connector->igp_lane_info & 0xc) 803771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15; 804771fe6b9SJerome Glisse } else { 805771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA; 806771fe6b9SJerome Glisse if (dig_connector->igp_lane_info & 0x1) 807771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3; 808771fe6b9SJerome Glisse else if (dig_connector->igp_lane_info & 0x2) 809771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7; 810771fe6b9SJerome Glisse else if (dig_connector->igp_lane_info & 0x4) 811771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11; 812771fe6b9SJerome Glisse else if (dig_connector->igp_lane_info & 0x8) 813771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15; 814771fe6b9SJerome Glisse } 815771fe6b9SJerome Glisse } else { 816771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 817771fe6b9SJerome Glisse args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | 818771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LINKA_B | 819771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LANE_0_7); 820771fe6b9SJerome Glisse else { 821771fe6b9SJerome Glisse if (dig_connector->linkb) 822771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB | ATOM_TRANSMITTER_CONFIG_LANE_0_3; 823771fe6b9SJerome Glisse else 824771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA | ATOM_TRANSMITTER_CONFIG_LANE_0_3; 825771fe6b9SJerome Glisse } 826771fe6b9SJerome Glisse } 827771fe6b9SJerome Glisse break; 828771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 829771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER; 830771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 831771fe6b9SJerome Glisse args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | 832771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LINKA_B | 833771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LANE_0_7); 834771fe6b9SJerome Glisse else { 835771fe6b9SJerome Glisse if (dig_connector->linkb) 836771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB | ATOM_TRANSMITTER_CONFIG_LANE_0_3; 837771fe6b9SJerome Glisse else 838771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA | ATOM_TRANSMITTER_CONFIG_LANE_0_3; 839771fe6b9SJerome Glisse } 840771fe6b9SJerome Glisse break; 841771fe6b9SJerome Glisse } 842771fe6b9SJerome Glisse 843771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 844771fe6b9SJerome Glisse if (dig->coherent_mode) 845771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT; 846771fe6b9SJerome Glisse } 847771fe6b9SJerome Glisse } 848771fe6b9SJerome Glisse 849771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 850771fe6b9SJerome Glisse 851771fe6b9SJerome Glisse } 852771fe6b9SJerome Glisse 853771fe6b9SJerome Glisse static void 854771fe6b9SJerome Glisse atombios_yuv_setup(struct drm_encoder *encoder, bool enable) 855771fe6b9SJerome Glisse { 856771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 857771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 858771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 859771fe6b9SJerome Glisse struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 860771fe6b9SJerome Glisse ENABLE_YUV_PS_ALLOCATION args; 861771fe6b9SJerome Glisse int index = GetIndexIntoMasterTable(COMMAND, EnableYUV); 862771fe6b9SJerome Glisse uint32_t temp, reg; 863771fe6b9SJerome Glisse 864771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 865771fe6b9SJerome Glisse 866771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) 867771fe6b9SJerome Glisse reg = R600_BIOS_3_SCRATCH; 868771fe6b9SJerome Glisse else 869771fe6b9SJerome Glisse reg = RADEON_BIOS_3_SCRATCH; 870771fe6b9SJerome Glisse 871771fe6b9SJerome Glisse /* XXX: fix up scratch reg handling */ 872771fe6b9SJerome Glisse temp = RREG32(reg); 8734ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 874771fe6b9SJerome Glisse WREG32(reg, (ATOM_S3_TV1_ACTIVE | 875771fe6b9SJerome Glisse (radeon_crtc->crtc_id << 18))); 8764ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 877771fe6b9SJerome Glisse WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24))); 878771fe6b9SJerome Glisse else 879771fe6b9SJerome Glisse WREG32(reg, 0); 880771fe6b9SJerome Glisse 881771fe6b9SJerome Glisse if (enable) 882771fe6b9SJerome Glisse args.ucEnable = ATOM_ENABLE; 883771fe6b9SJerome Glisse args.ucCRTC = radeon_crtc->crtc_id; 884771fe6b9SJerome Glisse 885771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 886771fe6b9SJerome Glisse 887771fe6b9SJerome Glisse WREG32(reg, temp); 888771fe6b9SJerome Glisse } 889771fe6b9SJerome Glisse 890771fe6b9SJerome Glisse static void 891771fe6b9SJerome Glisse radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode) 892771fe6b9SJerome Glisse { 893771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 894771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 895771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 896771fe6b9SJerome Glisse DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args; 897771fe6b9SJerome Glisse int index = 0; 898771fe6b9SJerome Glisse bool is_dig = false; 899771fe6b9SJerome Glisse 900771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 901771fe6b9SJerome Glisse 902f641e51eSDave Airlie DRM_DEBUG("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n", 9034ce001abSDave Airlie radeon_encoder->encoder_id, mode, radeon_encoder->devices, 9044ce001abSDave Airlie radeon_encoder->active_device); 905771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 906771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 907771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 908771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl); 909771fe6b9SJerome Glisse break; 910771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 911771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 912771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 913771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 914771fe6b9SJerome Glisse is_dig = true; 915771fe6b9SJerome Glisse break; 916771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DVO1: 917771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DDI: 918771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 919771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl); 920771fe6b9SJerome Glisse break; 921771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 922771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); 923771fe6b9SJerome Glisse break; 924771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 925771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 926771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); 927771fe6b9SJerome Glisse else 928771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl); 929771fe6b9SJerome Glisse break; 930771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 931771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 9328c2a6d73SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 933771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl); 9348c2a6d73SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 935771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl); 936771fe6b9SJerome Glisse else 937771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl); 938771fe6b9SJerome Glisse break; 939771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 940771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 9418c2a6d73SAlex Deucher if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 942771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl); 9438c2a6d73SAlex Deucher else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 944771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl); 945771fe6b9SJerome Glisse else 946771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl); 947771fe6b9SJerome Glisse break; 948771fe6b9SJerome Glisse } 949771fe6b9SJerome Glisse 950771fe6b9SJerome Glisse if (is_dig) { 951771fe6b9SJerome Glisse switch (mode) { 952771fe6b9SJerome Glisse case DRM_MODE_DPMS_ON: 953771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE); 954771fe6b9SJerome Glisse break; 955771fe6b9SJerome Glisse case DRM_MODE_DPMS_STANDBY: 956771fe6b9SJerome Glisse case DRM_MODE_DPMS_SUSPEND: 957771fe6b9SJerome Glisse case DRM_MODE_DPMS_OFF: 958771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE); 959771fe6b9SJerome Glisse break; 960771fe6b9SJerome Glisse } 961771fe6b9SJerome Glisse } else { 962771fe6b9SJerome Glisse switch (mode) { 963771fe6b9SJerome Glisse case DRM_MODE_DPMS_ON: 964771fe6b9SJerome Glisse args.ucAction = ATOM_ENABLE; 965771fe6b9SJerome Glisse break; 966771fe6b9SJerome Glisse case DRM_MODE_DPMS_STANDBY: 967771fe6b9SJerome Glisse case DRM_MODE_DPMS_SUSPEND: 968771fe6b9SJerome Glisse case DRM_MODE_DPMS_OFF: 969771fe6b9SJerome Glisse args.ucAction = ATOM_DISABLE; 970771fe6b9SJerome Glisse break; 971771fe6b9SJerome Glisse } 972771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 973771fe6b9SJerome Glisse } 974771fe6b9SJerome Glisse radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 975771fe6b9SJerome Glisse } 976771fe6b9SJerome Glisse 977771fe6b9SJerome Glisse union crtc_sourc_param { 978771fe6b9SJerome Glisse SELECT_CRTC_SOURCE_PS_ALLOCATION v1; 979771fe6b9SJerome Glisse SELECT_CRTC_SOURCE_PARAMETERS_V2 v2; 980771fe6b9SJerome Glisse }; 981771fe6b9SJerome Glisse 982771fe6b9SJerome Glisse static void 983771fe6b9SJerome Glisse atombios_set_encoder_crtc_source(struct drm_encoder *encoder) 984771fe6b9SJerome Glisse { 985771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 986771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 987771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 988771fe6b9SJerome Glisse struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 989771fe6b9SJerome Glisse union crtc_sourc_param args; 990771fe6b9SJerome Glisse int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source); 991771fe6b9SJerome Glisse uint8_t frev, crev; 992771fe6b9SJerome Glisse 993771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 994771fe6b9SJerome Glisse 995771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 996771fe6b9SJerome Glisse 997771fe6b9SJerome Glisse switch (frev) { 998771fe6b9SJerome Glisse case 1: 999771fe6b9SJerome Glisse switch (crev) { 1000771fe6b9SJerome Glisse case 1: 1001771fe6b9SJerome Glisse default: 1002771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 1003771fe6b9SJerome Glisse args.v1.ucCRTC = radeon_crtc->crtc_id; 1004771fe6b9SJerome Glisse else { 1005771fe6b9SJerome Glisse if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) { 1006771fe6b9SJerome Glisse args.v1.ucCRTC = radeon_crtc->crtc_id; 1007771fe6b9SJerome Glisse } else { 1008771fe6b9SJerome Glisse args.v1.ucCRTC = radeon_crtc->crtc_id << 2; 1009771fe6b9SJerome Glisse } 1010771fe6b9SJerome Glisse } 1011771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 1012771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 1013771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 1014771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX; 1015771fe6b9SJerome Glisse break; 1016771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 1017771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 1018771fe6b9SJerome Glisse if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) 1019771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX; 1020771fe6b9SJerome Glisse else 1021771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX; 1022771fe6b9SJerome Glisse break; 1023771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1024771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DDI: 1025771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1026771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX; 1027771fe6b9SJerome Glisse break; 1028771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1029771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 10304ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1031771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX; 10324ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 1033771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_CV_INDEX; 1034771fe6b9SJerome Glisse else 1035771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX; 1036771fe6b9SJerome Glisse break; 1037771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 1038771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 10394ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1040771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX; 10414ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 1042771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_CV_INDEX; 1043771fe6b9SJerome Glisse else 1044771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX; 1045771fe6b9SJerome Glisse break; 1046771fe6b9SJerome Glisse } 1047771fe6b9SJerome Glisse break; 1048771fe6b9SJerome Glisse case 2: 1049771fe6b9SJerome Glisse args.v2.ucCRTC = radeon_crtc->crtc_id; 1050771fe6b9SJerome Glisse args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder); 1051771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 1052771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1053771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1054771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1055771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) { 1056771fe6b9SJerome Glisse if (radeon_crtc->crtc_id) 1057771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; 1058771fe6b9SJerome Glisse else 1059771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID; 1060771fe6b9SJerome Glisse } else 1061771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID; 1062771fe6b9SJerome Glisse break; 1063771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1064771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID; 1065771fe6b9SJerome Glisse break; 1066771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 1067771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; 1068771fe6b9SJerome Glisse break; 1069771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 10704ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1071771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 10724ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 1073771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 1074771fe6b9SJerome Glisse else 1075771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID; 1076771fe6b9SJerome Glisse break; 1077771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 10784ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1079771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 10804ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 1081771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 1082771fe6b9SJerome Glisse else 1083771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID; 1084771fe6b9SJerome Glisse break; 1085771fe6b9SJerome Glisse } 1086771fe6b9SJerome Glisse break; 1087771fe6b9SJerome Glisse } 1088771fe6b9SJerome Glisse break; 1089771fe6b9SJerome Glisse default: 1090771fe6b9SJerome Glisse DRM_ERROR("Unknown table version: %d, %d\n", frev, crev); 1091771fe6b9SJerome Glisse break; 1092771fe6b9SJerome Glisse } 1093771fe6b9SJerome Glisse 1094771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 1095771fe6b9SJerome Glisse 1096771fe6b9SJerome Glisse } 1097771fe6b9SJerome Glisse 1098771fe6b9SJerome Glisse static void 1099771fe6b9SJerome Glisse atombios_apply_encoder_quirks(struct drm_encoder *encoder, 1100771fe6b9SJerome Glisse struct drm_display_mode *mode) 1101771fe6b9SJerome Glisse { 1102771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 1103771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 1104771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1105771fe6b9SJerome Glisse struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 1106771fe6b9SJerome Glisse 1107771fe6b9SJerome Glisse /* Funky macbooks */ 1108771fe6b9SJerome Glisse if ((dev->pdev->device == 0x71C5) && 1109771fe6b9SJerome Glisse (dev->pdev->subsystem_vendor == 0x106b) && 1110771fe6b9SJerome Glisse (dev->pdev->subsystem_device == 0x0080)) { 1111771fe6b9SJerome Glisse if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) { 1112771fe6b9SJerome Glisse uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL); 1113771fe6b9SJerome Glisse 1114771fe6b9SJerome Glisse lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN; 1115771fe6b9SJerome Glisse lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN; 1116771fe6b9SJerome Glisse 1117771fe6b9SJerome Glisse WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control); 1118771fe6b9SJerome Glisse } 1119771fe6b9SJerome Glisse } 1120771fe6b9SJerome Glisse 1121771fe6b9SJerome Glisse /* set scaler clears this on some chips */ 1122ceefedd8SAlex Deucher if (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))) { 1123771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev) && (mode->flags & DRM_MODE_FLAG_INTERLACE)) 1124ceefedd8SAlex Deucher WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 1125ceefedd8SAlex Deucher AVIVO_D1MODE_INTERLEAVE_EN); 1126ceefedd8SAlex Deucher } 1127771fe6b9SJerome Glisse } 1128771fe6b9SJerome Glisse 1129771fe6b9SJerome Glisse static void 1130771fe6b9SJerome Glisse radeon_atom_encoder_mode_set(struct drm_encoder *encoder, 1131771fe6b9SJerome Glisse struct drm_display_mode *mode, 1132771fe6b9SJerome Glisse struct drm_display_mode *adjusted_mode) 1133771fe6b9SJerome Glisse { 1134771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 1135771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 1136771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1137771fe6b9SJerome Glisse struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 1138771fe6b9SJerome Glisse 1139771fe6b9SJerome Glisse if (radeon_encoder->enc_priv) { 1140771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig; 1141771fe6b9SJerome Glisse 1142771fe6b9SJerome Glisse dig = radeon_encoder->enc_priv; 1143771fe6b9SJerome Glisse dig->dig_block = radeon_crtc->crtc_id; 1144771fe6b9SJerome Glisse } 1145771fe6b9SJerome Glisse radeon_encoder->pixel_clock = adjusted_mode->clock; 1146771fe6b9SJerome Glisse 1147771fe6b9SJerome Glisse radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 1148771fe6b9SJerome Glisse atombios_set_encoder_crtc_source(encoder); 1149771fe6b9SJerome Glisse 1150771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) { 11514ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT)) 1152771fe6b9SJerome Glisse atombios_yuv_setup(encoder, true); 1153771fe6b9SJerome Glisse else 1154771fe6b9SJerome Glisse atombios_yuv_setup(encoder, false); 1155771fe6b9SJerome Glisse } 1156771fe6b9SJerome Glisse 1157771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 1158771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 1159771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 1160771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 1161771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 1162771fe6b9SJerome Glisse atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE); 1163771fe6b9SJerome Glisse break; 1164771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1165771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1166771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1167771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 1168771fe6b9SJerome Glisse /* disable the encoder and transmitter */ 1169771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE); 1170771fe6b9SJerome Glisse atombios_dig_encoder_setup(encoder, ATOM_DISABLE); 1171771fe6b9SJerome Glisse 1172771fe6b9SJerome Glisse /* setup and enable the encoder and transmitter */ 1173771fe6b9SJerome Glisse atombios_dig_encoder_setup(encoder, ATOM_ENABLE); 1174f95a9f0bSAlex Deucher atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT); 1175771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP); 1176771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE); 1177771fe6b9SJerome Glisse break; 1178771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DDI: 1179771fe6b9SJerome Glisse atombios_ddia_setup(encoder, ATOM_ENABLE); 1180771fe6b9SJerome Glisse break; 1181771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1182771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1183771fe6b9SJerome Glisse atombios_external_tmds_setup(encoder, ATOM_ENABLE); 1184771fe6b9SJerome Glisse break; 1185771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1186771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 1187771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 1188771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 1189771fe6b9SJerome Glisse atombios_dac_setup(encoder, ATOM_ENABLE); 11904ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) 1191771fe6b9SJerome Glisse atombios_tv_setup(encoder, ATOM_ENABLE); 1192771fe6b9SJerome Glisse break; 1193771fe6b9SJerome Glisse } 1194771fe6b9SJerome Glisse atombios_apply_encoder_quirks(encoder, adjusted_mode); 1195771fe6b9SJerome Glisse } 1196771fe6b9SJerome Glisse 1197771fe6b9SJerome Glisse static bool 11984ce001abSDave Airlie atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector) 1199771fe6b9SJerome Glisse { 1200771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 1201771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 1202771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 12034ce001abSDave Airlie struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1204771fe6b9SJerome Glisse 1205771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | 1206771fe6b9SJerome Glisse ATOM_DEVICE_CV_SUPPORT | 1207771fe6b9SJerome Glisse ATOM_DEVICE_CRT_SUPPORT)) { 1208771fe6b9SJerome Glisse DAC_LOAD_DETECTION_PS_ALLOCATION args; 1209771fe6b9SJerome Glisse int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection); 1210771fe6b9SJerome Glisse uint8_t frev, crev; 1211771fe6b9SJerome Glisse 1212771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 1213771fe6b9SJerome Glisse 1214771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 1215771fe6b9SJerome Glisse 1216771fe6b9SJerome Glisse args.sDacload.ucMisc = 0; 1217771fe6b9SJerome Glisse 1218771fe6b9SJerome Glisse if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) || 1219771fe6b9SJerome Glisse (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1)) 1220771fe6b9SJerome Glisse args.sDacload.ucDacType = ATOM_DAC_A; 1221771fe6b9SJerome Glisse else 1222771fe6b9SJerome Glisse args.sDacload.ucDacType = ATOM_DAC_B; 1223771fe6b9SJerome Glisse 12244ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) 1225771fe6b9SJerome Glisse args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT); 12264ce001abSDave Airlie else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) 1227771fe6b9SJerome Glisse args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT); 12284ce001abSDave Airlie else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { 1229771fe6b9SJerome Glisse args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT); 1230771fe6b9SJerome Glisse if (crev >= 3) 1231771fe6b9SJerome Glisse args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb; 12324ce001abSDave Airlie } else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { 1233771fe6b9SJerome Glisse args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT); 1234771fe6b9SJerome Glisse if (crev >= 3) 1235771fe6b9SJerome Glisse args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb; 1236771fe6b9SJerome Glisse } 1237771fe6b9SJerome Glisse 1238771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 1239771fe6b9SJerome Glisse 1240771fe6b9SJerome Glisse return true; 1241771fe6b9SJerome Glisse } else 1242771fe6b9SJerome Glisse return false; 1243771fe6b9SJerome Glisse } 1244771fe6b9SJerome Glisse 1245771fe6b9SJerome Glisse static enum drm_connector_status 1246771fe6b9SJerome Glisse radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) 1247771fe6b9SJerome Glisse { 1248771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 1249771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 1250771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 12514ce001abSDave Airlie struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1252771fe6b9SJerome Glisse uint32_t bios_0_scratch; 1253771fe6b9SJerome Glisse 12544ce001abSDave Airlie if (!atombios_dac_load_detect(encoder, connector)) { 1255771fe6b9SJerome Glisse DRM_DEBUG("detect returned false \n"); 1256771fe6b9SJerome Glisse return connector_status_unknown; 1257771fe6b9SJerome Glisse } 1258771fe6b9SJerome Glisse 1259771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) 1260771fe6b9SJerome Glisse bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH); 1261771fe6b9SJerome Glisse else 1262771fe6b9SJerome Glisse bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH); 1263771fe6b9SJerome Glisse 12644ce001abSDave Airlie DRM_DEBUG("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices); 12654ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) { 1266771fe6b9SJerome Glisse if (bios_0_scratch & ATOM_S0_CRT1_MASK) 1267771fe6b9SJerome Glisse return connector_status_connected; 12684ce001abSDave Airlie } 12694ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) { 1270771fe6b9SJerome Glisse if (bios_0_scratch & ATOM_S0_CRT2_MASK) 1271771fe6b9SJerome Glisse return connector_status_connected; 12724ce001abSDave Airlie } 12734ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { 1274771fe6b9SJerome Glisse if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A)) 1275771fe6b9SJerome Glisse return connector_status_connected; 12764ce001abSDave Airlie } 12774ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { 1278771fe6b9SJerome Glisse if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A)) 1279771fe6b9SJerome Glisse return connector_status_connected; /* CTV */ 1280771fe6b9SJerome Glisse else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A)) 1281771fe6b9SJerome Glisse return connector_status_connected; /* STV */ 1282771fe6b9SJerome Glisse } 1283771fe6b9SJerome Glisse return connector_status_disconnected; 1284771fe6b9SJerome Glisse } 1285771fe6b9SJerome Glisse 1286771fe6b9SJerome Glisse static void radeon_atom_encoder_prepare(struct drm_encoder *encoder) 1287771fe6b9SJerome Glisse { 1288771fe6b9SJerome Glisse radeon_atom_output_lock(encoder, true); 1289771fe6b9SJerome Glisse radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 1290771fe6b9SJerome Glisse } 1291771fe6b9SJerome Glisse 1292771fe6b9SJerome Glisse static void radeon_atom_encoder_commit(struct drm_encoder *encoder) 1293771fe6b9SJerome Glisse { 1294771fe6b9SJerome Glisse radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON); 1295771fe6b9SJerome Glisse radeon_atom_output_lock(encoder, false); 1296771fe6b9SJerome Glisse } 1297771fe6b9SJerome Glisse 12984ce001abSDave Airlie static void radeon_atom_encoder_disable(struct drm_encoder *encoder) 12994ce001abSDave Airlie { 13004ce001abSDave Airlie struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 13014ce001abSDave Airlie radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 13024ce001abSDave Airlie radeon_encoder->active_device = 0; 13034ce001abSDave Airlie } 13044ce001abSDave Airlie 1305771fe6b9SJerome Glisse static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = { 1306771fe6b9SJerome Glisse .dpms = radeon_atom_encoder_dpms, 1307771fe6b9SJerome Glisse .mode_fixup = radeon_atom_mode_fixup, 1308771fe6b9SJerome Glisse .prepare = radeon_atom_encoder_prepare, 1309771fe6b9SJerome Glisse .mode_set = radeon_atom_encoder_mode_set, 1310771fe6b9SJerome Glisse .commit = radeon_atom_encoder_commit, 13114ce001abSDave Airlie .disable = radeon_atom_encoder_disable, 1312771fe6b9SJerome Glisse /* no detect for TMDS/LVDS yet */ 1313771fe6b9SJerome Glisse }; 1314771fe6b9SJerome Glisse 1315771fe6b9SJerome Glisse static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = { 1316771fe6b9SJerome Glisse .dpms = radeon_atom_encoder_dpms, 1317771fe6b9SJerome Glisse .mode_fixup = radeon_atom_mode_fixup, 1318771fe6b9SJerome Glisse .prepare = radeon_atom_encoder_prepare, 1319771fe6b9SJerome Glisse .mode_set = radeon_atom_encoder_mode_set, 1320771fe6b9SJerome Glisse .commit = radeon_atom_encoder_commit, 1321771fe6b9SJerome Glisse .detect = radeon_atom_dac_detect, 1322771fe6b9SJerome Glisse }; 1323771fe6b9SJerome Glisse 1324771fe6b9SJerome Glisse void radeon_enc_destroy(struct drm_encoder *encoder) 1325771fe6b9SJerome Glisse { 1326771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1327771fe6b9SJerome Glisse kfree(radeon_encoder->enc_priv); 1328771fe6b9SJerome Glisse drm_encoder_cleanup(encoder); 1329771fe6b9SJerome Glisse kfree(radeon_encoder); 1330771fe6b9SJerome Glisse } 1331771fe6b9SJerome Glisse 1332771fe6b9SJerome Glisse static const struct drm_encoder_funcs radeon_atom_enc_funcs = { 1333771fe6b9SJerome Glisse .destroy = radeon_enc_destroy, 1334771fe6b9SJerome Glisse }; 1335771fe6b9SJerome Glisse 13364ce001abSDave Airlie struct radeon_encoder_atom_dac * 13374ce001abSDave Airlie radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder) 13384ce001abSDave Airlie { 13394ce001abSDave Airlie struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL); 13404ce001abSDave Airlie 13414ce001abSDave Airlie if (!dac) 13424ce001abSDave Airlie return NULL; 13434ce001abSDave Airlie 13444ce001abSDave Airlie dac->tv_std = TV_STD_NTSC; 13454ce001abSDave Airlie return dac; 13464ce001abSDave Airlie } 13474ce001abSDave Airlie 1348771fe6b9SJerome Glisse struct radeon_encoder_atom_dig * 1349771fe6b9SJerome Glisse radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder) 1350771fe6b9SJerome Glisse { 1351771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL); 1352771fe6b9SJerome Glisse 1353771fe6b9SJerome Glisse if (!dig) 1354771fe6b9SJerome Glisse return NULL; 1355771fe6b9SJerome Glisse 1356771fe6b9SJerome Glisse /* coherent mode by default */ 1357771fe6b9SJerome Glisse dig->coherent_mode = true; 1358771fe6b9SJerome Glisse 1359771fe6b9SJerome Glisse return dig; 1360771fe6b9SJerome Glisse } 1361771fe6b9SJerome Glisse 1362771fe6b9SJerome Glisse void 1363771fe6b9SJerome Glisse radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t supported_device) 1364771fe6b9SJerome Glisse { 1365dfee5614SDave Airlie struct radeon_device *rdev = dev->dev_private; 1366771fe6b9SJerome Glisse struct drm_encoder *encoder; 1367771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder; 1368771fe6b9SJerome Glisse 1369771fe6b9SJerome Glisse /* see if we already added it */ 1370771fe6b9SJerome Glisse list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 1371771fe6b9SJerome Glisse radeon_encoder = to_radeon_encoder(encoder); 1372771fe6b9SJerome Glisse if (radeon_encoder->encoder_id == encoder_id) { 1373771fe6b9SJerome Glisse radeon_encoder->devices |= supported_device; 1374771fe6b9SJerome Glisse return; 1375771fe6b9SJerome Glisse } 1376771fe6b9SJerome Glisse 1377771fe6b9SJerome Glisse } 1378771fe6b9SJerome Glisse 1379771fe6b9SJerome Glisse /* add a new one */ 1380771fe6b9SJerome Glisse radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL); 1381771fe6b9SJerome Glisse if (!radeon_encoder) 1382771fe6b9SJerome Glisse return; 1383771fe6b9SJerome Glisse 1384771fe6b9SJerome Glisse encoder = &radeon_encoder->base; 1385dfee5614SDave Airlie if (rdev->flags & RADEON_SINGLE_CRTC) 1386dfee5614SDave Airlie encoder->possible_crtcs = 0x1; 1387dfee5614SDave Airlie else 1388771fe6b9SJerome Glisse encoder->possible_crtcs = 0x3; 1389771fe6b9SJerome Glisse 1390771fe6b9SJerome Glisse radeon_encoder->enc_priv = NULL; 1391771fe6b9SJerome Glisse 1392771fe6b9SJerome Glisse radeon_encoder->encoder_id = encoder_id; 1393771fe6b9SJerome Glisse radeon_encoder->devices = supported_device; 1394c93bb85bSJerome Glisse radeon_encoder->rmx_type = RMX_OFF; 1395771fe6b9SJerome Glisse 1396771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 1397771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 1398771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 1399771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 1400771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 1401771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 1402771fe6b9SJerome Glisse radeon_encoder->rmx_type = RMX_FULL; 1403771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS); 1404771fe6b9SJerome Glisse radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); 1405771fe6b9SJerome Glisse } else { 1406771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS); 1407771fe6b9SJerome Glisse radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); 1408771fe6b9SJerome Glisse } 1409771fe6b9SJerome Glisse drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); 1410771fe6b9SJerome Glisse break; 1411771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1412771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC); 1413771fe6b9SJerome Glisse drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs); 1414771fe6b9SJerome Glisse break; 1415771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 1416771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 1417771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 1418771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TVDAC); 14194ce001abSDave Airlie radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder); 1420771fe6b9SJerome Glisse drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs); 1421771fe6b9SJerome Glisse break; 1422771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1423771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1424771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DDI: 1425771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1426771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 1427771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1428771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 142960d15f55SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 143060d15f55SAlex Deucher radeon_encoder->rmx_type = RMX_FULL; 143160d15f55SAlex Deucher drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS); 143260d15f55SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); 143360d15f55SAlex Deucher } else { 1434771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS); 1435771fe6b9SJerome Glisse radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); 143660d15f55SAlex Deucher } 1437771fe6b9SJerome Glisse drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); 1438771fe6b9SJerome Glisse break; 1439771fe6b9SJerome Glisse } 1440771fe6b9SJerome Glisse } 1441