Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007-8 Advanced Micro Devices, Inc. |
| 3 | * Copyright 2008 Red Hat Inc. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in |
| 13 | * all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 19 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 21 | * OTHER DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: Dave Airlie |
| 24 | * Alex Deucher |
| 25 | */ |
| 26 | #include "drmP.h" |
| 27 | #include "drm_crtc_helper.h" |
| 28 | #include "radeon_drm.h" |
| 29 | #include "radeon.h" |
| 30 | #include "atom.h" |
| 31 | |
| 32 | extern int atom_debug; |
| 33 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 34 | /* evil but including atombios.h is much worse */ |
| 35 | bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index, |
| 36 | struct drm_display_mode *mode); |
| 37 | |
Dave Airlie | 1f3b6a4 | 2009-10-13 14:10:37 +1000 | [diff] [blame] | 38 | static uint32_t radeon_encoder_clones(struct drm_encoder *encoder) |
| 39 | { |
| 40 | struct drm_device *dev = encoder->dev; |
| 41 | struct radeon_device *rdev = dev->dev_private; |
| 42 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 43 | struct drm_encoder *clone_encoder; |
| 44 | uint32_t index_mask = 0; |
| 45 | int count; |
| 46 | |
| 47 | /* DIG routing gets problematic */ |
| 48 | if (rdev->family >= CHIP_R600) |
| 49 | return index_mask; |
| 50 | /* LVDS/TV are too wacky */ |
| 51 | if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT) |
| 52 | return index_mask; |
| 53 | /* DVO requires 2x ppll clocks depending on tmds chip */ |
| 54 | if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) |
| 55 | return index_mask; |
| 56 | |
| 57 | count = -1; |
| 58 | list_for_each_entry(clone_encoder, &dev->mode_config.encoder_list, head) { |
| 59 | struct radeon_encoder *radeon_clone = to_radeon_encoder(clone_encoder); |
| 60 | count++; |
| 61 | |
| 62 | if (clone_encoder == encoder) |
| 63 | continue; |
| 64 | if (radeon_clone->devices & (ATOM_DEVICE_LCD_SUPPORT)) |
| 65 | continue; |
| 66 | if (radeon_clone->devices & ATOM_DEVICE_DFP2_SUPPORT) |
| 67 | continue; |
| 68 | else |
| 69 | index_mask |= (1 << count); |
| 70 | } |
| 71 | return index_mask; |
| 72 | } |
| 73 | |
| 74 | void radeon_setup_encoder_clones(struct drm_device *dev) |
| 75 | { |
| 76 | struct drm_encoder *encoder; |
| 77 | |
| 78 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 79 | encoder->possible_clones = radeon_encoder_clones(encoder); |
| 80 | } |
| 81 | } |
| 82 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 83 | uint32_t |
| 84 | radeon_get_encoder_id(struct drm_device *dev, uint32_t supported_device, uint8_t dac) |
| 85 | { |
| 86 | struct radeon_device *rdev = dev->dev_private; |
| 87 | uint32_t ret = 0; |
| 88 | |
| 89 | switch (supported_device) { |
| 90 | case ATOM_DEVICE_CRT1_SUPPORT: |
| 91 | case ATOM_DEVICE_TV1_SUPPORT: |
| 92 | case ATOM_DEVICE_TV2_SUPPORT: |
| 93 | case ATOM_DEVICE_CRT2_SUPPORT: |
| 94 | case ATOM_DEVICE_CV_SUPPORT: |
| 95 | switch (dac) { |
| 96 | case 1: /* dac a */ |
| 97 | if ((rdev->family == CHIP_RS300) || |
| 98 | (rdev->family == CHIP_RS400) || |
| 99 | (rdev->family == CHIP_RS480)) |
| 100 | ret = ENCODER_OBJECT_ID_INTERNAL_DAC2; |
| 101 | else if (ASIC_IS_AVIVO(rdev)) |
| 102 | ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1; |
| 103 | else |
| 104 | ret = ENCODER_OBJECT_ID_INTERNAL_DAC1; |
| 105 | break; |
| 106 | case 2: /* dac b */ |
| 107 | if (ASIC_IS_AVIVO(rdev)) |
| 108 | ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2; |
| 109 | else { |
| 110 | /*if (rdev->family == CHIP_R200) |
| 111 | ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; |
| 112 | else*/ |
| 113 | ret = ENCODER_OBJECT_ID_INTERNAL_DAC2; |
| 114 | } |
| 115 | break; |
| 116 | case 3: /* external dac */ |
| 117 | if (ASIC_IS_AVIVO(rdev)) |
| 118 | ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1; |
| 119 | else |
| 120 | ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; |
| 121 | break; |
| 122 | } |
| 123 | break; |
| 124 | case ATOM_DEVICE_LCD1_SUPPORT: |
| 125 | if (ASIC_IS_AVIVO(rdev)) |
| 126 | ret = ENCODER_OBJECT_ID_INTERNAL_LVTM1; |
| 127 | else |
| 128 | ret = ENCODER_OBJECT_ID_INTERNAL_LVDS; |
| 129 | break; |
| 130 | case ATOM_DEVICE_DFP1_SUPPORT: |
| 131 | if ((rdev->family == CHIP_RS300) || |
| 132 | (rdev->family == CHIP_RS400) || |
| 133 | (rdev->family == CHIP_RS480)) |
| 134 | ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; |
| 135 | else if (ASIC_IS_AVIVO(rdev)) |
| 136 | ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1; |
| 137 | else |
| 138 | ret = ENCODER_OBJECT_ID_INTERNAL_TMDS1; |
| 139 | break; |
| 140 | case ATOM_DEVICE_LCD2_SUPPORT: |
| 141 | case ATOM_DEVICE_DFP2_SUPPORT: |
| 142 | if ((rdev->family == CHIP_RS600) || |
| 143 | (rdev->family == CHIP_RS690) || |
| 144 | (rdev->family == CHIP_RS740)) |
| 145 | ret = ENCODER_OBJECT_ID_INTERNAL_DDI; |
| 146 | else if (ASIC_IS_AVIVO(rdev)) |
| 147 | ret = ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1; |
| 148 | else |
| 149 | ret = ENCODER_OBJECT_ID_INTERNAL_DVO1; |
| 150 | break; |
| 151 | case ATOM_DEVICE_DFP3_SUPPORT: |
| 152 | ret = ENCODER_OBJECT_ID_INTERNAL_LVTM1; |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | void |
| 160 | radeon_link_encoder_connector(struct drm_device *dev) |
| 161 | { |
| 162 | struct drm_connector *connector; |
| 163 | struct radeon_connector *radeon_connector; |
| 164 | struct drm_encoder *encoder; |
| 165 | struct radeon_encoder *radeon_encoder; |
| 166 | |
| 167 | /* walk the list and link encoders to connectors */ |
| 168 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 169 | radeon_connector = to_radeon_connector(connector); |
| 170 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 171 | radeon_encoder = to_radeon_encoder(encoder); |
| 172 | if (radeon_encoder->devices & radeon_connector->devices) |
| 173 | drm_mode_connector_attach_encoder(connector, encoder); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 178 | void radeon_encoder_set_active_device(struct drm_encoder *encoder) |
| 179 | { |
| 180 | struct drm_device *dev = encoder->dev; |
| 181 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 182 | struct drm_connector *connector; |
| 183 | |
| 184 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 185 | if (connector->encoder == encoder) { |
| 186 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 187 | radeon_encoder->active_device = radeon_encoder->devices & radeon_connector->devices; |
Dave Airlie | f641e51 | 2009-09-08 11:17:38 +1000 | [diff] [blame] | 188 | DRM_DEBUG("setting active device to %08x from %08x %08x for encoder %d\n", |
| 189 | radeon_encoder->active_device, radeon_encoder->devices, |
| 190 | radeon_connector->devices, encoder->encoder_type); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 195 | static struct drm_connector * |
| 196 | radeon_get_connector_for_encoder(struct drm_encoder *encoder) |
| 197 | { |
| 198 | struct drm_device *dev = encoder->dev; |
| 199 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 200 | struct drm_connector *connector; |
| 201 | struct radeon_connector *radeon_connector; |
| 202 | |
| 203 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 204 | radeon_connector = to_radeon_connector(connector); |
| 205 | if (radeon_encoder->devices & radeon_connector->devices) |
| 206 | return connector; |
| 207 | } |
| 208 | return NULL; |
| 209 | } |
| 210 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 211 | static bool radeon_atom_mode_fixup(struct drm_encoder *encoder, |
| 212 | struct drm_display_mode *mode, |
| 213 | struct drm_display_mode *adjusted_mode) |
| 214 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 215 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 216 | struct drm_device *dev = encoder->dev; |
| 217 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 218 | |
Alex Deucher | 8c2a6d7 | 2009-10-14 02:00:42 -0400 | [diff] [blame] | 219 | /* set the active encoder to connector routing */ |
| 220 | radeon_encoder_set_active_device(encoder); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 221 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
| 222 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 223 | /* hw bug */ |
| 224 | if ((mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 225 | && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2))) |
| 226 | adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2; |
| 227 | |
Alex Deucher | 80297e8 | 2009-11-12 14:55:14 -0500 | [diff] [blame] | 228 | /* get the native mode for LVDS */ |
| 229 | if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 230 | struct drm_display_mode *native_mode = &radeon_encoder->native_mode; |
| 231 | int mode_id = adjusted_mode->base.id; |
| 232 | *adjusted_mode = *native_mode; |
| 233 | if (!ASIC_IS_AVIVO(rdev)) { |
| 234 | adjusted_mode->hdisplay = mode->hdisplay; |
| 235 | adjusted_mode->vdisplay = mode->vdisplay; |
| 236 | } |
| 237 | adjusted_mode->base.id = mode_id; |
| 238 | } |
| 239 | |
| 240 | /* get the native mode for TV */ |
Alex Deucher | ceefedd | 2009-10-13 23:57:47 -0400 | [diff] [blame] | 241 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) { |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 242 | struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv; |
| 243 | if (tv_dac) { |
| 244 | if (tv_dac->tv_std == TV_STD_NTSC || |
| 245 | tv_dac->tv_std == TV_STD_NTSC_J || |
| 246 | tv_dac->tv_std == TV_STD_PAL_M) |
| 247 | radeon_atom_get_tv_timings(rdev, 0, adjusted_mode); |
| 248 | else |
| 249 | radeon_atom_get_tv_timings(rdev, 1, adjusted_mode); |
| 250 | } |
| 251 | } |
| 252 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | |
| 256 | static void |
| 257 | atombios_dac_setup(struct drm_encoder *encoder, int action) |
| 258 | { |
| 259 | struct drm_device *dev = encoder->dev; |
| 260 | struct radeon_device *rdev = dev->dev_private; |
| 261 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 262 | DAC_ENCODER_CONTROL_PS_ALLOCATION args; |
| 263 | int index = 0, num = 0; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 264 | struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 265 | enum radeon_tv_std tv_std = TV_STD_NTSC; |
| 266 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 267 | if (dac_info->tv_std) |
| 268 | tv_std = dac_info->tv_std; |
| 269 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 270 | memset(&args, 0, sizeof(args)); |
| 271 | |
| 272 | switch (radeon_encoder->encoder_id) { |
| 273 | case ENCODER_OBJECT_ID_INTERNAL_DAC1: |
| 274 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: |
| 275 | index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl); |
| 276 | num = 1; |
| 277 | break; |
| 278 | case ENCODER_OBJECT_ID_INTERNAL_DAC2: |
| 279 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: |
| 280 | index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl); |
| 281 | num = 2; |
| 282 | break; |
| 283 | } |
| 284 | |
| 285 | args.ucAction = action; |
| 286 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 287 | if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 288 | args.ucDacStandard = ATOM_DAC1_PS2; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 289 | else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 290 | args.ucDacStandard = ATOM_DAC1_CV; |
| 291 | else { |
| 292 | switch (tv_std) { |
| 293 | case TV_STD_PAL: |
| 294 | case TV_STD_PAL_M: |
| 295 | case TV_STD_SCART_PAL: |
| 296 | case TV_STD_SECAM: |
| 297 | case TV_STD_PAL_CN: |
| 298 | args.ucDacStandard = ATOM_DAC1_PAL; |
| 299 | break; |
| 300 | case TV_STD_NTSC: |
| 301 | case TV_STD_NTSC_J: |
| 302 | case TV_STD_PAL_60: |
| 303 | default: |
| 304 | args.ucDacStandard = ATOM_DAC1_NTSC; |
| 305 | break; |
| 306 | } |
| 307 | } |
| 308 | args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); |
| 309 | |
| 310 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 311 | |
| 312 | } |
| 313 | |
| 314 | static void |
| 315 | atombios_tv_setup(struct drm_encoder *encoder, int action) |
| 316 | { |
| 317 | struct drm_device *dev = encoder->dev; |
| 318 | struct radeon_device *rdev = dev->dev_private; |
| 319 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 320 | TV_ENCODER_CONTROL_PS_ALLOCATION args; |
| 321 | int index = 0; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 322 | struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 323 | enum radeon_tv_std tv_std = TV_STD_NTSC; |
| 324 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 325 | if (dac_info->tv_std) |
| 326 | tv_std = dac_info->tv_std; |
| 327 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 328 | memset(&args, 0, sizeof(args)); |
| 329 | |
| 330 | index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl); |
| 331 | |
| 332 | args.sTVEncoder.ucAction = action; |
| 333 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 334 | if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 335 | args.sTVEncoder.ucTvStandard = ATOM_TV_CV; |
| 336 | else { |
| 337 | switch (tv_std) { |
| 338 | case TV_STD_NTSC: |
| 339 | args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC; |
| 340 | break; |
| 341 | case TV_STD_PAL: |
| 342 | args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; |
| 343 | break; |
| 344 | case TV_STD_PAL_M: |
| 345 | args.sTVEncoder.ucTvStandard = ATOM_TV_PALM; |
| 346 | break; |
| 347 | case TV_STD_PAL_60: |
| 348 | args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60; |
| 349 | break; |
| 350 | case TV_STD_NTSC_J: |
| 351 | args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ; |
| 352 | break; |
| 353 | case TV_STD_SCART_PAL: |
| 354 | args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */ |
| 355 | break; |
| 356 | case TV_STD_SECAM: |
| 357 | args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM; |
| 358 | break; |
| 359 | case TV_STD_PAL_CN: |
| 360 | args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN; |
| 361 | break; |
| 362 | default: |
| 363 | args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC; |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); |
| 369 | |
| 370 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 371 | |
| 372 | } |
| 373 | |
| 374 | void |
| 375 | atombios_external_tmds_setup(struct drm_encoder *encoder, int action) |
| 376 | { |
| 377 | struct drm_device *dev = encoder->dev; |
| 378 | struct radeon_device *rdev = dev->dev_private; |
| 379 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 380 | ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION args; |
| 381 | int index = 0; |
| 382 | |
| 383 | memset(&args, 0, sizeof(args)); |
| 384 | |
| 385 | index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl); |
| 386 | |
| 387 | args.sXTmdsEncoder.ucEnable = action; |
| 388 | |
| 389 | if (radeon_encoder->pixel_clock > 165000) |
| 390 | args.sXTmdsEncoder.ucMisc = PANEL_ENCODER_MISC_DUAL; |
| 391 | |
| 392 | /*if (pScrn->rgbBits == 8)*/ |
| 393 | args.sXTmdsEncoder.ucMisc |= (1 << 1); |
| 394 | |
| 395 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 396 | |
| 397 | } |
| 398 | |
| 399 | static void |
| 400 | atombios_ddia_setup(struct drm_encoder *encoder, int action) |
| 401 | { |
| 402 | struct drm_device *dev = encoder->dev; |
| 403 | struct radeon_device *rdev = dev->dev_private; |
| 404 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 405 | DVO_ENCODER_CONTROL_PS_ALLOCATION args; |
| 406 | int index = 0; |
| 407 | |
| 408 | memset(&args, 0, sizeof(args)); |
| 409 | |
| 410 | index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl); |
| 411 | |
| 412 | args.sDVOEncoder.ucAction = action; |
| 413 | args.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); |
| 414 | |
| 415 | if (radeon_encoder->pixel_clock > 165000) |
| 416 | args.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute = PANEL_ENCODER_MISC_DUAL; |
| 417 | |
| 418 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 419 | |
| 420 | } |
| 421 | |
| 422 | union lvds_encoder_control { |
| 423 | LVDS_ENCODER_CONTROL_PS_ALLOCATION v1; |
| 424 | LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2; |
| 425 | }; |
| 426 | |
Alex Deucher | 32f48ff | 2009-11-30 01:54:16 -0500 | [diff] [blame] | 427 | void |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 428 | atombios_digital_setup(struct drm_encoder *encoder, int action) |
| 429 | { |
| 430 | struct drm_device *dev = encoder->dev; |
| 431 | struct radeon_device *rdev = dev->dev_private; |
| 432 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 433 | union lvds_encoder_control args; |
| 434 | int index = 0; |
| 435 | uint8_t frev, crev; |
| 436 | struct radeon_encoder_atom_dig *dig; |
| 437 | struct drm_connector *connector; |
| 438 | struct radeon_connector *radeon_connector; |
| 439 | struct radeon_connector_atom_dig *dig_connector; |
| 440 | |
| 441 | connector = radeon_get_connector_for_encoder(encoder); |
| 442 | if (!connector) |
| 443 | return; |
| 444 | |
| 445 | radeon_connector = to_radeon_connector(connector); |
| 446 | |
| 447 | if (!radeon_encoder->enc_priv) |
| 448 | return; |
| 449 | |
| 450 | dig = radeon_encoder->enc_priv; |
| 451 | |
| 452 | if (!radeon_connector->con_priv) |
| 453 | return; |
| 454 | |
| 455 | dig_connector = radeon_connector->con_priv; |
| 456 | |
| 457 | memset(&args, 0, sizeof(args)); |
| 458 | |
| 459 | switch (radeon_encoder->encoder_id) { |
| 460 | case ENCODER_OBJECT_ID_INTERNAL_LVDS: |
| 461 | index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl); |
| 462 | break; |
| 463 | case ENCODER_OBJECT_ID_INTERNAL_TMDS1: |
| 464 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: |
| 465 | index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl); |
| 466 | break; |
| 467 | case ENCODER_OBJECT_ID_INTERNAL_LVTM1: |
| 468 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) |
| 469 | index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl); |
| 470 | else |
| 471 | index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl); |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); |
| 476 | |
| 477 | switch (frev) { |
| 478 | case 1: |
| 479 | case 2: |
| 480 | switch (crev) { |
| 481 | case 1: |
| 482 | args.v1.ucMisc = 0; |
| 483 | args.v1.ucAction = action; |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 484 | if (drm_detect_hdmi_monitor(radeon_connector->edid)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 485 | args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE; |
| 486 | args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); |
| 487 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 488 | if (dig->lvds_misc & (1 << 0)) |
| 489 | args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; |
| 490 | if (dig->lvds_misc & (1 << 1)) |
| 491 | args.v1.ucMisc |= (1 << 1); |
| 492 | } else { |
| 493 | if (dig_connector->linkb) |
| 494 | args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; |
| 495 | if (radeon_encoder->pixel_clock > 165000) |
| 496 | args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL; |
| 497 | /*if (pScrn->rgbBits == 8) */ |
| 498 | args.v1.ucMisc |= (1 << 1); |
| 499 | } |
| 500 | break; |
| 501 | case 2: |
| 502 | case 3: |
| 503 | args.v2.ucMisc = 0; |
| 504 | args.v2.ucAction = action; |
| 505 | if (crev == 3) { |
| 506 | if (dig->coherent_mode) |
| 507 | args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT; |
| 508 | } |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 509 | if (drm_detect_hdmi_monitor(radeon_connector->edid)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 510 | args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE; |
| 511 | args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); |
| 512 | args.v2.ucTruncate = 0; |
| 513 | args.v2.ucSpatial = 0; |
| 514 | args.v2.ucTemporal = 0; |
| 515 | args.v2.ucFRC = 0; |
| 516 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 517 | if (dig->lvds_misc & (1 << 0)) |
| 518 | args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL; |
| 519 | if (dig->lvds_misc & (1 << 5)) { |
| 520 | args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN; |
| 521 | if (dig->lvds_misc & (1 << 1)) |
| 522 | args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH; |
| 523 | } |
| 524 | if (dig->lvds_misc & (1 << 6)) { |
| 525 | args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN; |
| 526 | if (dig->lvds_misc & (1 << 1)) |
| 527 | args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH; |
| 528 | if (((dig->lvds_misc >> 2) & 0x3) == 2) |
| 529 | args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4; |
| 530 | } |
| 531 | } else { |
| 532 | if (dig_connector->linkb) |
| 533 | args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB; |
| 534 | if (radeon_encoder->pixel_clock > 165000) |
| 535 | args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL; |
| 536 | } |
| 537 | break; |
| 538 | default: |
| 539 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 540 | break; |
| 541 | } |
| 542 | break; |
| 543 | default: |
| 544 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 545 | break; |
| 546 | } |
| 547 | |
| 548 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 549 | |
| 550 | } |
| 551 | |
| 552 | int |
| 553 | atombios_get_encoder_mode(struct drm_encoder *encoder) |
| 554 | { |
| 555 | struct drm_connector *connector; |
| 556 | struct radeon_connector *radeon_connector; |
| 557 | |
| 558 | connector = radeon_get_connector_for_encoder(encoder); |
| 559 | if (!connector) |
| 560 | return 0; |
| 561 | |
| 562 | radeon_connector = to_radeon_connector(connector); |
| 563 | |
| 564 | switch (connector->connector_type) { |
| 565 | case DRM_MODE_CONNECTOR_DVII: |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 566 | case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */ |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 567 | if (drm_detect_hdmi_monitor(radeon_connector->edid)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 568 | return ATOM_ENCODER_MODE_HDMI; |
| 569 | else if (radeon_connector->use_digital) |
| 570 | return ATOM_ENCODER_MODE_DVI; |
| 571 | else |
| 572 | return ATOM_ENCODER_MODE_CRT; |
| 573 | break; |
| 574 | case DRM_MODE_CONNECTOR_DVID: |
| 575 | case DRM_MODE_CONNECTOR_HDMIA: |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 576 | default: |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 577 | if (drm_detect_hdmi_monitor(radeon_connector->edid)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 578 | return ATOM_ENCODER_MODE_HDMI; |
| 579 | else |
| 580 | return ATOM_ENCODER_MODE_DVI; |
| 581 | break; |
| 582 | case DRM_MODE_CONNECTOR_LVDS: |
| 583 | return ATOM_ENCODER_MODE_LVDS; |
| 584 | break; |
| 585 | case DRM_MODE_CONNECTOR_DisplayPort: |
| 586 | /*if (radeon_output->MonType == MT_DP) |
| 587 | return ATOM_ENCODER_MODE_DP; |
| 588 | else*/ |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 589 | if (drm_detect_hdmi_monitor(radeon_connector->edid)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 590 | return ATOM_ENCODER_MODE_HDMI; |
| 591 | else |
| 592 | return ATOM_ENCODER_MODE_DVI; |
| 593 | break; |
| 594 | case CONNECTOR_DVI_A: |
| 595 | case CONNECTOR_VGA: |
| 596 | return ATOM_ENCODER_MODE_CRT; |
| 597 | break; |
| 598 | case CONNECTOR_STV: |
| 599 | case CONNECTOR_CTV: |
| 600 | case CONNECTOR_DIN: |
| 601 | /* fix me */ |
| 602 | return ATOM_ENCODER_MODE_TV; |
| 603 | /*return ATOM_ENCODER_MODE_CV;*/ |
| 604 | break; |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | static void |
| 609 | atombios_dig_encoder_setup(struct drm_encoder *encoder, int action) |
| 610 | { |
| 611 | struct drm_device *dev = encoder->dev; |
| 612 | struct radeon_device *rdev = dev->dev_private; |
| 613 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 614 | DIG_ENCODER_CONTROL_PS_ALLOCATION args; |
| 615 | int index = 0, num = 0; |
| 616 | uint8_t frev, crev; |
| 617 | struct radeon_encoder_atom_dig *dig; |
| 618 | struct drm_connector *connector; |
| 619 | struct radeon_connector *radeon_connector; |
| 620 | struct radeon_connector_atom_dig *dig_connector; |
| 621 | |
| 622 | connector = radeon_get_connector_for_encoder(encoder); |
| 623 | if (!connector) |
| 624 | return; |
| 625 | |
| 626 | radeon_connector = to_radeon_connector(connector); |
| 627 | |
| 628 | if (!radeon_connector->con_priv) |
| 629 | return; |
| 630 | |
| 631 | dig_connector = radeon_connector->con_priv; |
| 632 | |
| 633 | if (!radeon_encoder->enc_priv) |
| 634 | return; |
| 635 | |
| 636 | dig = radeon_encoder->enc_priv; |
| 637 | |
| 638 | memset(&args, 0, sizeof(args)); |
| 639 | |
| 640 | if (ASIC_IS_DCE32(rdev)) { |
| 641 | if (dig->dig_block) |
| 642 | index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); |
| 643 | else |
| 644 | index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); |
| 645 | num = dig->dig_block + 1; |
| 646 | } else { |
| 647 | switch (radeon_encoder->encoder_id) { |
| 648 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 649 | index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); |
| 650 | num = 1; |
| 651 | break; |
| 652 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: |
| 653 | index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); |
| 654 | num = 2; |
| 655 | break; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); |
| 660 | |
| 661 | args.ucAction = action; |
| 662 | args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); |
| 663 | |
| 664 | if (ASIC_IS_DCE32(rdev)) { |
| 665 | switch (radeon_encoder->encoder_id) { |
| 666 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 667 | args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1; |
| 668 | break; |
| 669 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: |
| 670 | args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2; |
| 671 | break; |
| 672 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: |
| 673 | args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3; |
| 674 | break; |
| 675 | } |
| 676 | } else { |
| 677 | switch (radeon_encoder->encoder_id) { |
| 678 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 679 | args.ucConfig = ATOM_ENCODER_CONFIG_TRANSMITTER1; |
| 680 | break; |
| 681 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: |
| 682 | args.ucConfig = ATOM_ENCODER_CONFIG_TRANSMITTER2; |
| 683 | break; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | if (radeon_encoder->pixel_clock > 165000) { |
| 688 | args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA_B; |
| 689 | args.ucLaneNum = 8; |
| 690 | } else { |
| 691 | if (dig_connector->linkb) |
| 692 | args.ucConfig |= ATOM_ENCODER_CONFIG_LINKB; |
| 693 | else |
| 694 | args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA; |
| 695 | args.ucLaneNum = 4; |
| 696 | } |
| 697 | |
| 698 | args.ucEncoderMode = atombios_get_encoder_mode(encoder); |
| 699 | |
| 700 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 701 | |
| 702 | } |
| 703 | |
| 704 | union dig_transmitter_control { |
| 705 | DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1; |
| 706 | DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2; |
| 707 | }; |
| 708 | |
| 709 | static void |
| 710 | atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action) |
| 711 | { |
| 712 | struct drm_device *dev = encoder->dev; |
| 713 | struct radeon_device *rdev = dev->dev_private; |
| 714 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 715 | union dig_transmitter_control args; |
| 716 | int index = 0, num = 0; |
| 717 | uint8_t frev, crev; |
| 718 | struct radeon_encoder_atom_dig *dig; |
| 719 | struct drm_connector *connector; |
| 720 | struct radeon_connector *radeon_connector; |
| 721 | struct radeon_connector_atom_dig *dig_connector; |
| 722 | |
| 723 | connector = radeon_get_connector_for_encoder(encoder); |
| 724 | if (!connector) |
| 725 | return; |
| 726 | |
| 727 | radeon_connector = to_radeon_connector(connector); |
| 728 | |
| 729 | if (!radeon_encoder->enc_priv) |
| 730 | return; |
| 731 | |
| 732 | dig = radeon_encoder->enc_priv; |
| 733 | |
| 734 | if (!radeon_connector->con_priv) |
| 735 | return; |
| 736 | |
| 737 | dig_connector = radeon_connector->con_priv; |
| 738 | |
| 739 | memset(&args, 0, sizeof(args)); |
| 740 | |
| 741 | if (ASIC_IS_DCE32(rdev)) |
| 742 | index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl); |
| 743 | else { |
| 744 | switch (radeon_encoder->encoder_id) { |
| 745 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 746 | index = GetIndexIntoMasterTable(COMMAND, DIG1TransmitterControl); |
| 747 | break; |
| 748 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: |
| 749 | index = GetIndexIntoMasterTable(COMMAND, DIG2TransmitterControl); |
| 750 | break; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); |
| 755 | |
| 756 | args.v1.ucAction = action; |
Alex Deucher | f95a9f0 | 2009-11-05 02:21:06 -0500 | [diff] [blame] | 757 | if (action == ATOM_TRANSMITTER_ACTION_INIT) { |
| 758 | args.v1.usInitInfo = radeon_connector->connector_object_id; |
| 759 | } else { |
| 760 | if (radeon_encoder->pixel_clock > 165000) |
| 761 | args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10); |
| 762 | else |
| 763 | args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); |
| 764 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 765 | if (ASIC_IS_DCE32(rdev)) { |
Alex Deucher | f95a9f0 | 2009-11-05 02:21:06 -0500 | [diff] [blame] | 766 | if (radeon_encoder->pixel_clock > 165000) |
Alex Deucher | 4170a6c1 | 2009-11-05 01:16:23 -0500 | [diff] [blame] | 767 | args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 768 | if (dig->dig_block) |
| 769 | args.v2.acConfig.ucEncoderSel = 1; |
| 770 | |
| 771 | switch (radeon_encoder->encoder_id) { |
| 772 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 773 | args.v2.acConfig.ucTransmitterSel = 0; |
| 774 | num = 0; |
| 775 | break; |
| 776 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: |
| 777 | args.v2.acConfig.ucTransmitterSel = 1; |
| 778 | num = 1; |
| 779 | break; |
| 780 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: |
| 781 | args.v2.acConfig.ucTransmitterSel = 2; |
| 782 | num = 2; |
| 783 | break; |
| 784 | } |
| 785 | |
| 786 | if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { |
| 787 | if (dig->coherent_mode) |
| 788 | args.v2.acConfig.fCoherentMode = 1; |
| 789 | } |
| 790 | } else { |
| 791 | args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 792 | |
| 793 | switch (radeon_encoder->encoder_id) { |
| 794 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 795 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER; |
| 796 | if (rdev->flags & RADEON_IS_IGP) { |
| 797 | if (radeon_encoder->pixel_clock > 165000) { |
| 798 | args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | |
| 799 | ATOM_TRANSMITTER_CONFIG_LINKA_B); |
| 800 | if (dig_connector->igp_lane_info & 0x3) |
| 801 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7; |
| 802 | else if (dig_connector->igp_lane_info & 0xc) |
| 803 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15; |
| 804 | } else { |
| 805 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA; |
| 806 | if (dig_connector->igp_lane_info & 0x1) |
| 807 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3; |
| 808 | else if (dig_connector->igp_lane_info & 0x2) |
| 809 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7; |
| 810 | else if (dig_connector->igp_lane_info & 0x4) |
| 811 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11; |
| 812 | else if (dig_connector->igp_lane_info & 0x8) |
| 813 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15; |
| 814 | } |
| 815 | } else { |
| 816 | if (radeon_encoder->pixel_clock > 165000) |
| 817 | args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | |
| 818 | ATOM_TRANSMITTER_CONFIG_LINKA_B | |
| 819 | ATOM_TRANSMITTER_CONFIG_LANE_0_7); |
| 820 | else { |
| 821 | if (dig_connector->linkb) |
| 822 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB | ATOM_TRANSMITTER_CONFIG_LANE_0_3; |
| 823 | else |
| 824 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA | ATOM_TRANSMITTER_CONFIG_LANE_0_3; |
| 825 | } |
| 826 | } |
| 827 | break; |
| 828 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: |
| 829 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER; |
| 830 | if (radeon_encoder->pixel_clock > 165000) |
| 831 | args.v1.ucConfig |= (ATOM_TRANSMITTER_CONFIG_8LANE_LINK | |
| 832 | ATOM_TRANSMITTER_CONFIG_LINKA_B | |
| 833 | ATOM_TRANSMITTER_CONFIG_LANE_0_7); |
| 834 | else { |
| 835 | if (dig_connector->linkb) |
| 836 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB | ATOM_TRANSMITTER_CONFIG_LANE_0_3; |
| 837 | else |
| 838 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA | ATOM_TRANSMITTER_CONFIG_LANE_0_3; |
| 839 | } |
| 840 | break; |
| 841 | } |
| 842 | |
| 843 | if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { |
| 844 | if (dig->coherent_mode) |
| 845 | args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 850 | |
| 851 | } |
| 852 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 853 | static void |
| 854 | atombios_yuv_setup(struct drm_encoder *encoder, bool enable) |
| 855 | { |
| 856 | struct drm_device *dev = encoder->dev; |
| 857 | struct radeon_device *rdev = dev->dev_private; |
| 858 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 859 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
| 860 | ENABLE_YUV_PS_ALLOCATION args; |
| 861 | int index = GetIndexIntoMasterTable(COMMAND, EnableYUV); |
| 862 | uint32_t temp, reg; |
| 863 | |
| 864 | memset(&args, 0, sizeof(args)); |
| 865 | |
| 866 | if (rdev->family >= CHIP_R600) |
| 867 | reg = R600_BIOS_3_SCRATCH; |
| 868 | else |
| 869 | reg = RADEON_BIOS_3_SCRATCH; |
| 870 | |
| 871 | /* XXX: fix up scratch reg handling */ |
| 872 | temp = RREG32(reg); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 873 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 874 | WREG32(reg, (ATOM_S3_TV1_ACTIVE | |
| 875 | (radeon_crtc->crtc_id << 18))); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 876 | else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 877 | WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24))); |
| 878 | else |
| 879 | WREG32(reg, 0); |
| 880 | |
| 881 | if (enable) |
| 882 | args.ucEnable = ATOM_ENABLE; |
| 883 | args.ucCRTC = radeon_crtc->crtc_id; |
| 884 | |
| 885 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 886 | |
| 887 | WREG32(reg, temp); |
| 888 | } |
| 889 | |
| 890 | static void |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 891 | radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 892 | { |
| 893 | struct drm_device *dev = encoder->dev; |
| 894 | struct radeon_device *rdev = dev->dev_private; |
| 895 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 896 | DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args; |
| 897 | int index = 0; |
| 898 | bool is_dig = false; |
| 899 | |
| 900 | memset(&args, 0, sizeof(args)); |
| 901 | |
Dave Airlie | f641e51 | 2009-09-08 11:17:38 +1000 | [diff] [blame] | 902 | DRM_DEBUG("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n", |
| 903 | radeon_encoder->encoder_id, mode, radeon_encoder->devices, |
| 904 | radeon_encoder->active_device); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 905 | switch (radeon_encoder->encoder_id) { |
| 906 | case ENCODER_OBJECT_ID_INTERNAL_TMDS1: |
| 907 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: |
| 908 | index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl); |
| 909 | break; |
| 910 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 911 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: |
| 912 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: |
| 913 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: |
| 914 | is_dig = true; |
| 915 | break; |
| 916 | case ENCODER_OBJECT_ID_INTERNAL_DVO1: |
| 917 | case ENCODER_OBJECT_ID_INTERNAL_DDI: |
| 918 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: |
| 919 | index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl); |
| 920 | break; |
| 921 | case ENCODER_OBJECT_ID_INTERNAL_LVDS: |
| 922 | index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); |
| 923 | break; |
| 924 | case ENCODER_OBJECT_ID_INTERNAL_LVTM1: |
| 925 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) |
| 926 | index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl); |
| 927 | else |
| 928 | index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl); |
| 929 | break; |
| 930 | case ENCODER_OBJECT_ID_INTERNAL_DAC1: |
| 931 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: |
Alex Deucher | 8c2a6d7 | 2009-10-14 02:00:42 -0400 | [diff] [blame] | 932 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 933 | index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl); |
Alex Deucher | 8c2a6d7 | 2009-10-14 02:00:42 -0400 | [diff] [blame] | 934 | else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 935 | index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl); |
| 936 | else |
| 937 | index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl); |
| 938 | break; |
| 939 | case ENCODER_OBJECT_ID_INTERNAL_DAC2: |
| 940 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: |
Alex Deucher | 8c2a6d7 | 2009-10-14 02:00:42 -0400 | [diff] [blame] | 941 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 942 | index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl); |
Alex Deucher | 8c2a6d7 | 2009-10-14 02:00:42 -0400 | [diff] [blame] | 943 | else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 944 | index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl); |
| 945 | else |
| 946 | index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl); |
| 947 | break; |
| 948 | } |
| 949 | |
| 950 | if (is_dig) { |
| 951 | switch (mode) { |
| 952 | case DRM_MODE_DPMS_ON: |
Dave Airlie | 50dafba | 2009-12-01 15:02:17 +1000 | [diff] [blame^] | 953 | atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 954 | break; |
| 955 | case DRM_MODE_DPMS_STANDBY: |
| 956 | case DRM_MODE_DPMS_SUSPEND: |
| 957 | case DRM_MODE_DPMS_OFF: |
Dave Airlie | 50dafba | 2009-12-01 15:02:17 +1000 | [diff] [blame^] | 958 | atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 959 | break; |
| 960 | } |
| 961 | } else { |
| 962 | switch (mode) { |
| 963 | case DRM_MODE_DPMS_ON: |
| 964 | args.ucAction = ATOM_ENABLE; |
| 965 | break; |
| 966 | case DRM_MODE_DPMS_STANDBY: |
| 967 | case DRM_MODE_DPMS_SUSPEND: |
| 968 | case DRM_MODE_DPMS_OFF: |
| 969 | args.ucAction = ATOM_DISABLE; |
| 970 | break; |
| 971 | } |
| 972 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 973 | } |
| 974 | radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); |
| 975 | } |
| 976 | |
| 977 | union crtc_sourc_param { |
| 978 | SELECT_CRTC_SOURCE_PS_ALLOCATION v1; |
| 979 | SELECT_CRTC_SOURCE_PARAMETERS_V2 v2; |
| 980 | }; |
| 981 | |
| 982 | static void |
| 983 | atombios_set_encoder_crtc_source(struct drm_encoder *encoder) |
| 984 | { |
| 985 | struct drm_device *dev = encoder->dev; |
| 986 | struct radeon_device *rdev = dev->dev_private; |
| 987 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 988 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
| 989 | union crtc_sourc_param args; |
| 990 | int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source); |
| 991 | uint8_t frev, crev; |
| 992 | |
| 993 | memset(&args, 0, sizeof(args)); |
| 994 | |
| 995 | atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); |
| 996 | |
| 997 | switch (frev) { |
| 998 | case 1: |
| 999 | switch (crev) { |
| 1000 | case 1: |
| 1001 | default: |
| 1002 | if (ASIC_IS_AVIVO(rdev)) |
| 1003 | args.v1.ucCRTC = radeon_crtc->crtc_id; |
| 1004 | else { |
| 1005 | if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) { |
| 1006 | args.v1.ucCRTC = radeon_crtc->crtc_id; |
| 1007 | } else { |
| 1008 | args.v1.ucCRTC = radeon_crtc->crtc_id << 2; |
| 1009 | } |
| 1010 | } |
| 1011 | switch (radeon_encoder->encoder_id) { |
| 1012 | case ENCODER_OBJECT_ID_INTERNAL_TMDS1: |
| 1013 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: |
| 1014 | args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX; |
| 1015 | break; |
| 1016 | case ENCODER_OBJECT_ID_INTERNAL_LVDS: |
| 1017 | case ENCODER_OBJECT_ID_INTERNAL_LVTM1: |
| 1018 | if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) |
| 1019 | args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX; |
| 1020 | else |
| 1021 | args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX; |
| 1022 | break; |
| 1023 | case ENCODER_OBJECT_ID_INTERNAL_DVO1: |
| 1024 | case ENCODER_OBJECT_ID_INTERNAL_DDI: |
| 1025 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: |
| 1026 | args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX; |
| 1027 | break; |
| 1028 | case ENCODER_OBJECT_ID_INTERNAL_DAC1: |
| 1029 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1030 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1031 | args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1032 | else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1033 | args.v1.ucDevice = ATOM_DEVICE_CV_INDEX; |
| 1034 | else |
| 1035 | args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX; |
| 1036 | break; |
| 1037 | case ENCODER_OBJECT_ID_INTERNAL_DAC2: |
| 1038 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1039 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1040 | args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1041 | else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1042 | args.v1.ucDevice = ATOM_DEVICE_CV_INDEX; |
| 1043 | else |
| 1044 | args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX; |
| 1045 | break; |
| 1046 | } |
| 1047 | break; |
| 1048 | case 2: |
| 1049 | args.v2.ucCRTC = radeon_crtc->crtc_id; |
| 1050 | args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder); |
| 1051 | switch (radeon_encoder->encoder_id) { |
| 1052 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 1053 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: |
| 1054 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: |
| 1055 | if (ASIC_IS_DCE32(rdev)) { |
| 1056 | if (radeon_crtc->crtc_id) |
| 1057 | args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; |
| 1058 | else |
| 1059 | args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID; |
| 1060 | } else |
| 1061 | args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID; |
| 1062 | break; |
| 1063 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: |
| 1064 | args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID; |
| 1065 | break; |
| 1066 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: |
| 1067 | args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; |
| 1068 | break; |
| 1069 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1070 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1071 | args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1072 | else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1073 | args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; |
| 1074 | else |
| 1075 | args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID; |
| 1076 | break; |
| 1077 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1078 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1079 | args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1080 | else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1081 | args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID; |
| 1082 | else |
| 1083 | args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID; |
| 1084 | break; |
| 1085 | } |
| 1086 | break; |
| 1087 | } |
| 1088 | break; |
| 1089 | default: |
| 1090 | DRM_ERROR("Unknown table version: %d, %d\n", frev, crev); |
| 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 1095 | |
| 1096 | } |
| 1097 | |
| 1098 | static void |
| 1099 | atombios_apply_encoder_quirks(struct drm_encoder *encoder, |
| 1100 | struct drm_display_mode *mode) |
| 1101 | { |
| 1102 | struct drm_device *dev = encoder->dev; |
| 1103 | struct radeon_device *rdev = dev->dev_private; |
| 1104 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 1105 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
| 1106 | |
| 1107 | /* Funky macbooks */ |
| 1108 | if ((dev->pdev->device == 0x71C5) && |
| 1109 | (dev->pdev->subsystem_vendor == 0x106b) && |
| 1110 | (dev->pdev->subsystem_device == 0x0080)) { |
| 1111 | if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) { |
| 1112 | uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL); |
| 1113 | |
| 1114 | lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN; |
| 1115 | lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN; |
| 1116 | |
| 1117 | WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control); |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | /* set scaler clears this on some chips */ |
Alex Deucher | ceefedd | 2009-10-13 23:57:47 -0400 | [diff] [blame] | 1122 | if (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))) { |
| 1123 | if (ASIC_IS_AVIVO(rdev) && (mode->flags & DRM_MODE_FLAG_INTERLACE)) |
| 1124 | WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, |
| 1125 | AVIVO_D1MODE_INTERLEAVE_EN); |
| 1126 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static void |
| 1130 | radeon_atom_encoder_mode_set(struct drm_encoder *encoder, |
| 1131 | struct drm_display_mode *mode, |
| 1132 | struct drm_display_mode *adjusted_mode) |
| 1133 | { |
| 1134 | struct drm_device *dev = encoder->dev; |
| 1135 | struct radeon_device *rdev = dev->dev_private; |
| 1136 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 1137 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
| 1138 | |
| 1139 | if (radeon_encoder->enc_priv) { |
| 1140 | struct radeon_encoder_atom_dig *dig; |
| 1141 | |
| 1142 | dig = radeon_encoder->enc_priv; |
| 1143 | dig->dig_block = radeon_crtc->crtc_id; |
| 1144 | } |
| 1145 | radeon_encoder->pixel_clock = adjusted_mode->clock; |
| 1146 | |
| 1147 | radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1148 | atombios_set_encoder_crtc_source(encoder); |
| 1149 | |
| 1150 | if (ASIC_IS_AVIVO(rdev)) { |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1151 | if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1152 | atombios_yuv_setup(encoder, true); |
| 1153 | else |
| 1154 | atombios_yuv_setup(encoder, false); |
| 1155 | } |
| 1156 | |
| 1157 | switch (radeon_encoder->encoder_id) { |
| 1158 | case ENCODER_OBJECT_ID_INTERNAL_TMDS1: |
| 1159 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: |
| 1160 | case ENCODER_OBJECT_ID_INTERNAL_LVDS: |
| 1161 | case ENCODER_OBJECT_ID_INTERNAL_LVTM1: |
| 1162 | atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE); |
| 1163 | break; |
| 1164 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 1165 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: |
| 1166 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: |
| 1167 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: |
| 1168 | /* disable the encoder and transmitter */ |
| 1169 | atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE); |
| 1170 | atombios_dig_encoder_setup(encoder, ATOM_DISABLE); |
| 1171 | |
| 1172 | /* setup and enable the encoder and transmitter */ |
| 1173 | atombios_dig_encoder_setup(encoder, ATOM_ENABLE); |
Alex Deucher | f95a9f0 | 2009-11-05 02:21:06 -0500 | [diff] [blame] | 1174 | atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1175 | atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP); |
| 1176 | atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE); |
| 1177 | break; |
| 1178 | case ENCODER_OBJECT_ID_INTERNAL_DDI: |
| 1179 | atombios_ddia_setup(encoder, ATOM_ENABLE); |
| 1180 | break; |
| 1181 | case ENCODER_OBJECT_ID_INTERNAL_DVO1: |
| 1182 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: |
| 1183 | atombios_external_tmds_setup(encoder, ATOM_ENABLE); |
| 1184 | break; |
| 1185 | case ENCODER_OBJECT_ID_INTERNAL_DAC1: |
| 1186 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: |
| 1187 | case ENCODER_OBJECT_ID_INTERNAL_DAC2: |
| 1188 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: |
| 1189 | atombios_dac_setup(encoder, ATOM_ENABLE); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1190 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1191 | atombios_tv_setup(encoder, ATOM_ENABLE); |
| 1192 | break; |
| 1193 | } |
| 1194 | atombios_apply_encoder_quirks(encoder, adjusted_mode); |
| 1195 | } |
| 1196 | |
| 1197 | static bool |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1198 | atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1199 | { |
| 1200 | struct drm_device *dev = encoder->dev; |
| 1201 | struct radeon_device *rdev = dev->dev_private; |
| 1202 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1203 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1204 | |
| 1205 | if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | |
| 1206 | ATOM_DEVICE_CV_SUPPORT | |
| 1207 | ATOM_DEVICE_CRT_SUPPORT)) { |
| 1208 | DAC_LOAD_DETECTION_PS_ALLOCATION args; |
| 1209 | int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection); |
| 1210 | uint8_t frev, crev; |
| 1211 | |
| 1212 | memset(&args, 0, sizeof(args)); |
| 1213 | |
| 1214 | atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); |
| 1215 | |
| 1216 | args.sDacload.ucMisc = 0; |
| 1217 | |
| 1218 | if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) || |
| 1219 | (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1)) |
| 1220 | args.sDacload.ucDacType = ATOM_DAC_A; |
| 1221 | else |
| 1222 | args.sDacload.ucDacType = ATOM_DAC_B; |
| 1223 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1224 | if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1225 | args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1226 | else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1227 | args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1228 | else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1229 | args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT); |
| 1230 | if (crev >= 3) |
| 1231 | args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1232 | } else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1233 | args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT); |
| 1234 | if (crev >= 3) |
| 1235 | args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb; |
| 1236 | } |
| 1237 | |
| 1238 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 1239 | |
| 1240 | return true; |
| 1241 | } else |
| 1242 | return false; |
| 1243 | } |
| 1244 | |
| 1245 | static enum drm_connector_status |
| 1246 | radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
| 1247 | { |
| 1248 | struct drm_device *dev = encoder->dev; |
| 1249 | struct radeon_device *rdev = dev->dev_private; |
| 1250 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1251 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1252 | uint32_t bios_0_scratch; |
| 1253 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1254 | if (!atombios_dac_load_detect(encoder, connector)) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1255 | DRM_DEBUG("detect returned false \n"); |
| 1256 | return connector_status_unknown; |
| 1257 | } |
| 1258 | |
| 1259 | if (rdev->family >= CHIP_R600) |
| 1260 | bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH); |
| 1261 | else |
| 1262 | bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH); |
| 1263 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1264 | DRM_DEBUG("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices); |
| 1265 | if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1266 | if (bios_0_scratch & ATOM_S0_CRT1_MASK) |
| 1267 | return connector_status_connected; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1268 | } |
| 1269 | if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1270 | if (bios_0_scratch & ATOM_S0_CRT2_MASK) |
| 1271 | return connector_status_connected; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1272 | } |
| 1273 | if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1274 | if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A)) |
| 1275 | return connector_status_connected; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1276 | } |
| 1277 | if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1278 | if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A)) |
| 1279 | return connector_status_connected; /* CTV */ |
| 1280 | else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A)) |
| 1281 | return connector_status_connected; /* STV */ |
| 1282 | } |
| 1283 | return connector_status_disconnected; |
| 1284 | } |
| 1285 | |
| 1286 | static void radeon_atom_encoder_prepare(struct drm_encoder *encoder) |
| 1287 | { |
| 1288 | radeon_atom_output_lock(encoder, true); |
| 1289 | radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); |
| 1290 | } |
| 1291 | |
| 1292 | static void radeon_atom_encoder_commit(struct drm_encoder *encoder) |
| 1293 | { |
| 1294 | radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON); |
| 1295 | radeon_atom_output_lock(encoder, false); |
| 1296 | } |
| 1297 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1298 | static void radeon_atom_encoder_disable(struct drm_encoder *encoder) |
| 1299 | { |
| 1300 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 1301 | radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1302 | radeon_encoder->active_device = 0; |
| 1303 | } |
| 1304 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1305 | static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = { |
| 1306 | .dpms = radeon_atom_encoder_dpms, |
| 1307 | .mode_fixup = radeon_atom_mode_fixup, |
| 1308 | .prepare = radeon_atom_encoder_prepare, |
| 1309 | .mode_set = radeon_atom_encoder_mode_set, |
| 1310 | .commit = radeon_atom_encoder_commit, |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1311 | .disable = radeon_atom_encoder_disable, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1312 | /* no detect for TMDS/LVDS yet */ |
| 1313 | }; |
| 1314 | |
| 1315 | static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = { |
| 1316 | .dpms = radeon_atom_encoder_dpms, |
| 1317 | .mode_fixup = radeon_atom_mode_fixup, |
| 1318 | .prepare = radeon_atom_encoder_prepare, |
| 1319 | .mode_set = radeon_atom_encoder_mode_set, |
| 1320 | .commit = radeon_atom_encoder_commit, |
| 1321 | .detect = radeon_atom_dac_detect, |
| 1322 | }; |
| 1323 | |
| 1324 | void radeon_enc_destroy(struct drm_encoder *encoder) |
| 1325 | { |
| 1326 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 1327 | kfree(radeon_encoder->enc_priv); |
| 1328 | drm_encoder_cleanup(encoder); |
| 1329 | kfree(radeon_encoder); |
| 1330 | } |
| 1331 | |
| 1332 | static const struct drm_encoder_funcs radeon_atom_enc_funcs = { |
| 1333 | .destroy = radeon_enc_destroy, |
| 1334 | }; |
| 1335 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1336 | struct radeon_encoder_atom_dac * |
| 1337 | radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder) |
| 1338 | { |
| 1339 | struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL); |
| 1340 | |
| 1341 | if (!dac) |
| 1342 | return NULL; |
| 1343 | |
| 1344 | dac->tv_std = TV_STD_NTSC; |
| 1345 | return dac; |
| 1346 | } |
| 1347 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1348 | struct radeon_encoder_atom_dig * |
| 1349 | radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder) |
| 1350 | { |
| 1351 | struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL); |
| 1352 | |
| 1353 | if (!dig) |
| 1354 | return NULL; |
| 1355 | |
| 1356 | /* coherent mode by default */ |
| 1357 | dig->coherent_mode = true; |
| 1358 | |
| 1359 | return dig; |
| 1360 | } |
| 1361 | |
| 1362 | void |
| 1363 | radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t supported_device) |
| 1364 | { |
Dave Airlie | dfee561 | 2009-10-02 09:19:09 +1000 | [diff] [blame] | 1365 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1366 | struct drm_encoder *encoder; |
| 1367 | struct radeon_encoder *radeon_encoder; |
| 1368 | |
| 1369 | /* see if we already added it */ |
| 1370 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 1371 | radeon_encoder = to_radeon_encoder(encoder); |
| 1372 | if (radeon_encoder->encoder_id == encoder_id) { |
| 1373 | radeon_encoder->devices |= supported_device; |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | } |
| 1378 | |
| 1379 | /* add a new one */ |
| 1380 | radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL); |
| 1381 | if (!radeon_encoder) |
| 1382 | return; |
| 1383 | |
| 1384 | encoder = &radeon_encoder->base; |
Dave Airlie | dfee561 | 2009-10-02 09:19:09 +1000 | [diff] [blame] | 1385 | if (rdev->flags & RADEON_SINGLE_CRTC) |
| 1386 | encoder->possible_crtcs = 0x1; |
| 1387 | else |
| 1388 | encoder->possible_crtcs = 0x3; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1389 | |
| 1390 | radeon_encoder->enc_priv = NULL; |
| 1391 | |
| 1392 | radeon_encoder->encoder_id = encoder_id; |
| 1393 | radeon_encoder->devices = supported_device; |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1394 | radeon_encoder->rmx_type = RMX_OFF; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1395 | |
| 1396 | switch (radeon_encoder->encoder_id) { |
| 1397 | case ENCODER_OBJECT_ID_INTERNAL_LVDS: |
| 1398 | case ENCODER_OBJECT_ID_INTERNAL_TMDS1: |
| 1399 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1: |
| 1400 | case ENCODER_OBJECT_ID_INTERNAL_LVTM1: |
| 1401 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 1402 | radeon_encoder->rmx_type = RMX_FULL; |
| 1403 | drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS); |
| 1404 | radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); |
| 1405 | } else { |
| 1406 | drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS); |
| 1407 | radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); |
| 1408 | } |
| 1409 | drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); |
| 1410 | break; |
| 1411 | case ENCODER_OBJECT_ID_INTERNAL_DAC1: |
| 1412 | drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC); |
| 1413 | drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs); |
| 1414 | break; |
| 1415 | case ENCODER_OBJECT_ID_INTERNAL_DAC2: |
| 1416 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: |
| 1417 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: |
| 1418 | drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TVDAC); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1419 | radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1420 | drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs); |
| 1421 | break; |
| 1422 | case ENCODER_OBJECT_ID_INTERNAL_DVO1: |
| 1423 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: |
| 1424 | case ENCODER_OBJECT_ID_INTERNAL_DDI: |
| 1425 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: |
| 1426 | case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: |
| 1427 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: |
| 1428 | case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: |
Alex Deucher | 60d15f5 | 2009-09-08 14:22:45 -0400 | [diff] [blame] | 1429 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 1430 | radeon_encoder->rmx_type = RMX_FULL; |
| 1431 | drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS); |
| 1432 | radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); |
| 1433 | } else { |
| 1434 | drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS); |
| 1435 | radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder); |
| 1436 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1437 | drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs); |
| 1438 | break; |
| 1439 | } |
| 1440 | } |