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 34771fe6b9SJerome Glisse uint32_t 35771fe6b9SJerome Glisse radeon_get_encoder_id(struct drm_device *dev, uint32_t supported_device, uint8_t dac) 36771fe6b9SJerome Glisse { 37771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 38771fe6b9SJerome Glisse uint32_t ret = 0; 39771fe6b9SJerome Glisse 40771fe6b9SJerome Glisse switch (supported_device) { 41771fe6b9SJerome Glisse case ATOM_DEVICE_CRT1_SUPPORT: 42771fe6b9SJerome Glisse case ATOM_DEVICE_TV1_SUPPORT: 43771fe6b9SJerome Glisse case ATOM_DEVICE_TV2_SUPPORT: 44771fe6b9SJerome Glisse case ATOM_DEVICE_CRT2_SUPPORT: 45771fe6b9SJerome Glisse case ATOM_DEVICE_CV_SUPPORT: 46771fe6b9SJerome Glisse switch (dac) { 47771fe6b9SJerome Glisse case 1: /* dac a */ 48771fe6b9SJerome Glisse if ((rdev->family == CHIP_RS300) || 49771fe6b9SJerome Glisse (rdev->family == CHIP_RS400) || 50771fe6b9SJerome Glisse (rdev->family == CHIP_RS480)) 51771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DAC2; 52771fe6b9SJerome Glisse else if (ASIC_IS_AVIVO(rdev)) 53771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1; 54771fe6b9SJerome Glisse else 55771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DAC1; 56771fe6b9SJerome Glisse break; 57771fe6b9SJerome Glisse case 2: /* dac b */ 58771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 59771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2; 60771fe6b9SJerome Glisse else { 61771fe6b9SJerome Glisse /*if (rdev->family == CHIP_R200) 62771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; 63771fe6b9SJerome Glisse else*/ 64771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DAC2; 65771fe6b9SJerome Glisse } 66771fe6b9SJerome Glisse break; 67771fe6b9SJerome Glisse case 3: /* external dac */ 68771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 69771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1; 70771fe6b9SJerome Glisse else 71771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; 72771fe6b9SJerome Glisse break; 73771fe6b9SJerome Glisse } 74771fe6b9SJerome Glisse break; 75771fe6b9SJerome Glisse case ATOM_DEVICE_LCD1_SUPPORT: 76771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 77771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_LVTM1; 78771fe6b9SJerome Glisse else 79771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_LVDS; 80771fe6b9SJerome Glisse break; 81771fe6b9SJerome Glisse case ATOM_DEVICE_DFP1_SUPPORT: 82771fe6b9SJerome Glisse if ((rdev->family == CHIP_RS300) || 83771fe6b9SJerome Glisse (rdev->family == CHIP_RS400) || 84771fe6b9SJerome Glisse (rdev->family == CHIP_RS480)) 85771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; 86771fe6b9SJerome Glisse else if (ASIC_IS_AVIVO(rdev)) 87771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1; 88771fe6b9SJerome Glisse else 89771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_TMDS1; 90771fe6b9SJerome Glisse break; 91771fe6b9SJerome Glisse case ATOM_DEVICE_LCD2_SUPPORT: 92771fe6b9SJerome Glisse case ATOM_DEVICE_DFP2_SUPPORT: 93771fe6b9SJerome Glisse if ((rdev->family == CHIP_RS600) || 94771fe6b9SJerome Glisse (rdev->family == CHIP_RS690) || 95771fe6b9SJerome Glisse (rdev->family == CHIP_RS740)) 96771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DDI; 97771fe6b9SJerome Glisse else if (ASIC_IS_AVIVO(rdev)) 98771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1; 99771fe6b9SJerome Glisse else 100771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; 101771fe6b9SJerome Glisse break; 102771fe6b9SJerome Glisse case ATOM_DEVICE_DFP3_SUPPORT: 103771fe6b9SJerome Glisse ret = ENCODER_OBJECT_ID_INTERNAL_LVTM1; 104771fe6b9SJerome Glisse break; 105771fe6b9SJerome Glisse } 106771fe6b9SJerome Glisse 107771fe6b9SJerome Glisse return ret; 108771fe6b9SJerome Glisse } 109771fe6b9SJerome Glisse 110771fe6b9SJerome Glisse void 111771fe6b9SJerome Glisse radeon_link_encoder_connector(struct drm_device *dev) 112771fe6b9SJerome Glisse { 113771fe6b9SJerome Glisse struct drm_connector *connector; 114771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 115771fe6b9SJerome Glisse struct drm_encoder *encoder; 116771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder; 117771fe6b9SJerome Glisse 118771fe6b9SJerome Glisse /* walk the list and link encoders to connectors */ 119771fe6b9SJerome Glisse list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 120771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 121771fe6b9SJerome Glisse list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 122771fe6b9SJerome Glisse radeon_encoder = to_radeon_encoder(encoder); 123771fe6b9SJerome Glisse if (radeon_encoder->devices & radeon_connector->devices) 124771fe6b9SJerome Glisse drm_mode_connector_attach_encoder(connector, encoder); 125771fe6b9SJerome Glisse } 126771fe6b9SJerome Glisse } 127771fe6b9SJerome Glisse } 128771fe6b9SJerome Glisse 1294ce001abSDave Airlie void radeon_encoder_set_active_device(struct drm_encoder *encoder) 1304ce001abSDave Airlie { 1314ce001abSDave Airlie struct drm_device *dev = encoder->dev; 1324ce001abSDave Airlie struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1334ce001abSDave Airlie struct drm_connector *connector; 1344ce001abSDave Airlie 1354ce001abSDave Airlie list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 1364ce001abSDave Airlie if (connector->encoder == encoder) { 1374ce001abSDave Airlie struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1384ce001abSDave Airlie radeon_encoder->active_device = radeon_encoder->devices & radeon_connector->devices; 139f641e51eSDave Airlie DRM_DEBUG("setting active device to %08x from %08x %08x for encoder %d\n", 1404ce001abSDave Airlie radeon_encoder->active_device, radeon_encoder->devices, 1414ce001abSDave Airlie radeon_connector->devices, encoder->encoder_type); 1424ce001abSDave Airlie } 1434ce001abSDave Airlie } 1444ce001abSDave Airlie } 1454ce001abSDave Airlie 146771fe6b9SJerome Glisse static struct drm_connector * 147771fe6b9SJerome Glisse radeon_get_connector_for_encoder(struct drm_encoder *encoder) 148771fe6b9SJerome Glisse { 149771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 150771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 151771fe6b9SJerome Glisse struct drm_connector *connector; 152771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 153771fe6b9SJerome Glisse 154771fe6b9SJerome Glisse list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 155771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 156771fe6b9SJerome Glisse if (radeon_encoder->devices & radeon_connector->devices) 157771fe6b9SJerome Glisse return connector; 158771fe6b9SJerome Glisse } 159771fe6b9SJerome Glisse return NULL; 160771fe6b9SJerome Glisse } 161771fe6b9SJerome Glisse 162771fe6b9SJerome Glisse /* used for both atom and legacy */ 163771fe6b9SJerome Glisse void radeon_rmx_mode_fixup(struct drm_encoder *encoder, 164771fe6b9SJerome Glisse struct drm_display_mode *mode, 165771fe6b9SJerome Glisse struct drm_display_mode *adjusted_mode) 166771fe6b9SJerome Glisse { 167771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 168771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 169771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 170771fe6b9SJerome Glisse struct radeon_native_mode *native_mode = &radeon_encoder->native_mode; 171771fe6b9SJerome Glisse 172771fe6b9SJerome Glisse if (mode->hdisplay < native_mode->panel_xres || 173771fe6b9SJerome Glisse mode->vdisplay < native_mode->panel_yres) { 174771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) { 175771fe6b9SJerome Glisse adjusted_mode->hdisplay = native_mode->panel_xres; 176771fe6b9SJerome Glisse adjusted_mode->vdisplay = native_mode->panel_yres; 177771fe6b9SJerome Glisse adjusted_mode->htotal = native_mode->panel_xres + native_mode->hblank; 178771fe6b9SJerome Glisse adjusted_mode->hsync_start = native_mode->panel_xres + native_mode->hoverplus; 179771fe6b9SJerome Glisse adjusted_mode->hsync_end = adjusted_mode->hsync_start + native_mode->hsync_width; 180771fe6b9SJerome Glisse adjusted_mode->vtotal = native_mode->panel_yres + native_mode->vblank; 181771fe6b9SJerome Glisse adjusted_mode->vsync_start = native_mode->panel_yres + native_mode->voverplus; 182771fe6b9SJerome Glisse adjusted_mode->vsync_end = adjusted_mode->vsync_start + native_mode->vsync_width; 183771fe6b9SJerome Glisse /* update crtc values */ 184771fe6b9SJerome Glisse drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V); 185771fe6b9SJerome Glisse /* adjust crtc values */ 186771fe6b9SJerome Glisse adjusted_mode->crtc_hdisplay = native_mode->panel_xres; 187771fe6b9SJerome Glisse adjusted_mode->crtc_vdisplay = native_mode->panel_yres; 188771fe6b9SJerome Glisse adjusted_mode->crtc_htotal = adjusted_mode->crtc_hdisplay + native_mode->hblank; 189771fe6b9SJerome Glisse adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hdisplay + native_mode->hoverplus; 190771fe6b9SJerome Glisse adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + native_mode->hsync_width; 191771fe6b9SJerome Glisse adjusted_mode->crtc_vtotal = adjusted_mode->crtc_vdisplay + native_mode->vblank; 192771fe6b9SJerome Glisse adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + native_mode->voverplus; 193771fe6b9SJerome Glisse adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + native_mode->vsync_width; 194771fe6b9SJerome Glisse } else { 195771fe6b9SJerome Glisse adjusted_mode->htotal = native_mode->panel_xres + native_mode->hblank; 196771fe6b9SJerome Glisse adjusted_mode->hsync_start = native_mode->panel_xres + native_mode->hoverplus; 197771fe6b9SJerome Glisse adjusted_mode->hsync_end = adjusted_mode->hsync_start + native_mode->hsync_width; 198771fe6b9SJerome Glisse adjusted_mode->vtotal = native_mode->panel_yres + native_mode->vblank; 199771fe6b9SJerome Glisse adjusted_mode->vsync_start = native_mode->panel_yres + native_mode->voverplus; 200771fe6b9SJerome Glisse adjusted_mode->vsync_end = adjusted_mode->vsync_start + native_mode->vsync_width; 201771fe6b9SJerome Glisse /* update crtc values */ 202771fe6b9SJerome Glisse drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V); 203771fe6b9SJerome Glisse /* adjust crtc values */ 204771fe6b9SJerome Glisse adjusted_mode->crtc_htotal = adjusted_mode->crtc_hdisplay + native_mode->hblank; 205771fe6b9SJerome Glisse adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hdisplay + native_mode->hoverplus; 206771fe6b9SJerome Glisse adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + native_mode->hsync_width; 207771fe6b9SJerome Glisse adjusted_mode->crtc_vtotal = adjusted_mode->crtc_vdisplay + native_mode->vblank; 208771fe6b9SJerome Glisse adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + native_mode->voverplus; 209771fe6b9SJerome Glisse adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + native_mode->vsync_width; 210771fe6b9SJerome Glisse } 211771fe6b9SJerome Glisse adjusted_mode->flags = native_mode->flags; 212771fe6b9SJerome Glisse adjusted_mode->clock = native_mode->dotclock; 213771fe6b9SJerome Glisse } 214771fe6b9SJerome Glisse } 215771fe6b9SJerome Glisse 216c93bb85bSJerome Glisse 217771fe6b9SJerome Glisse static bool radeon_atom_mode_fixup(struct drm_encoder *encoder, 218771fe6b9SJerome Glisse struct drm_display_mode *mode, 219771fe6b9SJerome Glisse struct drm_display_mode *adjusted_mode) 220771fe6b9SJerome Glisse { 221771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 222771fe6b9SJerome Glisse 223771fe6b9SJerome Glisse drm_mode_set_crtcinfo(adjusted_mode, 0); 224771fe6b9SJerome Glisse 225771fe6b9SJerome Glisse if (radeon_encoder->rmx_type != RMX_OFF) 226771fe6b9SJerome Glisse radeon_rmx_mode_fixup(encoder, mode, adjusted_mode); 227771fe6b9SJerome Glisse 228771fe6b9SJerome Glisse /* hw bug */ 229771fe6b9SJerome Glisse if ((mode->flags & DRM_MODE_FLAG_INTERLACE) 230771fe6b9SJerome Glisse && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2))) 231771fe6b9SJerome Glisse adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2; 232771fe6b9SJerome Glisse 233771fe6b9SJerome Glisse return true; 234771fe6b9SJerome Glisse } 235771fe6b9SJerome Glisse 236771fe6b9SJerome Glisse static void 237771fe6b9SJerome Glisse atombios_dac_setup(struct drm_encoder *encoder, int action) 238771fe6b9SJerome Glisse { 239771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 240771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 241771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 242771fe6b9SJerome Glisse DAC_ENCODER_CONTROL_PS_ALLOCATION args; 243771fe6b9SJerome Glisse int index = 0, num = 0; 244771fe6b9SJerome Glisse /* fixme - fill in enc_priv for atom dac */ 245771fe6b9SJerome Glisse enum radeon_tv_std tv_std = TV_STD_NTSC; 246771fe6b9SJerome Glisse 247771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 248771fe6b9SJerome Glisse 249771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 250771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 251771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 252771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl); 253771fe6b9SJerome Glisse num = 1; 254771fe6b9SJerome Glisse break; 255771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 256771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 257771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl); 258771fe6b9SJerome Glisse num = 2; 259771fe6b9SJerome Glisse break; 260771fe6b9SJerome Glisse } 261771fe6b9SJerome Glisse 262771fe6b9SJerome Glisse args.ucAction = action; 263771fe6b9SJerome Glisse 2644ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT)) 265771fe6b9SJerome Glisse args.ucDacStandard = ATOM_DAC1_PS2; 2664ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 267771fe6b9SJerome Glisse args.ucDacStandard = ATOM_DAC1_CV; 268771fe6b9SJerome Glisse else { 269771fe6b9SJerome Glisse switch (tv_std) { 270771fe6b9SJerome Glisse case TV_STD_PAL: 271771fe6b9SJerome Glisse case TV_STD_PAL_M: 272771fe6b9SJerome Glisse case TV_STD_SCART_PAL: 273771fe6b9SJerome Glisse case TV_STD_SECAM: 274771fe6b9SJerome Glisse case TV_STD_PAL_CN: 275771fe6b9SJerome Glisse args.ucDacStandard = ATOM_DAC1_PAL; 276771fe6b9SJerome Glisse break; 277771fe6b9SJerome Glisse case TV_STD_NTSC: 278771fe6b9SJerome Glisse case TV_STD_NTSC_J: 279771fe6b9SJerome Glisse case TV_STD_PAL_60: 280771fe6b9SJerome Glisse default: 281771fe6b9SJerome Glisse args.ucDacStandard = ATOM_DAC1_NTSC; 282771fe6b9SJerome Glisse break; 283771fe6b9SJerome Glisse } 284771fe6b9SJerome Glisse } 285771fe6b9SJerome Glisse args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 286771fe6b9SJerome Glisse 287771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 288771fe6b9SJerome Glisse 289771fe6b9SJerome Glisse } 290771fe6b9SJerome Glisse 291771fe6b9SJerome Glisse static void 292771fe6b9SJerome Glisse atombios_tv_setup(struct drm_encoder *encoder, int action) 293771fe6b9SJerome Glisse { 294771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 295771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 296771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 297771fe6b9SJerome Glisse TV_ENCODER_CONTROL_PS_ALLOCATION args; 298771fe6b9SJerome Glisse int index = 0; 299771fe6b9SJerome Glisse /* fixme - fill in enc_priv for atom dac */ 300771fe6b9SJerome Glisse enum radeon_tv_std tv_std = TV_STD_NTSC; 301771fe6b9SJerome Glisse 302771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 303771fe6b9SJerome Glisse 304771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl); 305771fe6b9SJerome Glisse 306771fe6b9SJerome Glisse args.sTVEncoder.ucAction = action; 307771fe6b9SJerome Glisse 3084ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 309771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_CV; 310771fe6b9SJerome Glisse else { 311771fe6b9SJerome Glisse switch (tv_std) { 312771fe6b9SJerome Glisse case TV_STD_NTSC: 313771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC; 314771fe6b9SJerome Glisse break; 315771fe6b9SJerome Glisse case TV_STD_PAL: 316771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; 317771fe6b9SJerome Glisse break; 318771fe6b9SJerome Glisse case TV_STD_PAL_M: 319771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PALM; 320771fe6b9SJerome Glisse break; 321771fe6b9SJerome Glisse case TV_STD_PAL_60: 322771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60; 323771fe6b9SJerome Glisse break; 324771fe6b9SJerome Glisse case TV_STD_NTSC_J: 325771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ; 326771fe6b9SJerome Glisse break; 327771fe6b9SJerome Glisse case TV_STD_SCART_PAL: 328771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */ 329771fe6b9SJerome Glisse break; 330771fe6b9SJerome Glisse case TV_STD_SECAM: 331771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM; 332771fe6b9SJerome Glisse break; 333771fe6b9SJerome Glisse case TV_STD_PAL_CN: 334771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN; 335771fe6b9SJerome Glisse break; 336771fe6b9SJerome Glisse default: 337771fe6b9SJerome Glisse args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC; 338771fe6b9SJerome Glisse break; 339771fe6b9SJerome Glisse } 340771fe6b9SJerome Glisse } 341771fe6b9SJerome Glisse 342771fe6b9SJerome Glisse args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 343771fe6b9SJerome Glisse 344771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 345771fe6b9SJerome Glisse 346771fe6b9SJerome Glisse } 347771fe6b9SJerome Glisse 348771fe6b9SJerome Glisse void 349771fe6b9SJerome Glisse atombios_external_tmds_setup(struct drm_encoder *encoder, int action) 350771fe6b9SJerome Glisse { 351771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 352771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 353771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 354771fe6b9SJerome Glisse ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION args; 355771fe6b9SJerome Glisse int index = 0; 356771fe6b9SJerome Glisse 357771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 358771fe6b9SJerome Glisse 359771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl); 360771fe6b9SJerome Glisse 361771fe6b9SJerome Glisse args.sXTmdsEncoder.ucEnable = action; 362771fe6b9SJerome Glisse 363771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 364771fe6b9SJerome Glisse args.sXTmdsEncoder.ucMisc = PANEL_ENCODER_MISC_DUAL; 365771fe6b9SJerome Glisse 366771fe6b9SJerome Glisse /*if (pScrn->rgbBits == 8)*/ 367771fe6b9SJerome Glisse args.sXTmdsEncoder.ucMisc |= (1 << 1); 368771fe6b9SJerome Glisse 369771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 370771fe6b9SJerome Glisse 371771fe6b9SJerome Glisse } 372771fe6b9SJerome Glisse 373771fe6b9SJerome Glisse static void 374771fe6b9SJerome Glisse atombios_ddia_setup(struct drm_encoder *encoder, int action) 375771fe6b9SJerome Glisse { 376771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 377771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 378771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 379771fe6b9SJerome Glisse DVO_ENCODER_CONTROL_PS_ALLOCATION args; 380771fe6b9SJerome Glisse int index = 0; 381771fe6b9SJerome Glisse 382771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 383771fe6b9SJerome Glisse 384771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl); 385771fe6b9SJerome Glisse 386771fe6b9SJerome Glisse args.sDVOEncoder.ucAction = action; 387771fe6b9SJerome Glisse args.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 388771fe6b9SJerome Glisse 389771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 390771fe6b9SJerome Glisse args.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute = PANEL_ENCODER_MISC_DUAL; 391771fe6b9SJerome Glisse 392771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 393771fe6b9SJerome Glisse 394771fe6b9SJerome Glisse } 395771fe6b9SJerome Glisse 396771fe6b9SJerome Glisse union lvds_encoder_control { 397771fe6b9SJerome Glisse LVDS_ENCODER_CONTROL_PS_ALLOCATION v1; 398771fe6b9SJerome Glisse LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2; 399771fe6b9SJerome Glisse }; 400771fe6b9SJerome Glisse 401771fe6b9SJerome Glisse static void 402771fe6b9SJerome Glisse atombios_digital_setup(struct drm_encoder *encoder, int action) 403771fe6b9SJerome Glisse { 404771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 405771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 406771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 407771fe6b9SJerome Glisse union lvds_encoder_control args; 408771fe6b9SJerome Glisse int index = 0; 409771fe6b9SJerome Glisse uint8_t frev, crev; 410771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig; 411771fe6b9SJerome Glisse struct drm_connector *connector; 412771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 413771fe6b9SJerome Glisse struct radeon_connector_atom_dig *dig_connector; 414771fe6b9SJerome Glisse 415771fe6b9SJerome Glisse connector = radeon_get_connector_for_encoder(encoder); 416771fe6b9SJerome Glisse if (!connector) 417771fe6b9SJerome Glisse return; 418771fe6b9SJerome Glisse 419771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 420771fe6b9SJerome Glisse 421771fe6b9SJerome Glisse if (!radeon_encoder->enc_priv) 422771fe6b9SJerome Glisse return; 423771fe6b9SJerome Glisse 424771fe6b9SJerome Glisse dig = radeon_encoder->enc_priv; 425771fe6b9SJerome Glisse 426771fe6b9SJerome Glisse if (!radeon_connector->con_priv) 427771fe6b9SJerome Glisse return; 428771fe6b9SJerome Glisse 429771fe6b9SJerome Glisse dig_connector = radeon_connector->con_priv; 430771fe6b9SJerome Glisse 431771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 432771fe6b9SJerome Glisse 433771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 434771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 435771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl); 436771fe6b9SJerome Glisse break; 437771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 438771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 439771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl); 440771fe6b9SJerome Glisse break; 441771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 442771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 443771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl); 444771fe6b9SJerome Glisse else 445771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl); 446771fe6b9SJerome Glisse break; 447771fe6b9SJerome Glisse } 448771fe6b9SJerome Glisse 449771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 450771fe6b9SJerome Glisse 451771fe6b9SJerome Glisse switch (frev) { 452771fe6b9SJerome Glisse case 1: 453771fe6b9SJerome Glisse case 2: 454771fe6b9SJerome Glisse switch (crev) { 455771fe6b9SJerome Glisse case 1: 456771fe6b9SJerome Glisse args.v1.ucMisc = 0; 457771fe6b9SJerome Glisse args.v1.ucAction = action; 458771fe6b9SJerome Glisse if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr)) 459771fe6b9SJerome Glisse args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE; 460771fe6b9SJerome Glisse args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 461771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 462771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 0)) 463771fe6b9SJerome Glisse args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; 464771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 1)) 465771fe6b9SJerome Glisse args.v1.ucMisc |= (1 << 1); 466771fe6b9SJerome Glisse } else { 467771fe6b9SJerome Glisse if (dig_connector->linkb) 468771fe6b9SJerome Glisse args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; 469771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 470771fe6b9SJerome Glisse args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; 471771fe6b9SJerome Glisse /*if (pScrn->rgbBits == 8) */ 472771fe6b9SJerome Glisse args.v1.ucMisc |= (1 << 1); 473771fe6b9SJerome Glisse } 474771fe6b9SJerome Glisse break; 475771fe6b9SJerome Glisse case 2: 476771fe6b9SJerome Glisse case 3: 477771fe6b9SJerome Glisse args.v2.ucMisc = 0; 478771fe6b9SJerome Glisse args.v2.ucAction = action; 479771fe6b9SJerome Glisse if (crev == 3) { 480771fe6b9SJerome Glisse if (dig->coherent_mode) 481771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT; 482771fe6b9SJerome Glisse } 483771fe6b9SJerome Glisse if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr)) 484771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE; 485771fe6b9SJerome Glisse args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 486771fe6b9SJerome Glisse args.v2.ucTruncate = 0; 487771fe6b9SJerome Glisse args.v2.ucSpatial = 0; 488771fe6b9SJerome Glisse args.v2.ucTemporal = 0; 489771fe6b9SJerome Glisse args.v2.ucFRC = 0; 490771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 491771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 0)) 492771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL; 493771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 5)) { 494771fe6b9SJerome Glisse args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN; 495771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 1)) 496771fe6b9SJerome Glisse args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH; 497771fe6b9SJerome Glisse } 498771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 6)) { 499771fe6b9SJerome Glisse args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN; 500771fe6b9SJerome Glisse if (dig->lvds_misc & (1 << 1)) 501771fe6b9SJerome Glisse args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH; 502771fe6b9SJerome Glisse if (((dig->lvds_misc >> 2) & 0x3) == 2) 503771fe6b9SJerome Glisse args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4; 504771fe6b9SJerome Glisse } 505771fe6b9SJerome Glisse } else { 506771fe6b9SJerome Glisse if (dig_connector->linkb) 507771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; 508771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 509771fe6b9SJerome Glisse args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL; 510771fe6b9SJerome Glisse } 511771fe6b9SJerome Glisse break; 512771fe6b9SJerome Glisse default: 513771fe6b9SJerome Glisse DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 514771fe6b9SJerome Glisse break; 515771fe6b9SJerome Glisse } 516771fe6b9SJerome Glisse break; 517771fe6b9SJerome Glisse default: 518771fe6b9SJerome Glisse DRM_ERROR("Unknown table version %d, %d\n", frev, crev); 519771fe6b9SJerome Glisse break; 520771fe6b9SJerome Glisse } 521771fe6b9SJerome Glisse 522771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 523771fe6b9SJerome Glisse 524771fe6b9SJerome Glisse } 525771fe6b9SJerome Glisse 526771fe6b9SJerome Glisse int 527771fe6b9SJerome Glisse atombios_get_encoder_mode(struct drm_encoder *encoder) 528771fe6b9SJerome Glisse { 529771fe6b9SJerome Glisse struct drm_connector *connector; 530771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 531771fe6b9SJerome Glisse 532771fe6b9SJerome Glisse connector = radeon_get_connector_for_encoder(encoder); 533771fe6b9SJerome Glisse if (!connector) 534771fe6b9SJerome Glisse return 0; 535771fe6b9SJerome Glisse 536771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 537771fe6b9SJerome Glisse 538771fe6b9SJerome Glisse switch (connector->connector_type) { 539771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_DVII: 540771fe6b9SJerome Glisse if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr)) 541771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_HDMI; 542771fe6b9SJerome Glisse else if (radeon_connector->use_digital) 543771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_DVI; 544771fe6b9SJerome Glisse else 545771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_CRT; 546771fe6b9SJerome Glisse break; 547771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_DVID: 548771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_HDMIA: 549771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_HDMIB: 550771fe6b9SJerome Glisse default: 551771fe6b9SJerome Glisse if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr)) 552771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_HDMI; 553771fe6b9SJerome Glisse else 554771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_DVI; 555771fe6b9SJerome Glisse break; 556771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_LVDS: 557771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_LVDS; 558771fe6b9SJerome Glisse break; 559771fe6b9SJerome Glisse case DRM_MODE_CONNECTOR_DisplayPort: 560771fe6b9SJerome Glisse /*if (radeon_output->MonType == MT_DP) 561771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_DP; 562771fe6b9SJerome Glisse else*/ 563771fe6b9SJerome Glisse if (drm_detect_hdmi_monitor((struct edid *)connector->edid_blob_ptr)) 564771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_HDMI; 565771fe6b9SJerome Glisse else 566771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_DVI; 567771fe6b9SJerome Glisse break; 568771fe6b9SJerome Glisse case CONNECTOR_DVI_A: 569771fe6b9SJerome Glisse case CONNECTOR_VGA: 570771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_CRT; 571771fe6b9SJerome Glisse break; 572771fe6b9SJerome Glisse case CONNECTOR_STV: 573771fe6b9SJerome Glisse case CONNECTOR_CTV: 574771fe6b9SJerome Glisse case CONNECTOR_DIN: 575771fe6b9SJerome Glisse /* fix me */ 576771fe6b9SJerome Glisse return ATOM_ENCODER_MODE_TV; 577771fe6b9SJerome Glisse /*return ATOM_ENCODER_MODE_CV;*/ 578771fe6b9SJerome Glisse break; 579771fe6b9SJerome Glisse } 580771fe6b9SJerome Glisse } 581771fe6b9SJerome Glisse 582771fe6b9SJerome Glisse static void 583771fe6b9SJerome Glisse atombios_dig_encoder_setup(struct drm_encoder *encoder, int action) 584771fe6b9SJerome Glisse { 585771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 586771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 587771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 588771fe6b9SJerome Glisse DIG_ENCODER_CONTROL_PS_ALLOCATION args; 589771fe6b9SJerome Glisse int index = 0, num = 0; 590771fe6b9SJerome Glisse uint8_t frev, crev; 591771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig; 592771fe6b9SJerome Glisse struct drm_connector *connector; 593771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 594771fe6b9SJerome Glisse struct radeon_connector_atom_dig *dig_connector; 595771fe6b9SJerome Glisse 596771fe6b9SJerome Glisse connector = radeon_get_connector_for_encoder(encoder); 597771fe6b9SJerome Glisse if (!connector) 598771fe6b9SJerome Glisse return; 599771fe6b9SJerome Glisse 600771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 601771fe6b9SJerome Glisse 602771fe6b9SJerome Glisse if (!radeon_connector->con_priv) 603771fe6b9SJerome Glisse return; 604771fe6b9SJerome Glisse 605771fe6b9SJerome Glisse dig_connector = radeon_connector->con_priv; 606771fe6b9SJerome Glisse 607771fe6b9SJerome Glisse if (!radeon_encoder->enc_priv) 608771fe6b9SJerome Glisse return; 609771fe6b9SJerome Glisse 610771fe6b9SJerome Glisse dig = radeon_encoder->enc_priv; 611771fe6b9SJerome Glisse 612771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 613771fe6b9SJerome Glisse 614771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) { 615771fe6b9SJerome Glisse if (dig->dig_block) 616771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); 617771fe6b9SJerome Glisse else 618771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); 619771fe6b9SJerome Glisse num = dig->dig_block + 1; 620771fe6b9SJerome Glisse } else { 621771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 622771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 623771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); 624771fe6b9SJerome Glisse num = 1; 625771fe6b9SJerome Glisse break; 626771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 627771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); 628771fe6b9SJerome Glisse num = 2; 629771fe6b9SJerome Glisse break; 630771fe6b9SJerome Glisse } 631771fe6b9SJerome Glisse } 632771fe6b9SJerome Glisse 633771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 634771fe6b9SJerome Glisse 635771fe6b9SJerome Glisse args.ucAction = action; 636771fe6b9SJerome Glisse args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); 637771fe6b9SJerome Glisse 638771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) { 639771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 640771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 641771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1; 642771fe6b9SJerome Glisse break; 643771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 644771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2; 645771fe6b9SJerome Glisse break; 646771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 647771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3; 648771fe6b9SJerome Glisse break; 649771fe6b9SJerome Glisse } 650771fe6b9SJerome Glisse } else { 651771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 652771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 653771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_TRANSMITTER1; 654771fe6b9SJerome Glisse break; 655771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 656771fe6b9SJerome Glisse args.ucConfig = ATOM_ENCODER_CONFIG_TRANSMITTER2; 657771fe6b9SJerome Glisse break; 658771fe6b9SJerome Glisse } 659771fe6b9SJerome Glisse } 660771fe6b9SJerome Glisse 661771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) { 662771fe6b9SJerome Glisse args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA_B; 663771fe6b9SJerome Glisse args.ucLaneNum = 8; 664771fe6b9SJerome Glisse } else { 665771fe6b9SJerome Glisse if (dig_connector->linkb) 666771fe6b9SJerome Glisse args.ucConfig |= ATOM_ENCODER_CONFIG_LINKB; 667771fe6b9SJerome Glisse else 668771fe6b9SJerome Glisse args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA; 669771fe6b9SJerome Glisse args.ucLaneNum = 4; 670771fe6b9SJerome Glisse } 671771fe6b9SJerome Glisse 672771fe6b9SJerome Glisse args.ucEncoderMode = atombios_get_encoder_mode(encoder); 673771fe6b9SJerome Glisse 674771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 675771fe6b9SJerome Glisse 676771fe6b9SJerome Glisse } 677771fe6b9SJerome Glisse 678771fe6b9SJerome Glisse union dig_transmitter_control { 679771fe6b9SJerome Glisse DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1; 680771fe6b9SJerome Glisse DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2; 681771fe6b9SJerome Glisse }; 682771fe6b9SJerome Glisse 683771fe6b9SJerome Glisse static void 684771fe6b9SJerome Glisse atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action) 685771fe6b9SJerome Glisse { 686771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 687771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 688771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 689771fe6b9SJerome Glisse union dig_transmitter_control args; 690771fe6b9SJerome Glisse int index = 0, num = 0; 691771fe6b9SJerome Glisse uint8_t frev, crev; 692771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig; 693771fe6b9SJerome Glisse struct drm_connector *connector; 694771fe6b9SJerome Glisse struct radeon_connector *radeon_connector; 695771fe6b9SJerome Glisse struct radeon_connector_atom_dig *dig_connector; 696771fe6b9SJerome Glisse 697771fe6b9SJerome Glisse connector = radeon_get_connector_for_encoder(encoder); 698771fe6b9SJerome Glisse if (!connector) 699771fe6b9SJerome Glisse return; 700771fe6b9SJerome Glisse 701771fe6b9SJerome Glisse radeon_connector = to_radeon_connector(connector); 702771fe6b9SJerome Glisse 703771fe6b9SJerome Glisse if (!radeon_encoder->enc_priv) 704771fe6b9SJerome Glisse return; 705771fe6b9SJerome Glisse 706771fe6b9SJerome Glisse dig = radeon_encoder->enc_priv; 707771fe6b9SJerome Glisse 708771fe6b9SJerome Glisse if (!radeon_connector->con_priv) 709771fe6b9SJerome Glisse return; 710771fe6b9SJerome Glisse 711771fe6b9SJerome Glisse dig_connector = radeon_connector->con_priv; 712771fe6b9SJerome Glisse 713771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 714771fe6b9SJerome Glisse 715771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) 716771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl); 717771fe6b9SJerome Glisse else { 718771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 719771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 720771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG1TransmitterControl); 721771fe6b9SJerome Glisse break; 722771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 723771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DIG2TransmitterControl); 724771fe6b9SJerome Glisse break; 725771fe6b9SJerome Glisse } 726771fe6b9SJerome Glisse } 727771fe6b9SJerome Glisse 728771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 729771fe6b9SJerome Glisse 730771fe6b9SJerome Glisse args.v1.ucAction = action; 731771fe6b9SJerome Glisse 732771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) { 733771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) { 734771fe6b9SJerome Glisse args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock * 10 * 2) / 100); 735771fe6b9SJerome Glisse args.v2.acConfig.fDualLinkConnector = 1; 736771fe6b9SJerome Glisse } else { 737771fe6b9SJerome Glisse args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock * 10 * 4) / 100); 738771fe6b9SJerome Glisse } 739771fe6b9SJerome Glisse if (dig->dig_block) 740771fe6b9SJerome Glisse args.v2.acConfig.ucEncoderSel = 1; 741771fe6b9SJerome Glisse 742771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 743771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 744771fe6b9SJerome Glisse args.v2.acConfig.ucTransmitterSel = 0; 745771fe6b9SJerome Glisse num = 0; 746771fe6b9SJerome Glisse break; 747771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 748771fe6b9SJerome Glisse args.v2.acConfig.ucTransmitterSel = 1; 749771fe6b9SJerome Glisse num = 1; 750771fe6b9SJerome Glisse break; 751771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 752771fe6b9SJerome Glisse args.v2.acConfig.ucTransmitterSel = 2; 753771fe6b9SJerome Glisse num = 2; 754771fe6b9SJerome Glisse break; 755771fe6b9SJerome Glisse } 756771fe6b9SJerome Glisse 757771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 758771fe6b9SJerome Glisse if (dig->coherent_mode) 759771fe6b9SJerome Glisse args.v2.acConfig.fCoherentMode = 1; 760771fe6b9SJerome Glisse } 761771fe6b9SJerome Glisse } else { 762771fe6b9SJerome Glisse args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL; 763771fe6b9SJerome Glisse args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock) / 10); 764771fe6b9SJerome Glisse 765771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 766771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 767771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER; 768771fe6b9SJerome Glisse if (rdev->flags & RADEON_IS_IGP) { 769771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) { 770771fe6b9SJerome Glisse args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | 771771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LINKA_B); 772771fe6b9SJerome Glisse if (dig_connector->igp_lane_info & 0x3) 773771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7; 774771fe6b9SJerome Glisse else if (dig_connector->igp_lane_info & 0xc) 775771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15; 776771fe6b9SJerome Glisse } else { 777771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA; 778771fe6b9SJerome Glisse if (dig_connector->igp_lane_info & 0x1) 779771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3; 780771fe6b9SJerome Glisse else if (dig_connector->igp_lane_info & 0x2) 781771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7; 782771fe6b9SJerome Glisse else if (dig_connector->igp_lane_info & 0x4) 783771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11; 784771fe6b9SJerome Glisse else if (dig_connector->igp_lane_info & 0x8) 785771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15; 786771fe6b9SJerome Glisse } 787771fe6b9SJerome Glisse } else { 788771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 789771fe6b9SJerome Glisse args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | 790771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LINKA_B | 791771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LANE_0_7); 792771fe6b9SJerome Glisse else { 793771fe6b9SJerome Glisse if (dig_connector->linkb) 794771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB | ATOM_TRANSMITTER_CONFIG_LANE_0_3; 795771fe6b9SJerome Glisse else 796771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA | ATOM_TRANSMITTER_CONFIG_LANE_0_3; 797771fe6b9SJerome Glisse } 798771fe6b9SJerome Glisse } 799771fe6b9SJerome Glisse break; 800771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 801771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER; 802771fe6b9SJerome Glisse if (radeon_encoder->pixel_clock > 165000) 803771fe6b9SJerome Glisse args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | 804771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LINKA_B | 805771fe6b9SJerome Glisse ATOM_TRANSMITTER_CONFIG_LANE_0_7); 806771fe6b9SJerome Glisse else { 807771fe6b9SJerome Glisse if (dig_connector->linkb) 808771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB | ATOM_TRANSMITTER_CONFIG_LANE_0_3; 809771fe6b9SJerome Glisse else 810771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA | ATOM_TRANSMITTER_CONFIG_LANE_0_3; 811771fe6b9SJerome Glisse } 812771fe6b9SJerome Glisse break; 813771fe6b9SJerome Glisse } 814771fe6b9SJerome Glisse 815771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 816771fe6b9SJerome Glisse if (dig->coherent_mode) 817771fe6b9SJerome Glisse args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT; 818771fe6b9SJerome Glisse } 819771fe6b9SJerome Glisse } 820771fe6b9SJerome Glisse 821771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 822771fe6b9SJerome Glisse 823771fe6b9SJerome Glisse } 824771fe6b9SJerome Glisse 825771fe6b9SJerome Glisse static void 826771fe6b9SJerome Glisse atombios_yuv_setup(struct drm_encoder *encoder, bool enable) 827771fe6b9SJerome Glisse { 828771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 829771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 830771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 831771fe6b9SJerome Glisse struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 832771fe6b9SJerome Glisse ENABLE_YUV_PS_ALLOCATION args; 833771fe6b9SJerome Glisse int index = GetIndexIntoMasterTable(COMMAND, EnableYUV); 834771fe6b9SJerome Glisse uint32_t temp, reg; 835771fe6b9SJerome Glisse 836771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 837771fe6b9SJerome Glisse 838771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) 839771fe6b9SJerome Glisse reg = R600_BIOS_3_SCRATCH; 840771fe6b9SJerome Glisse else 841771fe6b9SJerome Glisse reg = RADEON_BIOS_3_SCRATCH; 842771fe6b9SJerome Glisse 843771fe6b9SJerome Glisse /* XXX: fix up scratch reg handling */ 844771fe6b9SJerome Glisse temp = RREG32(reg); 8454ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 846771fe6b9SJerome Glisse WREG32(reg, (ATOM_S3_TV1_ACTIVE | 847771fe6b9SJerome Glisse (radeon_crtc->crtc_id << 18))); 8484ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 849771fe6b9SJerome Glisse WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24))); 850771fe6b9SJerome Glisse else 851771fe6b9SJerome Glisse WREG32(reg, 0); 852771fe6b9SJerome Glisse 853771fe6b9SJerome Glisse if (enable) 854771fe6b9SJerome Glisse args.ucEnable = ATOM_ENABLE; 855771fe6b9SJerome Glisse args.ucCRTC = radeon_crtc->crtc_id; 856771fe6b9SJerome Glisse 857771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 858771fe6b9SJerome Glisse 859771fe6b9SJerome Glisse WREG32(reg, temp); 860771fe6b9SJerome Glisse } 861771fe6b9SJerome Glisse 862771fe6b9SJerome Glisse static void 863771fe6b9SJerome Glisse radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode) 864771fe6b9SJerome Glisse { 865771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 866771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 867771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 868771fe6b9SJerome Glisse DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args; 869771fe6b9SJerome Glisse int index = 0; 870771fe6b9SJerome Glisse bool is_dig = false; 8714ce001abSDave Airlie int devices; 872771fe6b9SJerome Glisse 873771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 874771fe6b9SJerome Glisse 8754ce001abSDave Airlie /* on DPMS off we have no idea if active device is meaningful */ 8764ce001abSDave Airlie if (mode != DRM_MODE_DPMS_ON && !radeon_encoder->active_device) 8774ce001abSDave Airlie devices = radeon_encoder->devices; 8784ce001abSDave Airlie else 8794ce001abSDave Airlie devices = radeon_encoder->active_device; 8804ce001abSDave Airlie 881f641e51eSDave Airlie DRM_DEBUG("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n", 8824ce001abSDave Airlie radeon_encoder->encoder_id, mode, radeon_encoder->devices, 8834ce001abSDave Airlie radeon_encoder->active_device); 884771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 885771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 886771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 887771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl); 888771fe6b9SJerome Glisse break; 889771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 890771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 891771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 892771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 893771fe6b9SJerome Glisse is_dig = true; 894771fe6b9SJerome Glisse break; 895771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DVO1: 896771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DDI: 897771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 898771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl); 899771fe6b9SJerome Glisse break; 900771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 901771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); 902771fe6b9SJerome Glisse break; 903771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 904771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 905771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); 906771fe6b9SJerome Glisse else 907771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl); 908771fe6b9SJerome Glisse break; 909771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 910771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 9114ce001abSDave Airlie if (devices & (ATOM_DEVICE_TV_SUPPORT)) 912771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl); 9134ce001abSDave Airlie else if (devices & (ATOM_DEVICE_CV_SUPPORT)) 914771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl); 915771fe6b9SJerome Glisse else 916771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl); 917771fe6b9SJerome Glisse break; 918771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 919771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 9204ce001abSDave Airlie if (devices & (ATOM_DEVICE_TV_SUPPORT)) 921771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl); 9224ce001abSDave Airlie else if (devices & (ATOM_DEVICE_CV_SUPPORT)) 923771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl); 924771fe6b9SJerome Glisse else 925771fe6b9SJerome Glisse index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl); 926771fe6b9SJerome Glisse break; 927771fe6b9SJerome Glisse } 928771fe6b9SJerome Glisse 929771fe6b9SJerome Glisse if (is_dig) { 930771fe6b9SJerome Glisse switch (mode) { 931771fe6b9SJerome Glisse case DRM_MODE_DPMS_ON: 932771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE); 933771fe6b9SJerome Glisse break; 934771fe6b9SJerome Glisse case DRM_MODE_DPMS_STANDBY: 935771fe6b9SJerome Glisse case DRM_MODE_DPMS_SUSPEND: 936771fe6b9SJerome Glisse case DRM_MODE_DPMS_OFF: 937771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE); 938771fe6b9SJerome Glisse break; 939771fe6b9SJerome Glisse } 940771fe6b9SJerome Glisse } else { 941771fe6b9SJerome Glisse switch (mode) { 942771fe6b9SJerome Glisse case DRM_MODE_DPMS_ON: 943771fe6b9SJerome Glisse args.ucAction = ATOM_ENABLE; 944771fe6b9SJerome Glisse break; 945771fe6b9SJerome Glisse case DRM_MODE_DPMS_STANDBY: 946771fe6b9SJerome Glisse case DRM_MODE_DPMS_SUSPEND: 947771fe6b9SJerome Glisse case DRM_MODE_DPMS_OFF: 948771fe6b9SJerome Glisse args.ucAction = ATOM_DISABLE; 949771fe6b9SJerome Glisse break; 950771fe6b9SJerome Glisse } 951771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 952771fe6b9SJerome Glisse } 953771fe6b9SJerome Glisse radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 954771fe6b9SJerome Glisse } 955771fe6b9SJerome Glisse 956771fe6b9SJerome Glisse union crtc_sourc_param { 957771fe6b9SJerome Glisse SELECT_CRTC_SOURCE_PS_ALLOCATION v1; 958771fe6b9SJerome Glisse SELECT_CRTC_SOURCE_PARAMETERS_V2 v2; 959771fe6b9SJerome Glisse }; 960771fe6b9SJerome Glisse 961771fe6b9SJerome Glisse static void 962771fe6b9SJerome Glisse atombios_set_encoder_crtc_source(struct drm_encoder *encoder) 963771fe6b9SJerome Glisse { 964771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 965771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 966771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 967771fe6b9SJerome Glisse struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 968771fe6b9SJerome Glisse union crtc_sourc_param args; 969771fe6b9SJerome Glisse int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source); 970771fe6b9SJerome Glisse uint8_t frev, crev; 971771fe6b9SJerome Glisse 972771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 973771fe6b9SJerome Glisse 974771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 975771fe6b9SJerome Glisse 976771fe6b9SJerome Glisse switch (frev) { 977771fe6b9SJerome Glisse case 1: 978771fe6b9SJerome Glisse switch (crev) { 979771fe6b9SJerome Glisse case 1: 980771fe6b9SJerome Glisse default: 981771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) 982771fe6b9SJerome Glisse args.v1.ucCRTC = radeon_crtc->crtc_id; 983771fe6b9SJerome Glisse else { 984771fe6b9SJerome Glisse if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) { 985771fe6b9SJerome Glisse args.v1.ucCRTC = radeon_crtc->crtc_id; 986771fe6b9SJerome Glisse } else { 987771fe6b9SJerome Glisse args.v1.ucCRTC = radeon_crtc->crtc_id << 2; 988771fe6b9SJerome Glisse } 989771fe6b9SJerome Glisse } 990771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 991771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 992771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 993771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX; 994771fe6b9SJerome Glisse break; 995771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 996771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 997771fe6b9SJerome Glisse if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) 998771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX; 999771fe6b9SJerome Glisse else 1000771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX; 1001771fe6b9SJerome Glisse break; 1002771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1003771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DDI: 1004771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1005771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX; 1006771fe6b9SJerome Glisse break; 1007771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1008771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 10094ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1010771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX; 10114ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 1012771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_CV_INDEX; 1013771fe6b9SJerome Glisse else 1014771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX; 1015771fe6b9SJerome Glisse break; 1016771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 1017771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 10184ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1019771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX; 10204ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 1021771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_CV_INDEX; 1022771fe6b9SJerome Glisse else 1023771fe6b9SJerome Glisse args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX; 1024771fe6b9SJerome Glisse break; 1025771fe6b9SJerome Glisse } 1026771fe6b9SJerome Glisse break; 1027771fe6b9SJerome Glisse case 2: 1028771fe6b9SJerome Glisse args.v2.ucCRTC = radeon_crtc->crtc_id; 1029771fe6b9SJerome Glisse args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder); 1030771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 1031771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1032771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1033771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1034771fe6b9SJerome Glisse if (ASIC_IS_DCE32(rdev)) { 1035771fe6b9SJerome Glisse if (radeon_crtc->crtc_id) 1036771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; 1037771fe6b9SJerome Glisse else 1038771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID; 1039771fe6b9SJerome Glisse } else 1040771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID; 1041771fe6b9SJerome Glisse break; 1042771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1043771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID; 1044771fe6b9SJerome Glisse break; 1045771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 1046771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; 1047771fe6b9SJerome Glisse break; 1048771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 10494ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1050771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 10514ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 1052771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 1053771fe6b9SJerome Glisse else 1054771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID; 1055771fe6b9SJerome Glisse break; 1056771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 10574ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1058771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 10594ce001abSDave Airlie else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) 1060771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; 1061771fe6b9SJerome Glisse else 1062771fe6b9SJerome Glisse args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID; 1063771fe6b9SJerome Glisse break; 1064771fe6b9SJerome Glisse } 1065771fe6b9SJerome Glisse break; 1066771fe6b9SJerome Glisse } 1067771fe6b9SJerome Glisse break; 1068771fe6b9SJerome Glisse default: 1069771fe6b9SJerome Glisse DRM_ERROR("Unknown table version: %d, %d\n", frev, crev); 1070771fe6b9SJerome Glisse break; 1071771fe6b9SJerome Glisse } 1072771fe6b9SJerome Glisse 1073771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 1074771fe6b9SJerome Glisse 1075771fe6b9SJerome Glisse } 1076771fe6b9SJerome Glisse 1077771fe6b9SJerome Glisse static void 1078771fe6b9SJerome Glisse atombios_apply_encoder_quirks(struct drm_encoder *encoder, 1079771fe6b9SJerome Glisse struct drm_display_mode *mode) 1080771fe6b9SJerome Glisse { 1081771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 1082771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 1083771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1084771fe6b9SJerome Glisse struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 1085771fe6b9SJerome Glisse 1086771fe6b9SJerome Glisse /* Funky macbooks */ 1087771fe6b9SJerome Glisse if ((dev->pdev->device == 0x71C5) && 1088771fe6b9SJerome Glisse (dev->pdev->subsystem_vendor == 0x106b) && 1089771fe6b9SJerome Glisse (dev->pdev->subsystem_device == 0x0080)) { 1090771fe6b9SJerome Glisse if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) { 1091771fe6b9SJerome Glisse uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL); 1092771fe6b9SJerome Glisse 1093771fe6b9SJerome Glisse lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN; 1094771fe6b9SJerome Glisse lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN; 1095771fe6b9SJerome Glisse 1096771fe6b9SJerome Glisse WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control); 1097771fe6b9SJerome Glisse } 1098771fe6b9SJerome Glisse } 1099771fe6b9SJerome Glisse 1100771fe6b9SJerome Glisse /* set scaler clears this on some chips */ 1101771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev) && (mode->flags & DRM_MODE_FLAG_INTERLACE)) 1102771fe6b9SJerome Glisse WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, AVIVO_D1MODE_INTERLEAVE_EN); 1103771fe6b9SJerome Glisse } 1104771fe6b9SJerome Glisse 1105771fe6b9SJerome Glisse static void 1106771fe6b9SJerome Glisse radeon_atom_encoder_mode_set(struct drm_encoder *encoder, 1107771fe6b9SJerome Glisse struct drm_display_mode *mode, 1108771fe6b9SJerome Glisse struct drm_display_mode *adjusted_mode) 1109771fe6b9SJerome Glisse { 1110771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 1111771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 1112771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1113771fe6b9SJerome Glisse struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 1114771fe6b9SJerome Glisse 1115771fe6b9SJerome Glisse if (radeon_encoder->enc_priv) { 1116771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig; 1117771fe6b9SJerome Glisse 1118771fe6b9SJerome Glisse dig = radeon_encoder->enc_priv; 1119771fe6b9SJerome Glisse dig->dig_block = radeon_crtc->crtc_id; 1120771fe6b9SJerome Glisse } 1121771fe6b9SJerome Glisse radeon_encoder->pixel_clock = adjusted_mode->clock; 1122771fe6b9SJerome Glisse 1123771fe6b9SJerome Glisse radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 1124771fe6b9SJerome Glisse atombios_set_encoder_crtc_source(encoder); 1125771fe6b9SJerome Glisse 1126771fe6b9SJerome Glisse if (ASIC_IS_AVIVO(rdev)) { 11274ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT)) 1128771fe6b9SJerome Glisse atombios_yuv_setup(encoder, true); 1129771fe6b9SJerome Glisse else 1130771fe6b9SJerome Glisse atombios_yuv_setup(encoder, false); 1131771fe6b9SJerome Glisse } 1132771fe6b9SJerome Glisse 1133771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 1134771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 1135771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 1136771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 1137771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 1138771fe6b9SJerome Glisse atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE); 1139771fe6b9SJerome Glisse break; 1140771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1141771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1142771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1143771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 1144771fe6b9SJerome Glisse /* disable the encoder and transmitter */ 1145771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE); 1146771fe6b9SJerome Glisse atombios_dig_encoder_setup(encoder, ATOM_DISABLE); 1147771fe6b9SJerome Glisse 1148771fe6b9SJerome Glisse /* setup and enable the encoder and transmitter */ 1149771fe6b9SJerome Glisse atombios_dig_encoder_setup(encoder, ATOM_ENABLE); 1150771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP); 1151771fe6b9SJerome Glisse atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE); 1152771fe6b9SJerome Glisse break; 1153771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DDI: 1154771fe6b9SJerome Glisse atombios_ddia_setup(encoder, ATOM_ENABLE); 1155771fe6b9SJerome Glisse break; 1156771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1157771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1158771fe6b9SJerome Glisse atombios_external_tmds_setup(encoder, ATOM_ENABLE); 1159771fe6b9SJerome Glisse break; 1160771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1161771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 1162771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 1163771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 1164771fe6b9SJerome Glisse atombios_dac_setup(encoder, ATOM_ENABLE); 11654ce001abSDave Airlie if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) 1166771fe6b9SJerome Glisse atombios_tv_setup(encoder, ATOM_ENABLE); 1167771fe6b9SJerome Glisse break; 1168771fe6b9SJerome Glisse } 1169771fe6b9SJerome Glisse atombios_apply_encoder_quirks(encoder, adjusted_mode); 1170771fe6b9SJerome Glisse } 1171771fe6b9SJerome Glisse 1172771fe6b9SJerome Glisse static bool 11734ce001abSDave Airlie atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector) 1174771fe6b9SJerome Glisse { 1175771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 1176771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 1177771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 11784ce001abSDave Airlie struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1179771fe6b9SJerome Glisse 1180771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | 1181771fe6b9SJerome Glisse ATOM_DEVICE_CV_SUPPORT | 1182771fe6b9SJerome Glisse ATOM_DEVICE_CRT_SUPPORT)) { 1183771fe6b9SJerome Glisse DAC_LOAD_DETECTION_PS_ALLOCATION args; 1184771fe6b9SJerome Glisse int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection); 1185771fe6b9SJerome Glisse uint8_t frev, crev; 1186771fe6b9SJerome Glisse 1187771fe6b9SJerome Glisse memset(&args, 0, sizeof(args)); 1188771fe6b9SJerome Glisse 1189771fe6b9SJerome Glisse atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); 1190771fe6b9SJerome Glisse 1191771fe6b9SJerome Glisse args.sDacload.ucMisc = 0; 1192771fe6b9SJerome Glisse 1193771fe6b9SJerome Glisse if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) || 1194771fe6b9SJerome Glisse (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1)) 1195771fe6b9SJerome Glisse args.sDacload.ucDacType = ATOM_DAC_A; 1196771fe6b9SJerome Glisse else 1197771fe6b9SJerome Glisse args.sDacload.ucDacType = ATOM_DAC_B; 1198771fe6b9SJerome Glisse 11994ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) 1200771fe6b9SJerome Glisse args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT); 12014ce001abSDave Airlie else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) 1202771fe6b9SJerome Glisse args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT); 12034ce001abSDave Airlie else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { 1204771fe6b9SJerome Glisse args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT); 1205771fe6b9SJerome Glisse if (crev >= 3) 1206771fe6b9SJerome Glisse args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb; 12074ce001abSDave Airlie } else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { 1208771fe6b9SJerome Glisse args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT); 1209771fe6b9SJerome Glisse if (crev >= 3) 1210771fe6b9SJerome Glisse args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb; 1211771fe6b9SJerome Glisse } 1212771fe6b9SJerome Glisse 1213771fe6b9SJerome Glisse atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 1214771fe6b9SJerome Glisse 1215771fe6b9SJerome Glisse return true; 1216771fe6b9SJerome Glisse } else 1217771fe6b9SJerome Glisse return false; 1218771fe6b9SJerome Glisse } 1219771fe6b9SJerome Glisse 1220771fe6b9SJerome Glisse static enum drm_connector_status 1221771fe6b9SJerome Glisse radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) 1222771fe6b9SJerome Glisse { 1223771fe6b9SJerome Glisse struct drm_device *dev = encoder->dev; 1224771fe6b9SJerome Glisse struct radeon_device *rdev = dev->dev_private; 1225771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 12264ce001abSDave Airlie struct radeon_connector *radeon_connector = to_radeon_connector(connector); 1227771fe6b9SJerome Glisse uint32_t bios_0_scratch; 1228771fe6b9SJerome Glisse 12294ce001abSDave Airlie if (!atombios_dac_load_detect(encoder, connector)) { 1230771fe6b9SJerome Glisse DRM_DEBUG("detect returned false \n"); 1231771fe6b9SJerome Glisse return connector_status_unknown; 1232771fe6b9SJerome Glisse } 1233771fe6b9SJerome Glisse 1234771fe6b9SJerome Glisse if (rdev->family >= CHIP_R600) 1235771fe6b9SJerome Glisse bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH); 1236771fe6b9SJerome Glisse else 1237771fe6b9SJerome Glisse bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH); 1238771fe6b9SJerome Glisse 12394ce001abSDave Airlie DRM_DEBUG("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices); 12404ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) { 1241771fe6b9SJerome Glisse if (bios_0_scratch & ATOM_S0_CRT1_MASK) 1242771fe6b9SJerome Glisse return connector_status_connected; 12434ce001abSDave Airlie } 12444ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) { 1245771fe6b9SJerome Glisse if (bios_0_scratch & ATOM_S0_CRT2_MASK) 1246771fe6b9SJerome Glisse return connector_status_connected; 12474ce001abSDave Airlie } 12484ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { 1249771fe6b9SJerome Glisse if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A)) 1250771fe6b9SJerome Glisse return connector_status_connected; 12514ce001abSDave Airlie } 12524ce001abSDave Airlie if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { 1253771fe6b9SJerome Glisse if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A)) 1254771fe6b9SJerome Glisse return connector_status_connected; /* CTV */ 1255771fe6b9SJerome Glisse else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A)) 1256771fe6b9SJerome Glisse return connector_status_connected; /* STV */ 1257771fe6b9SJerome Glisse } 1258771fe6b9SJerome Glisse return connector_status_disconnected; 1259771fe6b9SJerome Glisse } 1260771fe6b9SJerome Glisse 1261771fe6b9SJerome Glisse static void radeon_atom_encoder_prepare(struct drm_encoder *encoder) 1262771fe6b9SJerome Glisse { 1263771fe6b9SJerome Glisse radeon_atom_output_lock(encoder, true); 1264771fe6b9SJerome Glisse radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 12654ce001abSDave Airlie 12664ce001abSDave Airlie radeon_encoder_set_active_device(encoder); 1267771fe6b9SJerome Glisse } 1268771fe6b9SJerome Glisse 1269771fe6b9SJerome Glisse static void radeon_atom_encoder_commit(struct drm_encoder *encoder) 1270771fe6b9SJerome Glisse { 1271771fe6b9SJerome Glisse radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON); 1272771fe6b9SJerome Glisse radeon_atom_output_lock(encoder, false); 1273771fe6b9SJerome Glisse } 1274771fe6b9SJerome Glisse 12754ce001abSDave Airlie static void radeon_atom_encoder_disable(struct drm_encoder *encoder) 12764ce001abSDave Airlie { 12774ce001abSDave Airlie struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 12784ce001abSDave Airlie radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 12794ce001abSDave Airlie radeon_encoder->active_device = 0; 12804ce001abSDave Airlie } 12814ce001abSDave Airlie 1282771fe6b9SJerome Glisse static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = { 1283771fe6b9SJerome Glisse .dpms = radeon_atom_encoder_dpms, 1284771fe6b9SJerome Glisse .mode_fixup = radeon_atom_mode_fixup, 1285771fe6b9SJerome Glisse .prepare = radeon_atom_encoder_prepare, 1286771fe6b9SJerome Glisse .mode_set = radeon_atom_encoder_mode_set, 1287771fe6b9SJerome Glisse .commit = radeon_atom_encoder_commit, 12884ce001abSDave Airlie .disable = radeon_atom_encoder_disable, 1289771fe6b9SJerome Glisse /* no detect for TMDS/LVDS yet */ 1290771fe6b9SJerome Glisse }; 1291771fe6b9SJerome Glisse 1292771fe6b9SJerome Glisse static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = { 1293771fe6b9SJerome Glisse .dpms = radeon_atom_encoder_dpms, 1294771fe6b9SJerome Glisse .mode_fixup = radeon_atom_mode_fixup, 1295771fe6b9SJerome Glisse .prepare = radeon_atom_encoder_prepare, 1296771fe6b9SJerome Glisse .mode_set = radeon_atom_encoder_mode_set, 1297771fe6b9SJerome Glisse .commit = radeon_atom_encoder_commit, 1298771fe6b9SJerome Glisse .detect = radeon_atom_dac_detect, 1299771fe6b9SJerome Glisse }; 1300771fe6b9SJerome Glisse 1301771fe6b9SJerome Glisse void radeon_enc_destroy(struct drm_encoder *encoder) 1302771fe6b9SJerome Glisse { 1303771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1304771fe6b9SJerome Glisse kfree(radeon_encoder->enc_priv); 1305771fe6b9SJerome Glisse drm_encoder_cleanup(encoder); 1306771fe6b9SJerome Glisse kfree(radeon_encoder); 1307771fe6b9SJerome Glisse } 1308771fe6b9SJerome Glisse 1309771fe6b9SJerome Glisse static const struct drm_encoder_funcs radeon_atom_enc_funcs = { 1310771fe6b9SJerome Glisse .destroy = radeon_enc_destroy, 1311771fe6b9SJerome Glisse }; 1312771fe6b9SJerome Glisse 13134ce001abSDave Airlie struct radeon_encoder_atom_dac * 13144ce001abSDave Airlie radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder) 13154ce001abSDave Airlie { 13164ce001abSDave Airlie struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL); 13174ce001abSDave Airlie 13184ce001abSDave Airlie if (!dac) 13194ce001abSDave Airlie return NULL; 13204ce001abSDave Airlie 13214ce001abSDave Airlie dac->tv_std = TV_STD_NTSC; 13224ce001abSDave Airlie return dac; 13234ce001abSDave Airlie } 13244ce001abSDave Airlie 1325771fe6b9SJerome Glisse struct radeon_encoder_atom_dig * 1326771fe6b9SJerome Glisse radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder) 1327771fe6b9SJerome Glisse { 1328771fe6b9SJerome Glisse struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL); 1329771fe6b9SJerome Glisse 1330771fe6b9SJerome Glisse if (!dig) 1331771fe6b9SJerome Glisse return NULL; 1332771fe6b9SJerome Glisse 1333771fe6b9SJerome Glisse /* coherent mode by default */ 1334771fe6b9SJerome Glisse dig->coherent_mode = true; 1335771fe6b9SJerome Glisse 1336771fe6b9SJerome Glisse return dig; 1337771fe6b9SJerome Glisse } 1338771fe6b9SJerome Glisse 1339771fe6b9SJerome Glisse void 1340771fe6b9SJerome Glisse radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t supported_device) 1341771fe6b9SJerome Glisse { 1342771fe6b9SJerome Glisse struct drm_encoder *encoder; 1343771fe6b9SJerome Glisse struct radeon_encoder *radeon_encoder; 1344771fe6b9SJerome Glisse 1345771fe6b9SJerome Glisse /* see if we already added it */ 1346771fe6b9SJerome Glisse list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 1347771fe6b9SJerome Glisse radeon_encoder = to_radeon_encoder(encoder); 1348771fe6b9SJerome Glisse if (radeon_encoder->encoder_id == encoder_id) { 1349771fe6b9SJerome Glisse radeon_encoder->devices |= supported_device; 1350771fe6b9SJerome Glisse return; 1351771fe6b9SJerome Glisse } 1352771fe6b9SJerome Glisse 1353771fe6b9SJerome Glisse } 1354771fe6b9SJerome Glisse 1355771fe6b9SJerome Glisse /* add a new one */ 1356771fe6b9SJerome Glisse radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL); 1357771fe6b9SJerome Glisse if (!radeon_encoder) 1358771fe6b9SJerome Glisse return; 1359771fe6b9SJerome Glisse 1360771fe6b9SJerome Glisse encoder = &radeon_encoder->base; 1361771fe6b9SJerome Glisse encoder->possible_crtcs = 0x3; 1362771fe6b9SJerome Glisse encoder->possible_clones = 0; 1363771fe6b9SJerome Glisse 1364771fe6b9SJerome Glisse radeon_encoder->enc_priv = NULL; 1365771fe6b9SJerome Glisse 1366771fe6b9SJerome Glisse radeon_encoder->encoder_id = encoder_id; 1367771fe6b9SJerome Glisse radeon_encoder->devices = supported_device; 1368c93bb85bSJerome Glisse radeon_encoder->rmx_type = RMX_OFF; 1369771fe6b9SJerome Glisse 1370771fe6b9SJerome Glisse switch (radeon_encoder->encoder_id) { 1371771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVDS: 1372771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 1373771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: 1374771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_LVTM1: 1375771fe6b9SJerome Glisse if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 1376771fe6b9SJerome Glisse radeon_encoder->rmx_type = RMX_FULL; 1377771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS); 1378771fe6b9SJerome Glisse radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); 1379771fe6b9SJerome Glisse } else { 1380771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS); 1381771fe6b9SJerome Glisse radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); 1382771fe6b9SJerome Glisse } 1383771fe6b9SJerome Glisse drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); 1384771fe6b9SJerome Glisse break; 1385771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1386771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC); 1387771fe6b9SJerome Glisse drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs); 1388771fe6b9SJerome Glisse break; 1389771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DAC2: 1390771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 1391771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 1392771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TVDAC); 13934ce001abSDave Airlie radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder); 1394771fe6b9SJerome Glisse drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs); 1395771fe6b9SJerome Glisse break; 1396771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1397771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 1398771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_DDI: 1399771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 1400771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: 1401771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 1402771fe6b9SJerome Glisse case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 1403*60d15f55SAlex Deucher if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 1404*60d15f55SAlex Deucher radeon_encoder->rmx_type = RMX_FULL; 1405*60d15f55SAlex Deucher drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS); 1406*60d15f55SAlex Deucher radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); 1407*60d15f55SAlex Deucher } else { 1408771fe6b9SJerome Glisse drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS); 1409771fe6b9SJerome Glisse radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); 1410*60d15f55SAlex Deucher } 1411771fe6b9SJerome Glisse drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); 1412771fe6b9SJerome Glisse break; 1413771fe6b9SJerome Glisse } 1414771fe6b9SJerome Glisse } 1415