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