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 <drm/drmP.h> |
| 27 | #include <drm/drm_crtc_helper.h> |
| 28 | #include <drm/radeon_drm.h> |
| 29 | #include "radeon_fixed.h" |
| 30 | #include "radeon.h" |
| 31 | #include "atom.h" |
| 32 | #include "atom-bits.h" |
| 33 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 34 | static void atombios_overscan_setup(struct drm_crtc *crtc, |
| 35 | struct drm_display_mode *mode, |
| 36 | struct drm_display_mode *adjusted_mode) |
| 37 | { |
| 38 | struct drm_device *dev = crtc->dev; |
| 39 | struct radeon_device *rdev = dev->dev_private; |
| 40 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 41 | SET_CRTC_OVERSCAN_PS_ALLOCATION args; |
| 42 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_OverScan); |
| 43 | int a1, a2; |
| 44 | |
| 45 | memset(&args, 0, sizeof(args)); |
| 46 | |
| 47 | args.usOverscanRight = 0; |
| 48 | args.usOverscanLeft = 0; |
| 49 | args.usOverscanBottom = 0; |
| 50 | args.usOverscanTop = 0; |
| 51 | args.ucCRTC = radeon_crtc->crtc_id; |
| 52 | |
| 53 | switch (radeon_crtc->rmx_type) { |
| 54 | case RMX_CENTER: |
| 55 | args.usOverscanTop = (adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2; |
| 56 | args.usOverscanBottom = (adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2; |
| 57 | args.usOverscanLeft = (adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2; |
| 58 | args.usOverscanRight = (adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2; |
| 59 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 60 | break; |
| 61 | case RMX_ASPECT: |
| 62 | a1 = mode->crtc_vdisplay * adjusted_mode->crtc_hdisplay; |
| 63 | a2 = adjusted_mode->crtc_vdisplay * mode->crtc_hdisplay; |
| 64 | |
| 65 | if (a1 > a2) { |
| 66 | args.usOverscanLeft = (adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2; |
| 67 | args.usOverscanRight = (adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2; |
| 68 | } else if (a2 > a1) { |
| 69 | args.usOverscanLeft = (adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2; |
| 70 | args.usOverscanRight = (adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2; |
| 71 | } |
| 72 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 73 | break; |
| 74 | case RMX_FULL: |
| 75 | default: |
| 76 | args.usOverscanRight = 0; |
| 77 | args.usOverscanLeft = 0; |
| 78 | args.usOverscanBottom = 0; |
| 79 | args.usOverscanTop = 0; |
| 80 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static void atombios_scaler_setup(struct drm_crtc *crtc) |
| 86 | { |
| 87 | struct drm_device *dev = crtc->dev; |
| 88 | struct radeon_device *rdev = dev->dev_private; |
| 89 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 90 | ENABLE_SCALER_PS_ALLOCATION args; |
| 91 | int index = GetIndexIntoMasterTable(COMMAND, EnableScaler); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 92 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 93 | /* fixme - fill in enc_priv for atom dac */ |
| 94 | enum radeon_tv_std tv_std = TV_STD_NTSC; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 95 | bool is_tv = false, is_cv = false; |
| 96 | struct drm_encoder *encoder; |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 97 | |
| 98 | if (!ASIC_IS_AVIVO(rdev) && radeon_crtc->crtc_id) |
| 99 | return; |
| 100 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 101 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 102 | /* find tv std */ |
| 103 | if (encoder->crtc == crtc) { |
| 104 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 105 | if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) { |
| 106 | struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv; |
| 107 | tv_std = tv_dac->tv_std; |
| 108 | is_tv = true; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 113 | memset(&args, 0, sizeof(args)); |
| 114 | |
| 115 | args.ucScaler = radeon_crtc->crtc_id; |
| 116 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 117 | if (is_tv) { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 118 | switch (tv_std) { |
| 119 | case TV_STD_NTSC: |
| 120 | default: |
| 121 | args.ucTVStandard = ATOM_TV_NTSC; |
| 122 | break; |
| 123 | case TV_STD_PAL: |
| 124 | args.ucTVStandard = ATOM_TV_PAL; |
| 125 | break; |
| 126 | case TV_STD_PAL_M: |
| 127 | args.ucTVStandard = ATOM_TV_PALM; |
| 128 | break; |
| 129 | case TV_STD_PAL_60: |
| 130 | args.ucTVStandard = ATOM_TV_PAL60; |
| 131 | break; |
| 132 | case TV_STD_NTSC_J: |
| 133 | args.ucTVStandard = ATOM_TV_NTSCJ; |
| 134 | break; |
| 135 | case TV_STD_SCART_PAL: |
| 136 | args.ucTVStandard = ATOM_TV_PAL; /* ??? */ |
| 137 | break; |
| 138 | case TV_STD_SECAM: |
| 139 | args.ucTVStandard = ATOM_TV_SECAM; |
| 140 | break; |
| 141 | case TV_STD_PAL_CN: |
| 142 | args.ucTVStandard = ATOM_TV_PALCN; |
| 143 | break; |
| 144 | } |
| 145 | args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 146 | } else if (is_cv) { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 147 | args.ucTVStandard = ATOM_TV_CV; |
| 148 | args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; |
| 149 | } else { |
| 150 | switch (radeon_crtc->rmx_type) { |
| 151 | case RMX_FULL: |
| 152 | args.ucEnable = ATOM_SCALER_EXPANSION; |
| 153 | break; |
| 154 | case RMX_CENTER: |
| 155 | args.ucEnable = ATOM_SCALER_CENTER; |
| 156 | break; |
| 157 | case RMX_ASPECT: |
| 158 | args.ucEnable = ATOM_SCALER_EXPANSION; |
| 159 | break; |
| 160 | default: |
| 161 | if (ASIC_IS_AVIVO(rdev)) |
| 162 | args.ucEnable = ATOM_SCALER_DISABLE; |
| 163 | else |
| 164 | args.ucEnable = ATOM_SCALER_CENTER; |
| 165 | break; |
| 166 | } |
| 167 | } |
| 168 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 169 | if ((is_tv || is_cv) |
| 170 | && rdev->family >= CHIP_RV515 && rdev->family <= CHIP_R580) { |
| 171 | atom_rv515_force_tv_scaler(rdev, radeon_crtc); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 175 | static void atombios_lock_crtc(struct drm_crtc *crtc, int lock) |
| 176 | { |
| 177 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 178 | struct drm_device *dev = crtc->dev; |
| 179 | struct radeon_device *rdev = dev->dev_private; |
| 180 | int index = |
| 181 | GetIndexIntoMasterTable(COMMAND, UpdateCRTC_DoubleBufferRegisters); |
| 182 | ENABLE_CRTC_PS_ALLOCATION args; |
| 183 | |
| 184 | memset(&args, 0, sizeof(args)); |
| 185 | |
| 186 | args.ucCRTC = radeon_crtc->crtc_id; |
| 187 | args.ucEnable = lock; |
| 188 | |
| 189 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 190 | } |
| 191 | |
| 192 | static void atombios_enable_crtc(struct drm_crtc *crtc, int state) |
| 193 | { |
| 194 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 195 | struct drm_device *dev = crtc->dev; |
| 196 | struct radeon_device *rdev = dev->dev_private; |
| 197 | int index = GetIndexIntoMasterTable(COMMAND, EnableCRTC); |
| 198 | ENABLE_CRTC_PS_ALLOCATION args; |
| 199 | |
| 200 | memset(&args, 0, sizeof(args)); |
| 201 | |
| 202 | args.ucCRTC = radeon_crtc->crtc_id; |
| 203 | args.ucEnable = state; |
| 204 | |
| 205 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 206 | } |
| 207 | |
| 208 | static void atombios_enable_crtc_memreq(struct drm_crtc *crtc, int state) |
| 209 | { |
| 210 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 211 | struct drm_device *dev = crtc->dev; |
| 212 | struct radeon_device *rdev = dev->dev_private; |
| 213 | int index = GetIndexIntoMasterTable(COMMAND, EnableCRTCMemReq); |
| 214 | ENABLE_CRTC_PS_ALLOCATION args; |
| 215 | |
| 216 | memset(&args, 0, sizeof(args)); |
| 217 | |
| 218 | args.ucCRTC = radeon_crtc->crtc_id; |
| 219 | args.ucEnable = state; |
| 220 | |
| 221 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 222 | } |
| 223 | |
| 224 | static void atombios_blank_crtc(struct drm_crtc *crtc, int state) |
| 225 | { |
| 226 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 227 | struct drm_device *dev = crtc->dev; |
| 228 | struct radeon_device *rdev = dev->dev_private; |
| 229 | int index = GetIndexIntoMasterTable(COMMAND, BlankCRTC); |
| 230 | BLANK_CRTC_PS_ALLOCATION args; |
| 231 | |
| 232 | memset(&args, 0, sizeof(args)); |
| 233 | |
| 234 | args.ucCRTC = radeon_crtc->crtc_id; |
| 235 | args.ucBlanking = state; |
| 236 | |
| 237 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 238 | } |
| 239 | |
| 240 | void atombios_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 241 | { |
| 242 | struct drm_device *dev = crtc->dev; |
| 243 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 500b758 | 2009-12-02 11:46:52 -0500 | [diff] [blame] | 244 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 245 | |
| 246 | switch (mode) { |
| 247 | case DRM_MODE_DPMS_ON: |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 248 | atombios_enable_crtc(crtc, ATOM_ENABLE); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 249 | if (ASIC_IS_DCE3(rdev)) |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 250 | atombios_enable_crtc_memreq(crtc, ATOM_ENABLE); |
| 251 | atombios_blank_crtc(crtc, ATOM_DISABLE); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 252 | drm_vblank_post_modeset(dev, radeon_crtc->crtc_id); |
Alex Deucher | 500b758 | 2009-12-02 11:46:52 -0500 | [diff] [blame] | 253 | radeon_crtc_load_lut(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 254 | break; |
| 255 | case DRM_MODE_DPMS_STANDBY: |
| 256 | case DRM_MODE_DPMS_SUSPEND: |
| 257 | case DRM_MODE_DPMS_OFF: |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 258 | drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id); |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 259 | atombios_blank_crtc(crtc, ATOM_ENABLE); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 260 | if (ASIC_IS_DCE3(rdev)) |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 261 | atombios_enable_crtc_memreq(crtc, ATOM_DISABLE); |
| 262 | atombios_enable_crtc(crtc, ATOM_DISABLE); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 263 | break; |
| 264 | } |
Alex Deucher | 03214bd | 2010-03-16 17:42:46 -0400 | [diff] [blame^] | 265 | |
| 266 | /* adjust pm to dpms change */ |
| 267 | radeon_pm_compute_clocks(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static void |
| 271 | atombios_set_crtc_dtd_timing(struct drm_crtc *crtc, |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 272 | struct drm_display_mode *mode) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 273 | { |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 274 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 275 | struct drm_device *dev = crtc->dev; |
| 276 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 277 | SET_CRTC_USING_DTD_TIMING_PARAMETERS args; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 278 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_UsingDTDTiming); |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 279 | u16 misc = 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 280 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 281 | memset(&args, 0, sizeof(args)); |
| 282 | args.usH_Size = cpu_to_le16(mode->crtc_hdisplay); |
| 283 | args.usH_Blanking_Time = |
| 284 | cpu_to_le16(mode->crtc_hblank_end - mode->crtc_hdisplay); |
| 285 | args.usV_Size = cpu_to_le16(mode->crtc_vdisplay); |
| 286 | args.usV_Blanking_Time = |
| 287 | cpu_to_le16(mode->crtc_vblank_end - mode->crtc_vdisplay); |
| 288 | args.usH_SyncOffset = |
| 289 | cpu_to_le16(mode->crtc_hsync_start - mode->crtc_hdisplay); |
| 290 | args.usH_SyncWidth = |
| 291 | cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); |
| 292 | args.usV_SyncOffset = |
| 293 | cpu_to_le16(mode->crtc_vsync_start - mode->crtc_vdisplay); |
| 294 | args.usV_SyncWidth = |
| 295 | cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); |
| 296 | /*args.ucH_Border = mode->hborder;*/ |
| 297 | /*args.ucV_Border = mode->vborder;*/ |
| 298 | |
| 299 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 300 | misc |= ATOM_VSYNC_POLARITY; |
| 301 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 302 | misc |= ATOM_HSYNC_POLARITY; |
| 303 | if (mode->flags & DRM_MODE_FLAG_CSYNC) |
| 304 | misc |= ATOM_COMPOSITESYNC; |
| 305 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 306 | misc |= ATOM_INTERLACE; |
| 307 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 308 | misc |= ATOM_DOUBLE_CLOCK_MODE; |
| 309 | |
| 310 | args.susModeMiscInfo.usAccess = cpu_to_le16(misc); |
| 311 | args.ucCRTC = radeon_crtc->crtc_id; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 312 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 313 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 316 | static void atombios_crtc_set_timing(struct drm_crtc *crtc, |
| 317 | struct drm_display_mode *mode) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 318 | { |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 319 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 320 | struct drm_device *dev = crtc->dev; |
| 321 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 322 | SET_CRTC_TIMING_PARAMETERS_PS_ALLOCATION args; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 323 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_Timing); |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 324 | u16 misc = 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 325 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 326 | memset(&args, 0, sizeof(args)); |
| 327 | args.usH_Total = cpu_to_le16(mode->crtc_htotal); |
| 328 | args.usH_Disp = cpu_to_le16(mode->crtc_hdisplay); |
| 329 | args.usH_SyncStart = cpu_to_le16(mode->crtc_hsync_start); |
| 330 | args.usH_SyncWidth = |
| 331 | cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); |
| 332 | args.usV_Total = cpu_to_le16(mode->crtc_vtotal); |
| 333 | args.usV_Disp = cpu_to_le16(mode->crtc_vdisplay); |
| 334 | args.usV_SyncStart = cpu_to_le16(mode->crtc_vsync_start); |
| 335 | args.usV_SyncWidth = |
| 336 | cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); |
| 337 | |
| 338 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 339 | misc |= ATOM_VSYNC_POLARITY; |
| 340 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 341 | misc |= ATOM_HSYNC_POLARITY; |
| 342 | if (mode->flags & DRM_MODE_FLAG_CSYNC) |
| 343 | misc |= ATOM_COMPOSITESYNC; |
| 344 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 345 | misc |= ATOM_INTERLACE; |
| 346 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 347 | misc |= ATOM_DOUBLE_CLOCK_MODE; |
| 348 | |
| 349 | args.susModeMiscInfo.usAccess = cpu_to_le16(misc); |
| 350 | args.ucCRTC = radeon_crtc->crtc_id; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 351 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 352 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 353 | } |
| 354 | |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 355 | static void atombios_disable_ss(struct drm_crtc *crtc) |
| 356 | { |
| 357 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 358 | struct drm_device *dev = crtc->dev; |
| 359 | struct radeon_device *rdev = dev->dev_private; |
| 360 | u32 ss_cntl; |
| 361 | |
| 362 | if (ASIC_IS_DCE4(rdev)) { |
| 363 | switch (radeon_crtc->pll_id) { |
| 364 | case ATOM_PPLL1: |
| 365 | ss_cntl = RREG32(EVERGREEN_P1PLL_SS_CNTL); |
| 366 | ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; |
| 367 | WREG32(EVERGREEN_P1PLL_SS_CNTL, ss_cntl); |
| 368 | break; |
| 369 | case ATOM_PPLL2: |
| 370 | ss_cntl = RREG32(EVERGREEN_P2PLL_SS_CNTL); |
| 371 | ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; |
| 372 | WREG32(EVERGREEN_P2PLL_SS_CNTL, ss_cntl); |
| 373 | break; |
| 374 | case ATOM_DCPLL: |
| 375 | case ATOM_PPLL_INVALID: |
| 376 | return; |
| 377 | } |
| 378 | } else if (ASIC_IS_AVIVO(rdev)) { |
| 379 | switch (radeon_crtc->pll_id) { |
| 380 | case ATOM_PPLL1: |
| 381 | ss_cntl = RREG32(AVIVO_P1PLL_INT_SS_CNTL); |
| 382 | ss_cntl &= ~1; |
| 383 | WREG32(AVIVO_P1PLL_INT_SS_CNTL, ss_cntl); |
| 384 | break; |
| 385 | case ATOM_PPLL2: |
| 386 | ss_cntl = RREG32(AVIVO_P2PLL_INT_SS_CNTL); |
| 387 | ss_cntl &= ~1; |
| 388 | WREG32(AVIVO_P2PLL_INT_SS_CNTL, ss_cntl); |
| 389 | break; |
| 390 | case ATOM_DCPLL: |
| 391 | case ATOM_PPLL_INVALID: |
| 392 | return; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 398 | union atom_enable_ss { |
| 399 | ENABLE_LVDS_SS_PARAMETERS legacy; |
| 400 | ENABLE_SPREAD_SPECTRUM_ON_PPLL_PS_ALLOCATION v1; |
| 401 | }; |
| 402 | |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 403 | static void atombios_enable_ss(struct drm_crtc *crtc) |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 404 | { |
| 405 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 406 | struct drm_device *dev = crtc->dev; |
| 407 | struct radeon_device *rdev = dev->dev_private; |
| 408 | struct drm_encoder *encoder = NULL; |
| 409 | struct radeon_encoder *radeon_encoder = NULL; |
| 410 | struct radeon_encoder_atom_dig *dig = NULL; |
| 411 | int index = GetIndexIntoMasterTable(COMMAND, EnableSpreadSpectrumOnPPLL); |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 412 | union atom_enable_ss args; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 413 | uint16_t percentage = 0; |
| 414 | uint8_t type = 0, step = 0, delay = 0, range = 0; |
| 415 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 416 | /* XXX add ss support for DCE4 */ |
| 417 | if (ASIC_IS_DCE4(rdev)) |
| 418 | return; |
| 419 | |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 420 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 421 | if (encoder->crtc == crtc) { |
| 422 | radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 423 | /* only enable spread spectrum on LVDS */ |
Alex Deucher | d11aa88 | 2009-10-28 00:51:20 -0400 | [diff] [blame] | 424 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 425 | dig = radeon_encoder->enc_priv; |
| 426 | if (dig && dig->ss) { |
| 427 | percentage = dig->ss->percentage; |
| 428 | type = dig->ss->type; |
| 429 | step = dig->ss->step; |
| 430 | delay = dig->ss->delay; |
| 431 | range = dig->ss->range; |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 432 | } else |
Alex Deucher | d11aa88 | 2009-10-28 00:51:20 -0400 | [diff] [blame] | 433 | return; |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 434 | } else |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 435 | return; |
| 436 | break; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | if (!radeon_encoder) |
| 441 | return; |
| 442 | |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 443 | memset(&args, 0, sizeof(args)); |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 444 | if (ASIC_IS_AVIVO(rdev)) { |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 445 | args.v1.usSpreadSpectrumPercentage = cpu_to_le16(percentage); |
| 446 | args.v1.ucSpreadSpectrumType = type; |
| 447 | args.v1.ucSpreadSpectrumStep = step; |
| 448 | args.v1.ucSpreadSpectrumDelay = delay; |
| 449 | args.v1.ucSpreadSpectrumRange = range; |
| 450 | args.v1.ucPpll = radeon_crtc->crtc_id ? ATOM_PPLL2 : ATOM_PPLL1; |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 451 | args.v1.ucEnable = ATOM_ENABLE; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 452 | } else { |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 453 | args.legacy.usSpreadSpectrumPercentage = cpu_to_le16(percentage); |
| 454 | args.legacy.ucSpreadSpectrumType = type; |
| 455 | args.legacy.ucSpreadSpectrumStepSize_Delay = (step & 3) << 2; |
| 456 | args.legacy.ucSpreadSpectrumStepSize_Delay |= (delay & 7) << 4; |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 457 | args.legacy.ucEnable = ATOM_ENABLE; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 458 | } |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 459 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 460 | } |
| 461 | |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 462 | union adjust_pixel_clock { |
| 463 | ADJUST_DISPLAY_PLL_PS_ALLOCATION v1; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 464 | ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3 v3; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 465 | }; |
| 466 | |
| 467 | static u32 atombios_adjust_pll(struct drm_crtc *crtc, |
| 468 | struct drm_display_mode *mode, |
| 469 | struct radeon_pll *pll) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 470 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 471 | struct drm_device *dev = crtc->dev; |
| 472 | struct radeon_device *rdev = dev->dev_private; |
| 473 | struct drm_encoder *encoder = NULL; |
| 474 | struct radeon_encoder *radeon_encoder = NULL; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 475 | u32 adjusted_clock = mode->clock; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 476 | int encoder_mode = 0; |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 477 | |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 478 | /* reset the pll flags */ |
| 479 | pll->flags = 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 480 | |
Alex Deucher | 7c27f87 | 2010-02-02 12:05:01 -0500 | [diff] [blame] | 481 | /* select the PLL algo */ |
| 482 | if (ASIC_IS_AVIVO(rdev)) { |
Alex Deucher | 383be5d | 2010-02-23 03:24:38 -0500 | [diff] [blame] | 483 | if (radeon_new_pll == 0) |
| 484 | pll->algo = PLL_ALGO_LEGACY; |
| 485 | else |
| 486 | pll->algo = PLL_ALGO_NEW; |
| 487 | } else { |
| 488 | if (radeon_new_pll == 1) |
| 489 | pll->algo = PLL_ALGO_NEW; |
Alex Deucher | 7c27f87 | 2010-02-02 12:05:01 -0500 | [diff] [blame] | 490 | else |
| 491 | pll->algo = PLL_ALGO_LEGACY; |
Alex Deucher | 383be5d | 2010-02-23 03:24:38 -0500 | [diff] [blame] | 492 | } |
Alex Deucher | 7c27f87 | 2010-02-02 12:05:01 -0500 | [diff] [blame] | 493 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 494 | if (ASIC_IS_AVIVO(rdev)) { |
Alex Deucher | eb1300b | 2009-07-13 11:09:56 -0400 | [diff] [blame] | 495 | if ((rdev->family == CHIP_RS600) || |
| 496 | (rdev->family == CHIP_RS690) || |
| 497 | (rdev->family == CHIP_RS740)) |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 498 | pll->flags |= (RADEON_PLL_USE_FRAC_FB_DIV | |
| 499 | RADEON_PLL_PREFER_CLOSEST_LOWER); |
Alex Deucher | eb1300b | 2009-07-13 11:09:56 -0400 | [diff] [blame] | 500 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 501 | if (ASIC_IS_DCE32(rdev) && mode->clock > 200000) /* range limits??? */ |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 502 | pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 503 | else |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 504 | pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 505 | } else { |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 506 | pll->flags |= RADEON_PLL_LEGACY; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 507 | |
| 508 | if (mode->clock > 200000) /* range limits??? */ |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 509 | pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 510 | else |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 511 | pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 512 | |
| 513 | } |
| 514 | |
| 515 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 516 | if (encoder->crtc == crtc) { |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 517 | radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 518 | encoder_mode = atombios_get_encoder_mode(encoder); |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 519 | if (ASIC_IS_AVIVO(rdev)) { |
| 520 | /* DVO wants 2x pixel clock if the DVO chip is in 12 bit mode */ |
| 521 | if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1) |
| 522 | adjusted_clock = mode->clock * 2; |
Alex Deucher | a1a4b23 | 2010-04-09 15:31:56 -0400 | [diff] [blame] | 523 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) { |
| 524 | pll->algo = PLL_ALGO_LEGACY; |
| 525 | pll->flags |= RADEON_PLL_PREFER_CLOSEST_LOWER; |
| 526 | } |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 527 | } else { |
| 528 | if (encoder->encoder_type != DRM_MODE_ENCODER_DAC) |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 529 | pll->flags |= RADEON_PLL_NO_ODD_POST_DIV; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 530 | if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS) |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 531 | pll->flags |= RADEON_PLL_USE_REF_DIV; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 532 | } |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 533 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
Alex Deucher | 2606c88 | 2009-10-08 13:36:21 -0400 | [diff] [blame] | 537 | /* DCE3+ has an AdjustDisplayPll that will adjust the pixel clock |
| 538 | * accordingly based on the encoder/transmitter to work around |
| 539 | * special hw requirements. |
| 540 | */ |
| 541 | if (ASIC_IS_DCE3(rdev)) { |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 542 | union adjust_pixel_clock args; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 543 | u8 frev, crev; |
| 544 | int index; |
Alex Deucher | 2606c88 | 2009-10-08 13:36:21 -0400 | [diff] [blame] | 545 | |
Alex Deucher | 2606c88 | 2009-10-08 13:36:21 -0400 | [diff] [blame] | 546 | index = GetIndexIntoMasterTable(COMMAND, AdjustDisplayPll); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 547 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
| 548 | &crev)) |
| 549 | return adjusted_clock; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 550 | |
| 551 | memset(&args, 0, sizeof(args)); |
| 552 | |
| 553 | switch (frev) { |
| 554 | case 1: |
| 555 | switch (crev) { |
| 556 | case 1: |
| 557 | case 2: |
| 558 | args.v1.usPixelClock = cpu_to_le16(mode->clock / 10); |
| 559 | args.v1.ucTransmitterID = radeon_encoder->encoder_id; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 560 | args.v1.ucEncodeMode = encoder_mode; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 561 | |
| 562 | atom_execute_table(rdev->mode_info.atom_context, |
| 563 | index, (uint32_t *)&args); |
| 564 | adjusted_clock = le16_to_cpu(args.v1.usPixelClock) * 10; |
| 565 | break; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 566 | case 3: |
| 567 | args.v3.sInput.usPixelClock = cpu_to_le16(mode->clock / 10); |
| 568 | args.v3.sInput.ucTransmitterID = radeon_encoder->encoder_id; |
| 569 | args.v3.sInput.ucEncodeMode = encoder_mode; |
| 570 | args.v3.sInput.ucDispPllConfig = 0; |
| 571 | if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { |
| 572 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 573 | |
| 574 | if (encoder_mode == ATOM_ENCODER_MODE_DP) |
| 575 | args.v3.sInput.ucDispPllConfig |= |
| 576 | DISPPLL_CONFIG_COHERENT_MODE; |
| 577 | else { |
| 578 | if (dig->coherent_mode) |
| 579 | args.v3.sInput.ucDispPllConfig |= |
| 580 | DISPPLL_CONFIG_COHERENT_MODE; |
| 581 | if (mode->clock > 165000) |
| 582 | args.v3.sInput.ucDispPllConfig |= |
| 583 | DISPPLL_CONFIG_DUAL_LINK; |
| 584 | } |
| 585 | } else if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 586 | /* may want to enable SS on DP/eDP eventually */ |
Alex Deucher | 9f998ad | 2010-03-29 21:37:08 -0400 | [diff] [blame] | 587 | /*args.v3.sInput.ucDispPllConfig |= |
| 588 | DISPPLL_CONFIG_SS_ENABLE;*/ |
| 589 | if (encoder_mode == ATOM_ENCODER_MODE_DP) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 590 | args.v3.sInput.ucDispPllConfig |= |
Alex Deucher | 9f998ad | 2010-03-29 21:37:08 -0400 | [diff] [blame] | 591 | DISPPLL_CONFIG_COHERENT_MODE; |
| 592 | else { |
| 593 | if (mode->clock > 165000) |
| 594 | args.v3.sInput.ucDispPllConfig |= |
| 595 | DISPPLL_CONFIG_DUAL_LINK; |
| 596 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 597 | } |
| 598 | atom_execute_table(rdev->mode_info.atom_context, |
| 599 | index, (uint32_t *)&args); |
| 600 | adjusted_clock = le32_to_cpu(args.v3.sOutput.ulDispPllFreq) * 10; |
| 601 | if (args.v3.sOutput.ucRefDiv) { |
| 602 | pll->flags |= RADEON_PLL_USE_REF_DIV; |
| 603 | pll->reference_div = args.v3.sOutput.ucRefDiv; |
| 604 | } |
| 605 | if (args.v3.sOutput.ucPostDiv) { |
| 606 | pll->flags |= RADEON_PLL_USE_POST_DIV; |
| 607 | pll->post_div = args.v3.sOutput.ucPostDiv; |
| 608 | } |
| 609 | break; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 610 | default: |
| 611 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 612 | return adjusted_clock; |
| 613 | } |
| 614 | break; |
| 615 | default: |
| 616 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 617 | return adjusted_clock; |
| 618 | } |
Alex Deucher | d56ef9c | 2009-10-27 12:11:09 -0400 | [diff] [blame] | 619 | } |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 620 | return adjusted_clock; |
| 621 | } |
| 622 | |
| 623 | union set_pixel_clock { |
| 624 | SET_PIXEL_CLOCK_PS_ALLOCATION base; |
| 625 | PIXEL_CLOCK_PARAMETERS v1; |
| 626 | PIXEL_CLOCK_PARAMETERS_V2 v2; |
| 627 | PIXEL_CLOCK_PARAMETERS_V3 v3; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 628 | PIXEL_CLOCK_PARAMETERS_V5 v5; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 629 | }; |
| 630 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 631 | static void atombios_crtc_set_dcpll(struct drm_crtc *crtc) |
| 632 | { |
| 633 | struct drm_device *dev = crtc->dev; |
| 634 | struct radeon_device *rdev = dev->dev_private; |
| 635 | u8 frev, crev; |
| 636 | int index; |
| 637 | union set_pixel_clock args; |
| 638 | |
| 639 | memset(&args, 0, sizeof(args)); |
| 640 | |
| 641 | index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 642 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
| 643 | &crev)) |
| 644 | return; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 645 | |
| 646 | switch (frev) { |
| 647 | case 1: |
| 648 | switch (crev) { |
| 649 | case 5: |
| 650 | /* if the default dcpll clock is specified, |
| 651 | * SetPixelClock provides the dividers |
| 652 | */ |
| 653 | args.v5.ucCRTC = ATOM_CRTC_INVALID; |
| 654 | args.v5.usPixelClock = rdev->clock.default_dispclk; |
| 655 | args.v5.ucPpll = ATOM_DCPLL; |
| 656 | break; |
| 657 | default: |
| 658 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 659 | return; |
| 660 | } |
| 661 | break; |
| 662 | default: |
| 663 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 664 | return; |
| 665 | } |
| 666 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 667 | } |
| 668 | |
| 669 | static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 670 | { |
| 671 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 672 | struct drm_device *dev = crtc->dev; |
| 673 | struct radeon_device *rdev = dev->dev_private; |
| 674 | struct drm_encoder *encoder = NULL; |
| 675 | struct radeon_encoder *radeon_encoder = NULL; |
| 676 | u8 frev, crev; |
| 677 | int index; |
| 678 | union set_pixel_clock args; |
| 679 | u32 pll_clock = mode->clock; |
| 680 | u32 ref_div = 0, fb_div = 0, frac_fb_div = 0, post_div = 0; |
| 681 | struct radeon_pll *pll; |
| 682 | u32 adjusted_clock; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 683 | int encoder_mode = 0; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 684 | |
| 685 | memset(&args, 0, sizeof(args)); |
| 686 | |
| 687 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 688 | if (encoder->crtc == crtc) { |
| 689 | radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 690 | encoder_mode = atombios_get_encoder_mode(encoder); |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 691 | break; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | if (!radeon_encoder) |
| 696 | return; |
| 697 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 698 | switch (radeon_crtc->pll_id) { |
| 699 | case ATOM_PPLL1: |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 700 | pll = &rdev->clock.p1pll; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 701 | break; |
| 702 | case ATOM_PPLL2: |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 703 | pll = &rdev->clock.p2pll; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 704 | break; |
| 705 | case ATOM_DCPLL: |
| 706 | case ATOM_PPLL_INVALID: |
| 707 | pll = &rdev->clock.dcpll; |
| 708 | break; |
| 709 | } |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 710 | |
| 711 | /* adjust pixel clock as needed */ |
| 712 | adjusted_clock = atombios_adjust_pll(crtc, mode, pll); |
Alex Deucher | 2606c88 | 2009-10-08 13:36:21 -0400 | [diff] [blame] | 713 | |
Alex Deucher | 7c27f87 | 2010-02-02 12:05:01 -0500 | [diff] [blame] | 714 | radeon_compute_pll(pll, adjusted_clock, &pll_clock, &fb_div, &frac_fb_div, |
| 715 | &ref_div, &post_div); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 716 | |
Dave Airlie | 39deb2d | 2009-10-12 14:21:19 +1000 | [diff] [blame] | 717 | index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 718 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
| 719 | &crev)) |
| 720 | return; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 721 | |
| 722 | switch (frev) { |
| 723 | case 1: |
| 724 | switch (crev) { |
| 725 | case 1: |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 726 | args.v1.usPixelClock = cpu_to_le16(mode->clock / 10); |
| 727 | args.v1.usRefDiv = cpu_to_le16(ref_div); |
| 728 | args.v1.usFbDiv = cpu_to_le16(fb_div); |
| 729 | args.v1.ucFracFbDiv = frac_fb_div; |
| 730 | args.v1.ucPostDiv = post_div; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 731 | args.v1.ucPpll = radeon_crtc->pll_id; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 732 | args.v1.ucCRTC = radeon_crtc->crtc_id; |
| 733 | args.v1.ucRefDivSrc = 1; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 734 | break; |
| 735 | case 2: |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 736 | args.v2.usPixelClock = cpu_to_le16(mode->clock / 10); |
| 737 | args.v2.usRefDiv = cpu_to_le16(ref_div); |
| 738 | args.v2.usFbDiv = cpu_to_le16(fb_div); |
| 739 | args.v2.ucFracFbDiv = frac_fb_div; |
| 740 | args.v2.ucPostDiv = post_div; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 741 | args.v2.ucPpll = radeon_crtc->pll_id; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 742 | args.v2.ucCRTC = radeon_crtc->crtc_id; |
| 743 | args.v2.ucRefDivSrc = 1; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 744 | break; |
| 745 | case 3: |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 746 | args.v3.usPixelClock = cpu_to_le16(mode->clock / 10); |
| 747 | args.v3.usRefDiv = cpu_to_le16(ref_div); |
| 748 | args.v3.usFbDiv = cpu_to_le16(fb_div); |
| 749 | args.v3.ucFracFbDiv = frac_fb_div; |
| 750 | args.v3.ucPostDiv = post_div; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 751 | args.v3.ucPpll = radeon_crtc->pll_id; |
| 752 | args.v3.ucMiscInfo = (radeon_crtc->pll_id << 2); |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 753 | args.v3.ucTransmitterId = radeon_encoder->encoder_id; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 754 | args.v3.ucEncoderMode = encoder_mode; |
| 755 | break; |
| 756 | case 5: |
| 757 | args.v5.ucCRTC = radeon_crtc->crtc_id; |
| 758 | args.v5.usPixelClock = cpu_to_le16(mode->clock / 10); |
| 759 | args.v5.ucRefDiv = ref_div; |
| 760 | args.v5.usFbDiv = cpu_to_le16(fb_div); |
| 761 | args.v5.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); |
| 762 | args.v5.ucPostDiv = post_div; |
| 763 | args.v5.ucMiscInfo = 0; /* HDMI depth, etc. */ |
| 764 | args.v5.ucTransmitterID = radeon_encoder->encoder_id; |
| 765 | args.v5.ucEncoderMode = encoder_mode; |
| 766 | args.v5.ucPpll = radeon_crtc->pll_id; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 767 | break; |
| 768 | default: |
| 769 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 770 | return; |
| 771 | } |
| 772 | break; |
| 773 | default: |
| 774 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 775 | return; |
| 776 | } |
| 777 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 778 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 779 | } |
| 780 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 781 | static int evergreen_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
| 782 | struct drm_framebuffer *old_fb) |
| 783 | { |
| 784 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 785 | struct drm_device *dev = crtc->dev; |
| 786 | struct radeon_device *rdev = dev->dev_private; |
| 787 | struct radeon_framebuffer *radeon_fb; |
| 788 | struct drm_gem_object *obj; |
| 789 | struct radeon_bo *rbo; |
| 790 | uint64_t fb_location; |
| 791 | uint32_t fb_format, fb_pitch_pixels, tiling_flags; |
| 792 | int r; |
| 793 | |
| 794 | /* no fb bound */ |
| 795 | if (!crtc->fb) { |
| 796 | DRM_DEBUG("No FB bound\n"); |
| 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | radeon_fb = to_radeon_framebuffer(crtc->fb); |
| 801 | |
| 802 | /* Pin framebuffer & get tilling informations */ |
| 803 | obj = radeon_fb->obj; |
| 804 | rbo = obj->driver_private; |
| 805 | r = radeon_bo_reserve(rbo, false); |
| 806 | if (unlikely(r != 0)) |
| 807 | return r; |
| 808 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); |
| 809 | if (unlikely(r != 0)) { |
| 810 | radeon_bo_unreserve(rbo); |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); |
| 814 | radeon_bo_unreserve(rbo); |
| 815 | |
| 816 | switch (crtc->fb->bits_per_pixel) { |
| 817 | case 8: |
| 818 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_8BPP) | |
| 819 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_INDEXED)); |
| 820 | break; |
| 821 | case 15: |
| 822 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | |
| 823 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB1555)); |
| 824 | break; |
| 825 | case 16: |
| 826 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | |
| 827 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB565)); |
| 828 | break; |
| 829 | case 24: |
| 830 | case 32: |
| 831 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) | |
| 832 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB8888)); |
| 833 | break; |
| 834 | default: |
| 835 | DRM_ERROR("Unsupported screen depth %d\n", |
| 836 | crtc->fb->bits_per_pixel); |
| 837 | return -EINVAL; |
| 838 | } |
| 839 | |
| 840 | switch (radeon_crtc->crtc_id) { |
| 841 | case 0: |
| 842 | WREG32(AVIVO_D1VGA_CONTROL, 0); |
| 843 | break; |
| 844 | case 1: |
| 845 | WREG32(AVIVO_D2VGA_CONTROL, 0); |
| 846 | break; |
| 847 | case 2: |
| 848 | WREG32(EVERGREEN_D3VGA_CONTROL, 0); |
| 849 | break; |
| 850 | case 3: |
| 851 | WREG32(EVERGREEN_D4VGA_CONTROL, 0); |
| 852 | break; |
| 853 | case 4: |
| 854 | WREG32(EVERGREEN_D5VGA_CONTROL, 0); |
| 855 | break; |
| 856 | case 5: |
| 857 | WREG32(EVERGREEN_D6VGA_CONTROL, 0); |
| 858 | break; |
| 859 | default: |
| 860 | break; |
| 861 | } |
| 862 | |
| 863 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, |
| 864 | upper_32_bits(fb_location)); |
| 865 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, |
| 866 | upper_32_bits(fb_location)); |
| 867 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 868 | (u32)fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); |
| 869 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 870 | (u32) fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); |
| 871 | WREG32(EVERGREEN_GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); |
| 872 | |
| 873 | WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); |
| 874 | WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); |
| 875 | WREG32(EVERGREEN_GRPH_X_START + radeon_crtc->crtc_offset, 0); |
| 876 | WREG32(EVERGREEN_GRPH_Y_START + radeon_crtc->crtc_offset, 0); |
| 877 | WREG32(EVERGREEN_GRPH_X_END + radeon_crtc->crtc_offset, crtc->fb->width); |
| 878 | WREG32(EVERGREEN_GRPH_Y_END + radeon_crtc->crtc_offset, crtc->fb->height); |
| 879 | |
| 880 | fb_pitch_pixels = crtc->fb->pitch / (crtc->fb->bits_per_pixel / 8); |
| 881 | WREG32(EVERGREEN_GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); |
| 882 | WREG32(EVERGREEN_GRPH_ENABLE + radeon_crtc->crtc_offset, 1); |
| 883 | |
| 884 | WREG32(EVERGREEN_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, |
| 885 | crtc->mode.vdisplay); |
| 886 | x &= ~3; |
| 887 | y &= ~1; |
| 888 | WREG32(EVERGREEN_VIEWPORT_START + radeon_crtc->crtc_offset, |
| 889 | (x << 16) | y); |
| 890 | WREG32(EVERGREEN_VIEWPORT_SIZE + radeon_crtc->crtc_offset, |
| 891 | (crtc->mode.hdisplay << 16) | crtc->mode.vdisplay); |
| 892 | |
| 893 | if (crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) |
| 894 | WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, |
| 895 | EVERGREEN_INTERLEAVE_EN); |
| 896 | else |
| 897 | WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0); |
| 898 | |
| 899 | if (old_fb && old_fb != crtc->fb) { |
| 900 | radeon_fb = to_radeon_framebuffer(old_fb); |
| 901 | rbo = radeon_fb->obj->driver_private; |
| 902 | r = radeon_bo_reserve(rbo, false); |
| 903 | if (unlikely(r != 0)) |
| 904 | return r; |
| 905 | radeon_bo_unpin(rbo); |
| 906 | radeon_bo_unreserve(rbo); |
| 907 | } |
| 908 | |
| 909 | /* Bytes per pixel may have changed */ |
| 910 | radeon_bandwidth_update(rdev); |
| 911 | |
| 912 | return 0; |
| 913 | } |
| 914 | |
Alex Deucher | 54f088a | 2010-01-19 16:34:01 -0500 | [diff] [blame] | 915 | static int avivo_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
| 916 | struct drm_framebuffer *old_fb) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 917 | { |
| 918 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 919 | struct drm_device *dev = crtc->dev; |
| 920 | struct radeon_device *rdev = dev->dev_private; |
| 921 | struct radeon_framebuffer *radeon_fb; |
| 922 | struct drm_gem_object *obj; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 923 | struct radeon_bo *rbo; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 924 | uint64_t fb_location; |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 925 | uint32_t fb_format, fb_pitch_pixels, tiling_flags; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 926 | int r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 927 | |
Jerome Glisse | 2de3b48 | 2009-11-17 14:08:55 -0800 | [diff] [blame] | 928 | /* no fb bound */ |
| 929 | if (!crtc->fb) { |
| 930 | DRM_DEBUG("No FB bound\n"); |
| 931 | return 0; |
| 932 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 933 | |
| 934 | radeon_fb = to_radeon_framebuffer(crtc->fb); |
| 935 | |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 936 | /* Pin framebuffer & get tilling informations */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 937 | obj = radeon_fb->obj; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 938 | rbo = obj->driver_private; |
| 939 | r = radeon_bo_reserve(rbo, false); |
| 940 | if (unlikely(r != 0)) |
| 941 | return r; |
| 942 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); |
| 943 | if (unlikely(r != 0)) { |
| 944 | radeon_bo_unreserve(rbo); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 945 | return -EINVAL; |
| 946 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 947 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); |
| 948 | radeon_bo_unreserve(rbo); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 949 | |
| 950 | switch (crtc->fb->bits_per_pixel) { |
Dave Airlie | 41456df | 2009-09-16 10:15:21 +1000 | [diff] [blame] | 951 | case 8: |
| 952 | fb_format = |
| 953 | AVIVO_D1GRPH_CONTROL_DEPTH_8BPP | |
| 954 | AVIVO_D1GRPH_CONTROL_8BPP_INDEXED; |
| 955 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 956 | case 15: |
| 957 | fb_format = |
| 958 | AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | |
| 959 | AVIVO_D1GRPH_CONTROL_16BPP_ARGB1555; |
| 960 | break; |
| 961 | case 16: |
| 962 | fb_format = |
| 963 | AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | |
| 964 | AVIVO_D1GRPH_CONTROL_16BPP_RGB565; |
| 965 | break; |
| 966 | case 24: |
| 967 | case 32: |
| 968 | fb_format = |
| 969 | AVIVO_D1GRPH_CONTROL_DEPTH_32BPP | |
| 970 | AVIVO_D1GRPH_CONTROL_32BPP_ARGB8888; |
| 971 | break; |
| 972 | default: |
| 973 | DRM_ERROR("Unsupported screen depth %d\n", |
| 974 | crtc->fb->bits_per_pixel); |
| 975 | return -EINVAL; |
| 976 | } |
| 977 | |
Dave Airlie | cf2f05d | 2009-12-08 15:45:13 +1000 | [diff] [blame] | 978 | if (tiling_flags & RADEON_TILING_MACRO) |
| 979 | fb_format |= AVIVO_D1GRPH_MACRO_ADDRESS_MODE; |
| 980 | |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 981 | if (tiling_flags & RADEON_TILING_MICRO) |
| 982 | fb_format |= AVIVO_D1GRPH_TILED; |
| 983 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 984 | if (radeon_crtc->crtc_id == 0) |
| 985 | WREG32(AVIVO_D1VGA_CONTROL, 0); |
| 986 | else |
| 987 | WREG32(AVIVO_D2VGA_CONTROL, 0); |
Alex Deucher | c290dad | 2009-10-22 16:12:34 -0400 | [diff] [blame] | 988 | |
| 989 | if (rdev->family >= CHIP_RV770) { |
| 990 | if (radeon_crtc->crtc_id) { |
| 991 | WREG32(R700_D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, 0); |
| 992 | WREG32(R700_D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, 0); |
| 993 | } else { |
| 994 | WREG32(R700_D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, 0); |
| 995 | WREG32(R700_D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, 0); |
| 996 | } |
| 997 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 998 | WREG32(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 999 | (u32) fb_location); |
| 1000 | WREG32(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS + |
| 1001 | radeon_crtc->crtc_offset, (u32) fb_location); |
| 1002 | WREG32(AVIVO_D1GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); |
| 1003 | |
| 1004 | WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); |
| 1005 | WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); |
| 1006 | WREG32(AVIVO_D1GRPH_X_START + radeon_crtc->crtc_offset, 0); |
| 1007 | WREG32(AVIVO_D1GRPH_Y_START + radeon_crtc->crtc_offset, 0); |
| 1008 | WREG32(AVIVO_D1GRPH_X_END + radeon_crtc->crtc_offset, crtc->fb->width); |
| 1009 | WREG32(AVIVO_D1GRPH_Y_END + radeon_crtc->crtc_offset, crtc->fb->height); |
| 1010 | |
| 1011 | fb_pitch_pixels = crtc->fb->pitch / (crtc->fb->bits_per_pixel / 8); |
| 1012 | WREG32(AVIVO_D1GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); |
| 1013 | WREG32(AVIVO_D1GRPH_ENABLE + radeon_crtc->crtc_offset, 1); |
| 1014 | |
| 1015 | WREG32(AVIVO_D1MODE_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, |
| 1016 | crtc->mode.vdisplay); |
| 1017 | x &= ~3; |
| 1018 | y &= ~1; |
| 1019 | WREG32(AVIVO_D1MODE_VIEWPORT_START + radeon_crtc->crtc_offset, |
| 1020 | (x << 16) | y); |
| 1021 | WREG32(AVIVO_D1MODE_VIEWPORT_SIZE + radeon_crtc->crtc_offset, |
| 1022 | (crtc->mode.hdisplay << 16) | crtc->mode.vdisplay); |
| 1023 | |
| 1024 | if (crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) |
| 1025 | WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, |
| 1026 | AVIVO_D1MODE_INTERLEAVE_EN); |
| 1027 | else |
| 1028 | WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 0); |
| 1029 | |
| 1030 | if (old_fb && old_fb != crtc->fb) { |
| 1031 | radeon_fb = to_radeon_framebuffer(old_fb); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1032 | rbo = radeon_fb->obj->driver_private; |
| 1033 | r = radeon_bo_reserve(rbo, false); |
| 1034 | if (unlikely(r != 0)) |
| 1035 | return r; |
| 1036 | radeon_bo_unpin(rbo); |
| 1037 | radeon_bo_unreserve(rbo); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1038 | } |
Michel Dänzer | f30f37d | 2009-10-08 10:44:09 +0200 | [diff] [blame] | 1039 | |
| 1040 | /* Bytes per pixel may have changed */ |
| 1041 | radeon_bandwidth_update(rdev); |
| 1042 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1043 | return 0; |
| 1044 | } |
| 1045 | |
Alex Deucher | 54f088a | 2010-01-19 16:34:01 -0500 | [diff] [blame] | 1046 | int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
| 1047 | struct drm_framebuffer *old_fb) |
| 1048 | { |
| 1049 | struct drm_device *dev = crtc->dev; |
| 1050 | struct radeon_device *rdev = dev->dev_private; |
| 1051 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1052 | if (ASIC_IS_DCE4(rdev)) |
| 1053 | return evergreen_crtc_set_base(crtc, x, y, old_fb); |
| 1054 | else if (ASIC_IS_AVIVO(rdev)) |
Alex Deucher | 54f088a | 2010-01-19 16:34:01 -0500 | [diff] [blame] | 1055 | return avivo_crtc_set_base(crtc, x, y, old_fb); |
| 1056 | else |
| 1057 | return radeon_crtc_set_base(crtc, x, y, old_fb); |
| 1058 | } |
| 1059 | |
Alex Deucher | 615e0cb | 2010-01-20 16:22:53 -0500 | [diff] [blame] | 1060 | /* properly set additional regs when using atombios */ |
| 1061 | static void radeon_legacy_atom_fixup(struct drm_crtc *crtc) |
| 1062 | { |
| 1063 | struct drm_device *dev = crtc->dev; |
| 1064 | struct radeon_device *rdev = dev->dev_private; |
| 1065 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1066 | u32 disp_merge_cntl; |
| 1067 | |
| 1068 | switch (radeon_crtc->crtc_id) { |
| 1069 | case 0: |
| 1070 | disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL); |
| 1071 | disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN; |
| 1072 | WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl); |
| 1073 | break; |
| 1074 | case 1: |
| 1075 | disp_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL); |
| 1076 | disp_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN; |
| 1077 | WREG32(RADEON_DISP2_MERGE_CNTL, disp_merge_cntl); |
| 1078 | WREG32(RADEON_FP_H2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_H_SYNC_STRT_WID)); |
| 1079 | WREG32(RADEON_FP_V2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_V_SYNC_STRT_WID)); |
| 1080 | break; |
| 1081 | } |
| 1082 | } |
| 1083 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1084 | static int radeon_atom_pick_pll(struct drm_crtc *crtc) |
| 1085 | { |
| 1086 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1087 | struct drm_device *dev = crtc->dev; |
| 1088 | struct radeon_device *rdev = dev->dev_private; |
| 1089 | struct drm_encoder *test_encoder; |
| 1090 | struct drm_crtc *test_crtc; |
| 1091 | uint32_t pll_in_use = 0; |
| 1092 | |
| 1093 | if (ASIC_IS_DCE4(rdev)) { |
| 1094 | /* if crtc is driving DP and we have an ext clock, use that */ |
| 1095 | list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) { |
| 1096 | if (test_encoder->crtc && (test_encoder->crtc == crtc)) { |
| 1097 | if (atombios_get_encoder_mode(test_encoder) == ATOM_ENCODER_MODE_DP) { |
| 1098 | if (rdev->clock.dp_extclk) |
| 1099 | return ATOM_PPLL_INVALID; |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /* otherwise, pick one of the plls */ |
| 1105 | list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { |
| 1106 | struct radeon_crtc *radeon_test_crtc; |
| 1107 | |
| 1108 | if (crtc == test_crtc) |
| 1109 | continue; |
| 1110 | |
| 1111 | radeon_test_crtc = to_radeon_crtc(test_crtc); |
| 1112 | if ((radeon_test_crtc->pll_id >= ATOM_PPLL1) && |
| 1113 | (radeon_test_crtc->pll_id <= ATOM_PPLL2)) |
| 1114 | pll_in_use |= (1 << radeon_test_crtc->pll_id); |
| 1115 | } |
| 1116 | if (!(pll_in_use & 1)) |
| 1117 | return ATOM_PPLL1; |
| 1118 | return ATOM_PPLL2; |
| 1119 | } else |
| 1120 | return radeon_crtc->crtc_id; |
| 1121 | |
| 1122 | } |
| 1123 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1124 | int atombios_crtc_mode_set(struct drm_crtc *crtc, |
| 1125 | struct drm_display_mode *mode, |
| 1126 | struct drm_display_mode *adjusted_mode, |
| 1127 | int x, int y, struct drm_framebuffer *old_fb) |
| 1128 | { |
| 1129 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1130 | struct drm_device *dev = crtc->dev; |
| 1131 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1132 | |
| 1133 | /* TODO color tiling */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1134 | |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 1135 | atombios_disable_ss(crtc); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1136 | /* always set DCPLL */ |
| 1137 | if (ASIC_IS_DCE4(rdev)) |
| 1138 | atombios_crtc_set_dcpll(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1139 | atombios_crtc_set_pll(crtc, adjusted_mode); |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 1140 | atombios_enable_ss(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1141 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1142 | if (ASIC_IS_DCE4(rdev)) |
| 1143 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); |
| 1144 | else if (ASIC_IS_AVIVO(rdev)) |
| 1145 | atombios_crtc_set_timing(crtc, adjusted_mode); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1146 | else { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1147 | atombios_crtc_set_timing(crtc, adjusted_mode); |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1148 | if (radeon_crtc->crtc_id == 0) |
| 1149 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); |
Alex Deucher | 615e0cb | 2010-01-20 16:22:53 -0500 | [diff] [blame] | 1150 | radeon_legacy_atom_fixup(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1151 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1152 | atombios_crtc_set_base(crtc, x, y, old_fb); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1153 | atombios_overscan_setup(crtc, mode, adjusted_mode); |
| 1154 | atombios_scaler_setup(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc, |
| 1159 | struct drm_display_mode *mode, |
| 1160 | struct drm_display_mode *adjusted_mode) |
| 1161 | { |
Alex Deucher | 03214bd | 2010-03-16 17:42:46 -0400 | [diff] [blame^] | 1162 | struct drm_device *dev = crtc->dev; |
| 1163 | struct radeon_device *rdev = dev->dev_private; |
| 1164 | |
| 1165 | /* adjust pm to upcoming mode change */ |
| 1166 | radeon_pm_compute_clocks(rdev); |
| 1167 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1168 | if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) |
| 1169 | return false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1170 | return true; |
| 1171 | } |
| 1172 | |
| 1173 | static void atombios_crtc_prepare(struct drm_crtc *crtc) |
| 1174 | { |
Alex Deucher | 267364a | 2010-03-08 17:10:41 -0500 | [diff] [blame] | 1175 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1176 | |
| 1177 | /* pick pll */ |
| 1178 | radeon_crtc->pll_id = radeon_atom_pick_pll(crtc); |
| 1179 | |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 1180 | atombios_lock_crtc(crtc, ATOM_ENABLE); |
Alex Deucher | a348c84 | 2010-01-21 16:50:30 -0500 | [diff] [blame] | 1181 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static void atombios_crtc_commit(struct drm_crtc *crtc) |
| 1185 | { |
| 1186 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 1187 | atombios_lock_crtc(crtc, ATOM_DISABLE); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | static const struct drm_crtc_helper_funcs atombios_helper_funcs = { |
| 1191 | .dpms = atombios_crtc_dpms, |
| 1192 | .mode_fixup = atombios_crtc_mode_fixup, |
| 1193 | .mode_set = atombios_crtc_mode_set, |
| 1194 | .mode_set_base = atombios_crtc_set_base, |
| 1195 | .prepare = atombios_crtc_prepare, |
| 1196 | .commit = atombios_crtc_commit, |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1197 | .load_lut = radeon_crtc_load_lut, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1198 | }; |
| 1199 | |
| 1200 | void radeon_atombios_init_crtc(struct drm_device *dev, |
| 1201 | struct radeon_crtc *radeon_crtc) |
| 1202 | { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1203 | struct radeon_device *rdev = dev->dev_private; |
| 1204 | |
| 1205 | if (ASIC_IS_DCE4(rdev)) { |
| 1206 | switch (radeon_crtc->crtc_id) { |
| 1207 | case 0: |
| 1208 | default: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1209 | radeon_crtc->crtc_offset = EVERGREEN_CRTC0_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1210 | break; |
| 1211 | case 1: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1212 | radeon_crtc->crtc_offset = EVERGREEN_CRTC1_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1213 | break; |
| 1214 | case 2: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1215 | radeon_crtc->crtc_offset = EVERGREEN_CRTC2_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1216 | break; |
| 1217 | case 3: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1218 | radeon_crtc->crtc_offset = EVERGREEN_CRTC3_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1219 | break; |
| 1220 | case 4: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1221 | radeon_crtc->crtc_offset = EVERGREEN_CRTC4_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1222 | break; |
| 1223 | case 5: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1224 | radeon_crtc->crtc_offset = EVERGREEN_CRTC5_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1225 | break; |
| 1226 | } |
| 1227 | } else { |
| 1228 | if (radeon_crtc->crtc_id == 1) |
| 1229 | radeon_crtc->crtc_offset = |
| 1230 | AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL; |
| 1231 | else |
| 1232 | radeon_crtc->crtc_offset = 0; |
| 1233 | } |
| 1234 | radeon_crtc->pll_id = -1; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1235 | drm_crtc_helper_add(&radeon_crtc->base, &atombios_helper_funcs); |
| 1236 | } |