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: |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 51 | args.usOverscanTop = cpu_to_le16((adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2); |
| 52 | args.usOverscanBottom = cpu_to_le16((adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2); |
| 53 | args.usOverscanLeft = cpu_to_le16((adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2); |
| 54 | args.usOverscanRight = cpu_to_le16((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) { |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 61 | args.usOverscanLeft = cpu_to_le16((adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2); |
| 62 | args.usOverscanRight = cpu_to_le16((adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 63 | } else if (a2 > a1) { |
Alex Deucher | 942b0e9 | 2011-03-14 23:18:00 -0400 | [diff] [blame] | 64 | args.usOverscanTop = cpu_to_le16((adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2); |
| 65 | args.usOverscanBottom = cpu_to_le16((adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 66 | } |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 67 | break; |
| 68 | case RMX_FULL: |
| 69 | default: |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 70 | args.usOverscanRight = cpu_to_le16(radeon_crtc->h_border); |
| 71 | args.usOverscanLeft = cpu_to_le16(radeon_crtc->h_border); |
| 72 | args.usOverscanBottom = cpu_to_le16(radeon_crtc->v_border); |
| 73 | args.usOverscanTop = cpu_to_le16(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); |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 86 | struct radeon_encoder *radeon_encoder = |
| 87 | to_radeon_encoder(radeon_crtc->encoder); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 88 | /* fixme - fill in enc_priv for atom dac */ |
| 89 | enum radeon_tv_std tv_std = TV_STD_NTSC; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 90 | bool is_tv = false, is_cv = false; |
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 | |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 95 | if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) { |
| 96 | struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv; |
| 97 | tv_std = tv_dac->tv_std; |
| 98 | is_tv = true; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 99 | } |
| 100 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 101 | memset(&args, 0, sizeof(args)); |
| 102 | |
| 103 | args.ucScaler = radeon_crtc->crtc_id; |
| 104 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 105 | if (is_tv) { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 106 | switch (tv_std) { |
| 107 | case TV_STD_NTSC: |
| 108 | default: |
| 109 | args.ucTVStandard = ATOM_TV_NTSC; |
| 110 | break; |
| 111 | case TV_STD_PAL: |
| 112 | args.ucTVStandard = ATOM_TV_PAL; |
| 113 | break; |
| 114 | case TV_STD_PAL_M: |
| 115 | args.ucTVStandard = ATOM_TV_PALM; |
| 116 | break; |
| 117 | case TV_STD_PAL_60: |
| 118 | args.ucTVStandard = ATOM_TV_PAL60; |
| 119 | break; |
| 120 | case TV_STD_NTSC_J: |
| 121 | args.ucTVStandard = ATOM_TV_NTSCJ; |
| 122 | break; |
| 123 | case TV_STD_SCART_PAL: |
| 124 | args.ucTVStandard = ATOM_TV_PAL; /* ??? */ |
| 125 | break; |
| 126 | case TV_STD_SECAM: |
| 127 | args.ucTVStandard = ATOM_TV_SECAM; |
| 128 | break; |
| 129 | case TV_STD_PAL_CN: |
| 130 | args.ucTVStandard = ATOM_TV_PALCN; |
| 131 | break; |
| 132 | } |
| 133 | args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 134 | } else if (is_cv) { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 135 | args.ucTVStandard = ATOM_TV_CV; |
| 136 | args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; |
| 137 | } else { |
| 138 | switch (radeon_crtc->rmx_type) { |
| 139 | case RMX_FULL: |
| 140 | args.ucEnable = ATOM_SCALER_EXPANSION; |
| 141 | break; |
| 142 | case RMX_CENTER: |
| 143 | args.ucEnable = ATOM_SCALER_CENTER; |
| 144 | break; |
| 145 | case RMX_ASPECT: |
| 146 | args.ucEnable = ATOM_SCALER_EXPANSION; |
| 147 | break; |
| 148 | default: |
| 149 | if (ASIC_IS_AVIVO(rdev)) |
| 150 | args.ucEnable = ATOM_SCALER_DISABLE; |
| 151 | else |
| 152 | args.ucEnable = ATOM_SCALER_CENTER; |
| 153 | break; |
| 154 | } |
| 155 | } |
| 156 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 157 | if ((is_tv || is_cv) |
| 158 | && rdev->family >= CHIP_RV515 && rdev->family <= CHIP_R580) { |
| 159 | atom_rv515_force_tv_scaler(rdev, radeon_crtc); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 163 | static void atombios_lock_crtc(struct drm_crtc *crtc, int lock) |
| 164 | { |
| 165 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 166 | struct drm_device *dev = crtc->dev; |
| 167 | struct radeon_device *rdev = dev->dev_private; |
| 168 | int index = |
| 169 | GetIndexIntoMasterTable(COMMAND, UpdateCRTC_DoubleBufferRegisters); |
| 170 | ENABLE_CRTC_PS_ALLOCATION args; |
| 171 | |
| 172 | memset(&args, 0, sizeof(args)); |
| 173 | |
| 174 | args.ucCRTC = radeon_crtc->crtc_id; |
| 175 | args.ucEnable = lock; |
| 176 | |
| 177 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 178 | } |
| 179 | |
| 180 | static void atombios_enable_crtc(struct drm_crtc *crtc, int state) |
| 181 | { |
| 182 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 183 | struct drm_device *dev = crtc->dev; |
| 184 | struct radeon_device *rdev = dev->dev_private; |
| 185 | int index = GetIndexIntoMasterTable(COMMAND, EnableCRTC); |
| 186 | ENABLE_CRTC_PS_ALLOCATION args; |
| 187 | |
| 188 | memset(&args, 0, sizeof(args)); |
| 189 | |
| 190 | args.ucCRTC = radeon_crtc->crtc_id; |
| 191 | args.ucEnable = state; |
| 192 | |
| 193 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 194 | } |
| 195 | |
| 196 | static void atombios_enable_crtc_memreq(struct drm_crtc *crtc, int state) |
| 197 | { |
| 198 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 199 | struct drm_device *dev = crtc->dev; |
| 200 | struct radeon_device *rdev = dev->dev_private; |
| 201 | int index = GetIndexIntoMasterTable(COMMAND, EnableCRTCMemReq); |
| 202 | ENABLE_CRTC_PS_ALLOCATION args; |
| 203 | |
| 204 | memset(&args, 0, sizeof(args)); |
| 205 | |
| 206 | args.ucCRTC = radeon_crtc->crtc_id; |
| 207 | args.ucEnable = state; |
| 208 | |
| 209 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 210 | } |
| 211 | |
| 212 | static void atombios_blank_crtc(struct drm_crtc *crtc, int state) |
| 213 | { |
| 214 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 215 | struct drm_device *dev = crtc->dev; |
| 216 | struct radeon_device *rdev = dev->dev_private; |
| 217 | int index = GetIndexIntoMasterTable(COMMAND, BlankCRTC); |
| 218 | BLANK_CRTC_PS_ALLOCATION args; |
| 219 | |
| 220 | memset(&args, 0, sizeof(args)); |
| 221 | |
| 222 | args.ucCRTC = radeon_crtc->crtc_id; |
| 223 | args.ucBlanking = state; |
| 224 | |
| 225 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 226 | } |
| 227 | |
Alex Deucher | fef9f91 | 2012-03-20 17:18:03 -0400 | [diff] [blame] | 228 | static void atombios_powergate_crtc(struct drm_crtc *crtc, int state) |
| 229 | { |
| 230 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 231 | struct drm_device *dev = crtc->dev; |
| 232 | struct radeon_device *rdev = dev->dev_private; |
| 233 | int index = GetIndexIntoMasterTable(COMMAND, EnableDispPowerGating); |
| 234 | ENABLE_DISP_POWER_GATING_PARAMETERS_V2_1 args; |
| 235 | |
| 236 | memset(&args, 0, sizeof(args)); |
| 237 | |
| 238 | args.ucDispPipeId = radeon_crtc->crtc_id; |
| 239 | args.ucEnable = state; |
| 240 | |
| 241 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 242 | } |
| 243 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 244 | void atombios_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 245 | { |
| 246 | struct drm_device *dev = crtc->dev; |
| 247 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 500b758 | 2009-12-02 11:46:52 -0500 | [diff] [blame] | 248 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 249 | |
| 250 | switch (mode) { |
| 251 | case DRM_MODE_DPMS_ON: |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 252 | radeon_crtc->enabled = true; |
| 253 | /* adjust pm to dpms changes BEFORE enabling crtcs */ |
| 254 | radeon_pm_compute_clocks(rdev); |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 255 | atombios_enable_crtc(crtc, ATOM_ENABLE); |
Alex Deucher | 79f17c6 | 2012-03-20 17:18:02 -0400 | [diff] [blame] | 256 | if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev)) |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 257 | atombios_enable_crtc_memreq(crtc, ATOM_ENABLE); |
| 258 | atombios_blank_crtc(crtc, ATOM_DISABLE); |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 259 | drm_vblank_post_modeset(dev, radeon_crtc->crtc_id); |
Alex Deucher | 500b758 | 2009-12-02 11:46:52 -0500 | [diff] [blame] | 260 | radeon_crtc_load_lut(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 261 | break; |
| 262 | case DRM_MODE_DPMS_STANDBY: |
| 263 | case DRM_MODE_DPMS_SUSPEND: |
| 264 | case DRM_MODE_DPMS_OFF: |
Alex Deucher | 45f9a39 | 2010-03-24 13:55:51 -0400 | [diff] [blame] | 265 | drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id); |
Alex Deucher | a93f344 | 2010-12-20 11:22:29 -0500 | [diff] [blame] | 266 | if (radeon_crtc->enabled) |
| 267 | atombios_blank_crtc(crtc, ATOM_ENABLE); |
Alex Deucher | 79f17c6 | 2012-03-20 17:18:02 -0400 | [diff] [blame] | 268 | if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev)) |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 269 | atombios_enable_crtc_memreq(crtc, ATOM_DISABLE); |
| 270 | atombios_enable_crtc(crtc, ATOM_DISABLE); |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 271 | radeon_crtc->enabled = false; |
Alex Deucher | d731117 | 2010-05-03 01:13:14 -0400 | [diff] [blame] | 272 | /* adjust pm to dpms changes AFTER disabling crtcs */ |
| 273 | radeon_pm_compute_clocks(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 274 | break; |
| 275 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | static void |
| 279 | atombios_set_crtc_dtd_timing(struct drm_crtc *crtc, |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 280 | struct drm_display_mode *mode) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 281 | { |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 282 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 283 | struct drm_device *dev = crtc->dev; |
| 284 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 285 | SET_CRTC_USING_DTD_TIMING_PARAMETERS args; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 286 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_UsingDTDTiming); |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 287 | u16 misc = 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 288 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 289 | memset(&args, 0, sizeof(args)); |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 290 | 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] | 291 | args.usH_Blanking_Time = |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 292 | cpu_to_le16(mode->crtc_hblank_end - mode->crtc_hdisplay + (radeon_crtc->h_border * 2)); |
| 293 | 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] | 294 | args.usV_Blanking_Time = |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 295 | 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] | 296 | args.usH_SyncOffset = |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 297 | 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] | 298 | args.usH_SyncWidth = |
| 299 | cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); |
| 300 | args.usV_SyncOffset = |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 301 | 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] | 302 | args.usV_SyncWidth = |
| 303 | cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 304 | args.ucH_Border = radeon_crtc->h_border; |
| 305 | args.ucV_Border = radeon_crtc->v_border; |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 306 | |
| 307 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 308 | misc |= ATOM_VSYNC_POLARITY; |
| 309 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 310 | misc |= ATOM_HSYNC_POLARITY; |
| 311 | if (mode->flags & DRM_MODE_FLAG_CSYNC) |
| 312 | misc |= ATOM_COMPOSITESYNC; |
| 313 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 314 | misc |= ATOM_INTERLACE; |
| 315 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 316 | misc |= ATOM_DOUBLE_CLOCK_MODE; |
| 317 | |
| 318 | args.susModeMiscInfo.usAccess = cpu_to_le16(misc); |
| 319 | args.ucCRTC = radeon_crtc->crtc_id; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 320 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 321 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 324 | static void atombios_crtc_set_timing(struct drm_crtc *crtc, |
| 325 | struct drm_display_mode *mode) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 326 | { |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 327 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 328 | struct drm_device *dev = crtc->dev; |
| 329 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 330 | SET_CRTC_TIMING_PARAMETERS_PS_ALLOCATION args; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 331 | int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_Timing); |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 332 | u16 misc = 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 333 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 334 | memset(&args, 0, sizeof(args)); |
| 335 | args.usH_Total = cpu_to_le16(mode->crtc_htotal); |
| 336 | args.usH_Disp = cpu_to_le16(mode->crtc_hdisplay); |
| 337 | args.usH_SyncStart = cpu_to_le16(mode->crtc_hsync_start); |
| 338 | args.usH_SyncWidth = |
| 339 | cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); |
| 340 | args.usV_Total = cpu_to_le16(mode->crtc_vtotal); |
| 341 | args.usV_Disp = cpu_to_le16(mode->crtc_vdisplay); |
| 342 | args.usV_SyncStart = cpu_to_le16(mode->crtc_vsync_start); |
| 343 | args.usV_SyncWidth = |
| 344 | cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); |
| 345 | |
Alex Deucher | 54bfe49 | 2010-09-03 15:52:53 -0400 | [diff] [blame] | 346 | args.ucOverscanRight = radeon_crtc->h_border; |
| 347 | args.ucOverscanLeft = radeon_crtc->h_border; |
| 348 | args.ucOverscanBottom = radeon_crtc->v_border; |
| 349 | args.ucOverscanTop = radeon_crtc->v_border; |
| 350 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 351 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 352 | misc |= ATOM_VSYNC_POLARITY; |
| 353 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 354 | misc |= ATOM_HSYNC_POLARITY; |
| 355 | if (mode->flags & DRM_MODE_FLAG_CSYNC) |
| 356 | misc |= ATOM_COMPOSITESYNC; |
| 357 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 358 | misc |= ATOM_INTERLACE; |
| 359 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 360 | misc |= ATOM_DOUBLE_CLOCK_MODE; |
| 361 | |
| 362 | args.susModeMiscInfo.usAccess = cpu_to_le16(misc); |
| 363 | args.ucCRTC = radeon_crtc->crtc_id; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 364 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 365 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 366 | } |
| 367 | |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 368 | static void atombios_disable_ss(struct radeon_device *rdev, int pll_id) |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 369 | { |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 370 | u32 ss_cntl; |
| 371 | |
| 372 | if (ASIC_IS_DCE4(rdev)) { |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 373 | switch (pll_id) { |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 374 | case ATOM_PPLL1: |
| 375 | ss_cntl = RREG32(EVERGREEN_P1PLL_SS_CNTL); |
| 376 | ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; |
| 377 | WREG32(EVERGREEN_P1PLL_SS_CNTL, ss_cntl); |
| 378 | break; |
| 379 | case ATOM_PPLL2: |
| 380 | ss_cntl = RREG32(EVERGREEN_P2PLL_SS_CNTL); |
| 381 | ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; |
| 382 | WREG32(EVERGREEN_P2PLL_SS_CNTL, ss_cntl); |
| 383 | break; |
| 384 | case ATOM_DCPLL: |
| 385 | case ATOM_PPLL_INVALID: |
| 386 | return; |
| 387 | } |
| 388 | } else if (ASIC_IS_AVIVO(rdev)) { |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 389 | switch (pll_id) { |
Alex Deucher | b792210 | 2010-03-06 10:57:30 -0500 | [diff] [blame] | 390 | case ATOM_PPLL1: |
| 391 | ss_cntl = RREG32(AVIVO_P1PLL_INT_SS_CNTL); |
| 392 | ss_cntl &= ~1; |
| 393 | WREG32(AVIVO_P1PLL_INT_SS_CNTL, ss_cntl); |
| 394 | break; |
| 395 | case ATOM_PPLL2: |
| 396 | ss_cntl = RREG32(AVIVO_P2PLL_INT_SS_CNTL); |
| 397 | ss_cntl &= ~1; |
| 398 | WREG32(AVIVO_P2PLL_INT_SS_CNTL, ss_cntl); |
| 399 | break; |
| 400 | case ATOM_DCPLL: |
| 401 | case ATOM_PPLL_INVALID: |
| 402 | return; |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 408 | union atom_enable_ss { |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 409 | ENABLE_LVDS_SS_PARAMETERS lvds_ss; |
| 410 | ENABLE_LVDS_SS_PARAMETERS_V2 lvds_ss_2; |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 411 | ENABLE_SPREAD_SPECTRUM_ON_PPLL_PS_ALLOCATION v1; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 412 | ENABLE_SPREAD_SPECTRUM_ON_PPLL_V2 v2; |
Alex Deucher | a572eaa | 2011-01-06 21:19:16 -0500 | [diff] [blame] | 413 | ENABLE_SPREAD_SPECTRUM_ON_PPLL_V3 v3; |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 414 | }; |
| 415 | |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 416 | static void atombios_crtc_program_ss(struct radeon_device *rdev, |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 417 | int enable, |
| 418 | int pll_id, |
Jerome Glisse | 5efcc76 | 2012-08-17 14:40:04 -0400 | [diff] [blame] | 419 | int crtc_id, |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 420 | struct radeon_atom_ss *ss) |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 421 | { |
Jerome Glisse | 5efcc76 | 2012-08-17 14:40:04 -0400 | [diff] [blame] | 422 | unsigned i; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 423 | int index = GetIndexIntoMasterTable(COMMAND, EnableSpreadSpectrumOnPPLL); |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 424 | union atom_enable_ss args; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 425 | |
Jerome Glisse | 5efcc76 | 2012-08-17 14:40:04 -0400 | [diff] [blame] | 426 | if (!enable) { |
Alex Deucher | 5317670 | 2012-08-21 18:52:56 -0400 | [diff] [blame] | 427 | for (i = 0; i < rdev->num_crtc; i++) { |
Jerome Glisse | 5efcc76 | 2012-08-17 14:40:04 -0400 | [diff] [blame] | 428 | if (rdev->mode_info.crtcs[i] && |
| 429 | rdev->mode_info.crtcs[i]->enabled && |
| 430 | i != crtc_id && |
| 431 | pll_id == rdev->mode_info.crtcs[i]->pll_id) { |
| 432 | /* one other crtc is using this pll don't turn |
| 433 | * off spread spectrum as it might turn off |
| 434 | * display on active crtc |
| 435 | */ |
| 436 | return; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 441 | memset(&args, 0, sizeof(args)); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 442 | |
Alex Deucher | a572eaa | 2011-01-06 21:19:16 -0500 | [diff] [blame] | 443 | if (ASIC_IS_DCE5(rdev)) { |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 444 | args.v3.usSpreadSpectrumAmountFrac = cpu_to_le16(0); |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 445 | args.v3.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
Alex Deucher | a572eaa | 2011-01-06 21:19:16 -0500 | [diff] [blame] | 446 | switch (pll_id) { |
| 447 | case ATOM_PPLL1: |
| 448 | args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_P1PLL; |
Alex Deucher | a572eaa | 2011-01-06 21:19:16 -0500 | [diff] [blame] | 449 | break; |
| 450 | case ATOM_PPLL2: |
| 451 | args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_P2PLL; |
Alex Deucher | a572eaa | 2011-01-06 21:19:16 -0500 | [diff] [blame] | 452 | break; |
| 453 | case ATOM_DCPLL: |
| 454 | args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_DCPLL; |
Alex Deucher | a572eaa | 2011-01-06 21:19:16 -0500 | [diff] [blame] | 455 | break; |
| 456 | case ATOM_PPLL_INVALID: |
| 457 | return; |
| 458 | } |
Alex Deucher | f312f09 | 2012-07-17 14:02:44 -0400 | [diff] [blame] | 459 | args.v3.usSpreadSpectrumAmount = cpu_to_le16(ss->amount); |
| 460 | args.v3.usSpreadSpectrumStep = cpu_to_le16(ss->step); |
Alex Deucher | d0ae3e8 | 2011-05-23 14:06:20 -0400 | [diff] [blame] | 461 | args.v3.ucEnable = enable; |
Alex Deucher | 0671bdd7 | 2012-03-20 17:18:34 -0400 | [diff] [blame] | 462 | if ((ss->percentage == 0) || (ss->type & ATOM_EXTERNAL_SS_MASK) || ASIC_IS_DCE61(rdev)) |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 463 | args.v3.ucEnable = ATOM_DISABLE; |
Alex Deucher | a572eaa | 2011-01-06 21:19:16 -0500 | [diff] [blame] | 464 | } else if (ASIC_IS_DCE4(rdev)) { |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 465 | args.v2.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 466 | args.v2.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 467 | switch (pll_id) { |
| 468 | case ATOM_PPLL1: |
| 469 | args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_P1PLL; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 470 | break; |
| 471 | case ATOM_PPLL2: |
| 472 | args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_P2PLL; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 473 | break; |
| 474 | case ATOM_DCPLL: |
| 475 | args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_DCPLL; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 476 | break; |
| 477 | case ATOM_PPLL_INVALID: |
| 478 | return; |
| 479 | } |
Alex Deucher | f312f09 | 2012-07-17 14:02:44 -0400 | [diff] [blame] | 480 | args.v2.usSpreadSpectrumAmount = cpu_to_le16(ss->amount); |
| 481 | args.v2.usSpreadSpectrumStep = cpu_to_le16(ss->step); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 482 | args.v2.ucEnable = enable; |
Alex Deucher | 09cc650 | 2011-10-12 18:44:33 -0400 | [diff] [blame] | 483 | if ((ss->percentage == 0) || (ss->type & ATOM_EXTERNAL_SS_MASK) || ASIC_IS_DCE41(rdev)) |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 484 | args.v2.ucEnable = ATOM_DISABLE; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 485 | } else if (ASIC_IS_DCE3(rdev)) { |
| 486 | args.v1.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 487 | args.v1.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 488 | args.v1.ucSpreadSpectrumStep = ss->step; |
| 489 | args.v1.ucSpreadSpectrumDelay = ss->delay; |
| 490 | args.v1.ucSpreadSpectrumRange = ss->range; |
| 491 | args.v1.ucPpll = pll_id; |
| 492 | args.v1.ucEnable = enable; |
| 493 | } else if (ASIC_IS_AVIVO(rdev)) { |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 494 | if ((enable == ATOM_DISABLE) || (ss->percentage == 0) || |
| 495 | (ss->type & ATOM_EXTERNAL_SS_MASK)) { |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 496 | atombios_disable_ss(rdev, pll_id); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | args.lvds_ss_2.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 500 | args.lvds_ss_2.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 501 | args.lvds_ss_2.ucSpreadSpectrumStep = ss->step; |
| 502 | args.lvds_ss_2.ucSpreadSpectrumDelay = ss->delay; |
| 503 | args.lvds_ss_2.ucSpreadSpectrumRange = ss->range; |
| 504 | args.lvds_ss_2.ucEnable = enable; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 505 | } else { |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 506 | if ((enable == ATOM_DISABLE) || (ss->percentage == 0) || |
| 507 | (ss->type & ATOM_EXTERNAL_SS_MASK)) { |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 508 | atombios_disable_ss(rdev, pll_id); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 509 | return; |
| 510 | } |
| 511 | args.lvds_ss.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 512 | args.lvds_ss.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 513 | args.lvds_ss.ucSpreadSpectrumStepSize_Delay = (ss->step & 3) << 2; |
| 514 | args.lvds_ss.ucSpreadSpectrumStepSize_Delay |= (ss->delay & 7) << 4; |
| 515 | args.lvds_ss.ucEnable = enable; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 516 | } |
Alex Deucher | 26b9fc3 | 2010-02-01 16:39:11 -0500 | [diff] [blame] | 517 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 518 | } |
| 519 | |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 520 | union adjust_pixel_clock { |
| 521 | ADJUST_DISPLAY_PLL_PS_ALLOCATION v1; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 522 | ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3 v3; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 523 | }; |
| 524 | |
| 525 | static u32 atombios_adjust_pll(struct drm_crtc *crtc, |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 526 | struct drm_display_mode *mode) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 527 | { |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 528 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 529 | struct drm_device *dev = crtc->dev; |
| 530 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 531 | struct drm_encoder *encoder = radeon_crtc->encoder; |
| 532 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 533 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 534 | u32 adjusted_clock = mode->clock; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 535 | int encoder_mode = atombios_get_encoder_mode(encoder); |
Alex Deucher | fbee67a | 2010-08-16 12:44:47 -0400 | [diff] [blame] | 536 | u32 dp_clock = mode->clock; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 537 | int bpc = radeon_get_monitor_bpc(connector); |
| 538 | bool is_duallink = radeon_dig_monitor_is_duallink(encoder, mode->clock); |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 539 | |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 540 | /* reset the pll flags */ |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 541 | radeon_crtc->pll_flags = 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 542 | |
| 543 | if (ASIC_IS_AVIVO(rdev)) { |
Alex Deucher | eb1300b | 2009-07-13 11:09:56 -0400 | [diff] [blame] | 544 | if ((rdev->family == CHIP_RS600) || |
| 545 | (rdev->family == CHIP_RS690) || |
| 546 | (rdev->family == CHIP_RS740)) |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 547 | radeon_crtc->pll_flags |= (/*RADEON_PLL_USE_FRAC_FB_DIV |*/ |
| 548 | RADEON_PLL_PREFER_CLOSEST_LOWER); |
Dave Airlie | 5480f72 | 2010-10-19 10:36:47 +1000 | [diff] [blame] | 549 | |
| 550 | if (ASIC_IS_DCE32(rdev) && mode->clock > 200000) /* range limits??? */ |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 551 | radeon_crtc->pll_flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; |
Dave Airlie | 5480f72 | 2010-10-19 10:36:47 +1000 | [diff] [blame] | 552 | else |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 553 | radeon_crtc->pll_flags |= RADEON_PLL_PREFER_LOW_REF_DIV; |
Alex Deucher | 9bb09fa | 2011-04-07 10:31:25 -0400 | [diff] [blame] | 554 | |
Alex Deucher | 5785e53 | 2011-04-19 15:24:59 -0400 | [diff] [blame] | 555 | if (rdev->family < CHIP_RV770) |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 556 | radeon_crtc->pll_flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP; |
Alex Deucher | 37d4174 | 2012-04-19 10:48:38 -0400 | [diff] [blame] | 557 | /* use frac fb div on APUs */ |
Alex Deucher | c7d2f22 | 2012-12-18 22:11:51 -0500 | [diff] [blame] | 558 | if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev) || ASIC_IS_DCE8(rdev)) |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 559 | radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; |
Alex Deucher | 4116782 | 2013-04-01 16:06:25 -0400 | [diff] [blame] | 560 | /* use frac fb div on RS780/RS880 */ |
| 561 | if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880)) |
| 562 | radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; |
Alex Deucher | a02dc74 | 2012-11-13 18:03:41 -0500 | [diff] [blame] | 563 | if (ASIC_IS_DCE32(rdev) && mode->clock > 165000) |
| 564 | radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; |
Dave Airlie | 5480f72 | 2010-10-19 10:36:47 +1000 | [diff] [blame] | 565 | } else { |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 566 | radeon_crtc->pll_flags |= RADEON_PLL_LEGACY; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 567 | |
Dave Airlie | 5480f72 | 2010-10-19 10:36:47 +1000 | [diff] [blame] | 568 | if (mode->clock > 200000) /* range limits??? */ |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 569 | radeon_crtc->pll_flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; |
Dave Airlie | 5480f72 | 2010-10-19 10:36:47 +1000 | [diff] [blame] | 570 | else |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 571 | radeon_crtc->pll_flags |= RADEON_PLL_PREFER_LOW_REF_DIV; |
Dave Airlie | 5480f72 | 2010-10-19 10:36:47 +1000 | [diff] [blame] | 572 | } |
| 573 | |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 574 | if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) || |
| 575 | (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)) { |
| 576 | if (connector) { |
| 577 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 578 | struct radeon_connector_atom_dig *dig_connector = |
| 579 | radeon_connector->con_priv; |
Alex Deucher | fbee67a | 2010-08-16 12:44:47 -0400 | [diff] [blame] | 580 | |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 581 | dp_clock = dig_connector->dp_clock; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 585 | /* use recommended ref_div for ss */ |
| 586 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 587 | if (radeon_crtc->ss_enabled) { |
| 588 | if (radeon_crtc->ss.refdiv) { |
| 589 | radeon_crtc->pll_flags |= RADEON_PLL_USE_REF_DIV; |
| 590 | radeon_crtc->pll_reference_div = radeon_crtc->ss.refdiv; |
| 591 | if (ASIC_IS_AVIVO(rdev)) |
| 592 | radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | if (ASIC_IS_AVIVO(rdev)) { |
| 598 | /* DVO wants 2x pixel clock if the DVO chip is in 12 bit mode */ |
| 599 | if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1) |
| 600 | adjusted_clock = mode->clock * 2; |
| 601 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
| 602 | radeon_crtc->pll_flags |= RADEON_PLL_PREFER_CLOSEST_LOWER; |
| 603 | if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) |
| 604 | radeon_crtc->pll_flags |= RADEON_PLL_IS_LCD; |
| 605 | } else { |
| 606 | if (encoder->encoder_type != DRM_MODE_ENCODER_DAC) |
| 607 | radeon_crtc->pll_flags |= RADEON_PLL_NO_ODD_POST_DIV; |
| 608 | if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS) |
| 609 | radeon_crtc->pll_flags |= RADEON_PLL_USE_REF_DIV; |
| 610 | } |
| 611 | |
Alex Deucher | 2606c88 | 2009-10-08 13:36:21 -0400 | [diff] [blame] | 612 | /* DCE3+ has an AdjustDisplayPll that will adjust the pixel clock |
| 613 | * accordingly based on the encoder/transmitter to work around |
| 614 | * special hw requirements. |
| 615 | */ |
| 616 | if (ASIC_IS_DCE3(rdev)) { |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 617 | union adjust_pixel_clock args; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 618 | u8 frev, crev; |
| 619 | int index; |
Alex Deucher | 2606c88 | 2009-10-08 13:36:21 -0400 | [diff] [blame] | 620 | |
Alex Deucher | 2606c88 | 2009-10-08 13:36:21 -0400 | [diff] [blame] | 621 | index = GetIndexIntoMasterTable(COMMAND, AdjustDisplayPll); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 622 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
| 623 | &crev)) |
| 624 | return adjusted_clock; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 625 | |
| 626 | memset(&args, 0, sizeof(args)); |
| 627 | |
| 628 | switch (frev) { |
| 629 | case 1: |
| 630 | switch (crev) { |
| 631 | case 1: |
| 632 | case 2: |
| 633 | args.v1.usPixelClock = cpu_to_le16(mode->clock / 10); |
| 634 | args.v1.ucTransmitterID = radeon_encoder->encoder_id; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 635 | args.v1.ucEncodeMode = encoder_mode; |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 636 | if (radeon_crtc->ss_enabled && radeon_crtc->ss.percentage) |
Alex Deucher | fbee67a | 2010-08-16 12:44:47 -0400 | [diff] [blame] | 637 | args.v1.ucConfig |= |
| 638 | ADJUST_DISPLAY_CONFIG_SS_ENABLE; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 639 | |
| 640 | atom_execute_table(rdev->mode_info.atom_context, |
| 641 | index, (uint32_t *)&args); |
| 642 | adjusted_clock = le16_to_cpu(args.v1.usPixelClock) * 10; |
| 643 | break; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 644 | case 3: |
| 645 | args.v3.sInput.usPixelClock = cpu_to_le16(mode->clock / 10); |
| 646 | args.v3.sInput.ucTransmitterID = radeon_encoder->encoder_id; |
| 647 | args.v3.sInput.ucEncodeMode = encoder_mode; |
| 648 | args.v3.sInput.ucDispPllConfig = 0; |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 649 | if (radeon_crtc->ss_enabled && radeon_crtc->ss.percentage) |
Alex Deucher | b526ce2 | 2011-01-20 23:35:58 +0000 | [diff] [blame] | 650 | args.v3.sInput.ucDispPllConfig |= |
| 651 | DISPPLL_CONFIG_SS_ENABLE; |
Alex Deucher | 996d5c5 | 2011-10-26 15:59:50 -0400 | [diff] [blame] | 652 | if (ENCODER_MODE_IS_DP(encoder_mode)) { |
Alex Deucher | b4f15f8 | 2011-10-25 11:34:51 -0400 | [diff] [blame] | 653 | args.v3.sInput.ucDispPllConfig |= |
| 654 | DISPPLL_CONFIG_COHERENT_MODE; |
| 655 | /* 16200 or 27000 */ |
| 656 | args.v3.sInput.usPixelClock = cpu_to_le16(dp_clock / 10); |
| 657 | } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 658 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Alex Deucher | b4f15f8 | 2011-10-25 11:34:51 -0400 | [diff] [blame] | 659 | if (encoder_mode == ATOM_ENCODER_MODE_HDMI) |
| 660 | /* deep color support */ |
| 661 | args.v3.sInput.usPixelClock = |
| 662 | cpu_to_le16((mode->clock * bpc / 8) / 10); |
| 663 | if (dig->coherent_mode) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 664 | args.v3.sInput.ucDispPllConfig |= |
| 665 | DISPPLL_CONFIG_COHERENT_MODE; |
Alex Deucher | 9aa5999 | 2012-01-20 15:03:30 -0500 | [diff] [blame] | 666 | if (is_duallink) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 667 | args.v3.sInput.ucDispPllConfig |= |
Alex Deucher | b4f15f8 | 2011-10-25 11:34:51 -0400 | [diff] [blame] | 668 | DISPPLL_CONFIG_DUAL_LINK; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 669 | } |
Alex Deucher | 1d33e1f | 2011-10-31 08:58:47 -0400 | [diff] [blame] | 670 | if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != |
| 671 | ENCODER_OBJECT_ID_NONE) |
| 672 | args.v3.sInput.ucExtTransmitterID = |
| 673 | radeon_encoder_get_dp_bridge_encoder_id(encoder); |
| 674 | else |
Alex Deucher | cc9f67a | 2011-06-16 10:06:16 -0400 | [diff] [blame] | 675 | args.v3.sInput.ucExtTransmitterID = 0; |
| 676 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 677 | atom_execute_table(rdev->mode_info.atom_context, |
| 678 | index, (uint32_t *)&args); |
| 679 | adjusted_clock = le32_to_cpu(args.v3.sOutput.ulDispPllFreq) * 10; |
| 680 | if (args.v3.sOutput.ucRefDiv) { |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 681 | radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; |
| 682 | radeon_crtc->pll_flags |= RADEON_PLL_USE_REF_DIV; |
| 683 | radeon_crtc->pll_reference_div = args.v3.sOutput.ucRefDiv; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 684 | } |
| 685 | if (args.v3.sOutput.ucPostDiv) { |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 686 | radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; |
| 687 | radeon_crtc->pll_flags |= RADEON_PLL_USE_POST_DIV; |
| 688 | radeon_crtc->pll_post_div = args.v3.sOutput.ucPostDiv; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 689 | } |
| 690 | break; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 691 | default: |
| 692 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 693 | return adjusted_clock; |
| 694 | } |
| 695 | break; |
| 696 | default: |
| 697 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 698 | return adjusted_clock; |
| 699 | } |
Alex Deucher | d56ef9c | 2009-10-27 12:11:09 -0400 | [diff] [blame] | 700 | } |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 701 | return adjusted_clock; |
| 702 | } |
| 703 | |
| 704 | union set_pixel_clock { |
| 705 | SET_PIXEL_CLOCK_PS_ALLOCATION base; |
| 706 | PIXEL_CLOCK_PARAMETERS v1; |
| 707 | PIXEL_CLOCK_PARAMETERS_V2 v2; |
| 708 | PIXEL_CLOCK_PARAMETERS_V3 v3; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 709 | PIXEL_CLOCK_PARAMETERS_V5 v5; |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 710 | PIXEL_CLOCK_PARAMETERS_V6 v6; |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 711 | }; |
| 712 | |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 713 | /* on DCE5, make sure the voltage is high enough to support the |
| 714 | * required disp clk. |
| 715 | */ |
Alex Deucher | f3f1f03 | 2012-03-20 17:18:04 -0400 | [diff] [blame] | 716 | static void atombios_crtc_set_disp_eng_pll(struct radeon_device *rdev, |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 717 | u32 dispclk) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 718 | { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 719 | u8 frev, crev; |
| 720 | int index; |
| 721 | union set_pixel_clock args; |
| 722 | |
| 723 | memset(&args, 0, sizeof(args)); |
| 724 | |
| 725 | index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 726 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
| 727 | &crev)) |
| 728 | return; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 729 | |
| 730 | switch (frev) { |
| 731 | case 1: |
| 732 | switch (crev) { |
| 733 | case 5: |
| 734 | /* if the default dcpll clock is specified, |
| 735 | * SetPixelClock provides the dividers |
| 736 | */ |
| 737 | args.v5.ucCRTC = ATOM_CRTC_INVALID; |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 738 | args.v5.usPixelClock = cpu_to_le16(dispclk); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 739 | args.v5.ucPpll = ATOM_DCPLL; |
| 740 | break; |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 741 | case 6: |
| 742 | /* if the default dcpll clock is specified, |
| 743 | * SetPixelClock provides the dividers |
| 744 | */ |
Alex Deucher | 265aa6c | 2011-02-14 16:16:22 -0500 | [diff] [blame] | 745 | args.v6.ulDispEngClkFreq = cpu_to_le32(dispclk); |
Alex Deucher | 8542c12 | 2012-07-13 11:04:37 -0400 | [diff] [blame] | 746 | if (ASIC_IS_DCE61(rdev) || ASIC_IS_DCE8(rdev)) |
Alex Deucher | 729b95e | 2012-03-20 17:18:31 -0400 | [diff] [blame] | 747 | args.v6.ucPpll = ATOM_EXT_PLL1; |
| 748 | else if (ASIC_IS_DCE6(rdev)) |
Alex Deucher | f3f1f03 | 2012-03-20 17:18:04 -0400 | [diff] [blame] | 749 | args.v6.ucPpll = ATOM_PPLL0; |
| 750 | else |
| 751 | args.v6.ucPpll = ATOM_DCPLL; |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 752 | break; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 753 | default: |
| 754 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 755 | return; |
| 756 | } |
| 757 | break; |
| 758 | default: |
| 759 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 760 | return; |
| 761 | } |
| 762 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 763 | } |
| 764 | |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 765 | static void atombios_crtc_program_pll(struct drm_crtc *crtc, |
Benjamin Herrenschmidt | f1bece7 | 2011-07-13 16:28:15 +1000 | [diff] [blame] | 766 | u32 crtc_id, |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 767 | int pll_id, |
| 768 | u32 encoder_mode, |
| 769 | u32 encoder_id, |
| 770 | u32 clock, |
| 771 | u32 ref_div, |
| 772 | u32 fb_div, |
| 773 | u32 frac_fb_div, |
Alex Deucher | df271be | 2011-05-20 04:34:15 -0400 | [diff] [blame] | 774 | u32 post_div, |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 775 | int bpc, |
| 776 | bool ss_enabled, |
| 777 | struct radeon_atom_ss *ss) |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 778 | { |
| 779 | struct drm_device *dev = crtc->dev; |
| 780 | struct radeon_device *rdev = dev->dev_private; |
| 781 | u8 frev, crev; |
| 782 | int index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); |
| 783 | union set_pixel_clock args; |
| 784 | |
| 785 | memset(&args, 0, sizeof(args)); |
| 786 | |
| 787 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, |
| 788 | &crev)) |
| 789 | return; |
| 790 | |
| 791 | switch (frev) { |
| 792 | case 1: |
| 793 | switch (crev) { |
| 794 | case 1: |
| 795 | if (clock == ATOM_DISABLE) |
| 796 | return; |
| 797 | args.v1.usPixelClock = cpu_to_le16(clock / 10); |
| 798 | args.v1.usRefDiv = cpu_to_le16(ref_div); |
| 799 | args.v1.usFbDiv = cpu_to_le16(fb_div); |
| 800 | args.v1.ucFracFbDiv = frac_fb_div; |
| 801 | args.v1.ucPostDiv = post_div; |
| 802 | args.v1.ucPpll = pll_id; |
| 803 | args.v1.ucCRTC = crtc_id; |
| 804 | args.v1.ucRefDivSrc = 1; |
| 805 | break; |
| 806 | case 2: |
| 807 | args.v2.usPixelClock = cpu_to_le16(clock / 10); |
| 808 | args.v2.usRefDiv = cpu_to_le16(ref_div); |
| 809 | args.v2.usFbDiv = cpu_to_le16(fb_div); |
| 810 | args.v2.ucFracFbDiv = frac_fb_div; |
| 811 | args.v2.ucPostDiv = post_div; |
| 812 | args.v2.ucPpll = pll_id; |
| 813 | args.v2.ucCRTC = crtc_id; |
| 814 | args.v2.ucRefDivSrc = 1; |
| 815 | break; |
| 816 | case 3: |
| 817 | args.v3.usPixelClock = cpu_to_le16(clock / 10); |
| 818 | args.v3.usRefDiv = cpu_to_le16(ref_div); |
| 819 | args.v3.usFbDiv = cpu_to_le16(fb_div); |
| 820 | args.v3.ucFracFbDiv = frac_fb_div; |
| 821 | args.v3.ucPostDiv = post_div; |
| 822 | args.v3.ucPpll = pll_id; |
Alex Deucher | e729586 | 2012-09-12 17:58:07 -0400 | [diff] [blame] | 823 | if (crtc_id == ATOM_CRTC2) |
| 824 | args.v3.ucMiscInfo = PIXEL_CLOCK_MISC_CRTC_SEL_CRTC2; |
| 825 | else |
| 826 | args.v3.ucMiscInfo = PIXEL_CLOCK_MISC_CRTC_SEL_CRTC1; |
Alex Deucher | 6f15c50 | 2011-05-20 12:36:12 -0400 | [diff] [blame] | 827 | if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) |
| 828 | args.v3.ucMiscInfo |= PIXEL_CLOCK_MISC_REF_DIV_SRC; |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 829 | args.v3.ucTransmitterId = encoder_id; |
| 830 | args.v3.ucEncoderMode = encoder_mode; |
| 831 | break; |
| 832 | case 5: |
| 833 | args.v5.ucCRTC = crtc_id; |
| 834 | args.v5.usPixelClock = cpu_to_le16(clock / 10); |
| 835 | args.v5.ucRefDiv = ref_div; |
| 836 | args.v5.usFbDiv = cpu_to_le16(fb_div); |
| 837 | args.v5.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); |
| 838 | args.v5.ucPostDiv = post_div; |
| 839 | args.v5.ucMiscInfo = 0; /* HDMI depth, etc. */ |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 840 | if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) |
| 841 | args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_REF_DIV_SRC; |
Alex Deucher | df271be | 2011-05-20 04:34:15 -0400 | [diff] [blame] | 842 | switch (bpc) { |
| 843 | case 8: |
| 844 | default: |
| 845 | args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_24BPP; |
| 846 | break; |
| 847 | case 10: |
| 848 | args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_30BPP; |
| 849 | break; |
| 850 | } |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 851 | args.v5.ucTransmitterID = encoder_id; |
| 852 | args.v5.ucEncoderMode = encoder_mode; |
| 853 | args.v5.ucPpll = pll_id; |
| 854 | break; |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 855 | case 6: |
Benjamin Herrenschmidt | f1bece7 | 2011-07-13 16:28:15 +1000 | [diff] [blame] | 856 | args.v6.ulDispEngClkFreq = cpu_to_le32(crtc_id << 24 | clock / 10); |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 857 | args.v6.ucRefDiv = ref_div; |
| 858 | args.v6.usFbDiv = cpu_to_le16(fb_div); |
| 859 | args.v6.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); |
| 860 | args.v6.ucPostDiv = post_div; |
| 861 | args.v6.ucMiscInfo = 0; /* HDMI depth, etc. */ |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 862 | if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) |
| 863 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_REF_DIV_SRC; |
Alex Deucher | df271be | 2011-05-20 04:34:15 -0400 | [diff] [blame] | 864 | switch (bpc) { |
| 865 | case 8: |
| 866 | default: |
| 867 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_24BPP; |
| 868 | break; |
| 869 | case 10: |
| 870 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_30BPP; |
| 871 | break; |
| 872 | case 12: |
| 873 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_36BPP; |
| 874 | break; |
| 875 | case 16: |
| 876 | args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_48BPP; |
| 877 | break; |
| 878 | } |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 879 | args.v6.ucTransmitterID = encoder_id; |
| 880 | args.v6.ucEncoderMode = encoder_mode; |
| 881 | args.v6.ucPpll = pll_id; |
| 882 | break; |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 883 | default: |
| 884 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 885 | return; |
| 886 | } |
| 887 | break; |
| 888 | default: |
| 889 | DRM_ERROR("Unknown table version %d %d\n", frev, crev); |
| 890 | return; |
| 891 | } |
| 892 | |
| 893 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 894 | } |
| 895 | |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 896 | static bool atombios_crtc_prepare_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) |
| 897 | { |
| 898 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 899 | struct drm_device *dev = crtc->dev; |
| 900 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 901 | struct radeon_encoder *radeon_encoder = |
| 902 | to_radeon_encoder(radeon_crtc->encoder); |
| 903 | int encoder_mode = atombios_get_encoder_mode(radeon_crtc->encoder); |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 904 | |
| 905 | radeon_crtc->bpc = 8; |
| 906 | radeon_crtc->ss_enabled = false; |
| 907 | |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 908 | if ((radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) || |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 909 | (radeon_encoder_get_dp_bridge_encoder_id(radeon_crtc->encoder) != ENCODER_OBJECT_ID_NONE)) { |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 910 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 911 | struct drm_connector *connector = |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 912 | radeon_get_connector_for_encoder(radeon_crtc->encoder); |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 913 | struct radeon_connector *radeon_connector = |
| 914 | to_radeon_connector(connector); |
| 915 | struct radeon_connector_atom_dig *dig_connector = |
| 916 | radeon_connector->con_priv; |
| 917 | int dp_clock; |
| 918 | radeon_crtc->bpc = radeon_get_monitor_bpc(connector); |
| 919 | |
| 920 | switch (encoder_mode) { |
| 921 | case ATOM_ENCODER_MODE_DP_MST: |
| 922 | case ATOM_ENCODER_MODE_DP: |
| 923 | /* DP/eDP */ |
| 924 | dp_clock = dig_connector->dp_clock / 10; |
| 925 | if (ASIC_IS_DCE4(rdev)) |
| 926 | radeon_crtc->ss_enabled = |
| 927 | radeon_atombios_get_asic_ss_info(rdev, &radeon_crtc->ss, |
| 928 | ASIC_INTERNAL_SS_ON_DP, |
| 929 | dp_clock); |
| 930 | else { |
| 931 | if (dp_clock == 16200) { |
| 932 | radeon_crtc->ss_enabled = |
| 933 | radeon_atombios_get_ppll_ss_info(rdev, |
| 934 | &radeon_crtc->ss, |
| 935 | ATOM_DP_SS_ID2); |
| 936 | if (!radeon_crtc->ss_enabled) |
| 937 | radeon_crtc->ss_enabled = |
| 938 | radeon_atombios_get_ppll_ss_info(rdev, |
| 939 | &radeon_crtc->ss, |
| 940 | ATOM_DP_SS_ID1); |
| 941 | } else |
| 942 | radeon_crtc->ss_enabled = |
| 943 | radeon_atombios_get_ppll_ss_info(rdev, |
| 944 | &radeon_crtc->ss, |
| 945 | ATOM_DP_SS_ID1); |
| 946 | } |
| 947 | break; |
| 948 | case ATOM_ENCODER_MODE_LVDS: |
| 949 | if (ASIC_IS_DCE4(rdev)) |
| 950 | radeon_crtc->ss_enabled = |
| 951 | radeon_atombios_get_asic_ss_info(rdev, |
| 952 | &radeon_crtc->ss, |
| 953 | dig->lcd_ss_id, |
| 954 | mode->clock / 10); |
| 955 | else |
| 956 | radeon_crtc->ss_enabled = |
| 957 | radeon_atombios_get_ppll_ss_info(rdev, |
| 958 | &radeon_crtc->ss, |
| 959 | dig->lcd_ss_id); |
| 960 | break; |
| 961 | case ATOM_ENCODER_MODE_DVI: |
| 962 | if (ASIC_IS_DCE4(rdev)) |
| 963 | radeon_crtc->ss_enabled = |
| 964 | radeon_atombios_get_asic_ss_info(rdev, |
| 965 | &radeon_crtc->ss, |
| 966 | ASIC_INTERNAL_SS_ON_TMDS, |
| 967 | mode->clock / 10); |
| 968 | break; |
| 969 | case ATOM_ENCODER_MODE_HDMI: |
| 970 | if (ASIC_IS_DCE4(rdev)) |
| 971 | radeon_crtc->ss_enabled = |
| 972 | radeon_atombios_get_asic_ss_info(rdev, |
| 973 | &radeon_crtc->ss, |
| 974 | ASIC_INTERNAL_SS_ON_HDMI, |
| 975 | mode->clock / 10); |
| 976 | break; |
| 977 | default: |
| 978 | break; |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | /* adjust pixel clock as needed */ |
| 983 | radeon_crtc->adjusted_clock = atombios_adjust_pll(crtc, mode); |
| 984 | |
| 985 | return true; |
| 986 | } |
| 987 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 988 | 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] | 989 | { |
| 990 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 991 | struct drm_device *dev = crtc->dev; |
| 992 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 993 | struct radeon_encoder *radeon_encoder = |
| 994 | to_radeon_encoder(radeon_crtc->encoder); |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 995 | u32 pll_clock = mode->clock; |
| 996 | u32 ref_div = 0, fb_div = 0, frac_fb_div = 0, post_div = 0; |
| 997 | struct radeon_pll *pll; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 998 | int encoder_mode = atombios_get_encoder_mode(radeon_crtc->encoder); |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 999 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1000 | switch (radeon_crtc->pll_id) { |
| 1001 | case ATOM_PPLL1: |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 1002 | pll = &rdev->clock.p1pll; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1003 | break; |
| 1004 | case ATOM_PPLL2: |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 1005 | pll = &rdev->clock.p2pll; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1006 | break; |
| 1007 | case ATOM_DCPLL: |
| 1008 | case ATOM_PPLL_INVALID: |
Stefan Richter | 921d98b | 2010-05-26 10:27:44 +1000 | [diff] [blame] | 1009 | default: |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1010 | pll = &rdev->clock.dcpll; |
| 1011 | break; |
| 1012 | } |
Alex Deucher | 4eaeca3 | 2010-01-19 17:32:27 -0500 | [diff] [blame] | 1013 | |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1014 | /* update pll params */ |
| 1015 | pll->flags = radeon_crtc->pll_flags; |
| 1016 | pll->reference_div = radeon_crtc->pll_reference_div; |
| 1017 | pll->post_div = radeon_crtc->pll_post_div; |
Alex Deucher | 2606c88 | 2009-10-08 13:36:21 -0400 | [diff] [blame] | 1018 | |
Alex Deucher | 64146f8 | 2011-03-22 01:46:12 -0400 | [diff] [blame] | 1019 | if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) |
| 1020 | /* TV seems to prefer the legacy algo on some boards */ |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1021 | radeon_compute_pll_legacy(pll, radeon_crtc->adjusted_clock, &pll_clock, |
| 1022 | &fb_div, &frac_fb_div, &ref_div, &post_div); |
Alex Deucher | 64146f8 | 2011-03-22 01:46:12 -0400 | [diff] [blame] | 1023 | else if (ASIC_IS_AVIVO(rdev)) |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1024 | radeon_compute_pll_avivo(pll, radeon_crtc->adjusted_clock, &pll_clock, |
| 1025 | &fb_div, &frac_fb_div, &ref_div, &post_div); |
Alex Deucher | 619efb1 | 2011-01-31 16:48:53 -0500 | [diff] [blame] | 1026 | else |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1027 | radeon_compute_pll_legacy(pll, radeon_crtc->adjusted_clock, &pll_clock, |
| 1028 | &fb_div, &frac_fb_div, &ref_div, &post_div); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1029 | |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1030 | atombios_crtc_program_ss(rdev, ATOM_DISABLE, radeon_crtc->pll_id, |
| 1031 | radeon_crtc->crtc_id, &radeon_crtc->ss); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1032 | |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1033 | atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, |
| 1034 | encoder_mode, radeon_encoder->encoder_id, mode->clock, |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1035 | ref_div, fb_div, frac_fb_div, post_div, |
| 1036 | radeon_crtc->bpc, radeon_crtc->ss_enabled, &radeon_crtc->ss); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1037 | |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1038 | if (radeon_crtc->ss_enabled) { |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1039 | /* calculate ss amount and step size */ |
| 1040 | if (ASIC_IS_DCE4(rdev)) { |
| 1041 | u32 step_size; |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1042 | u32 amount = (((fb_div * 10) + frac_fb_div) * radeon_crtc->ss.percentage) / 10000; |
| 1043 | radeon_crtc->ss.amount = (amount / 10) & ATOM_PPLL_SS_AMOUNT_V2_FBDIV_MASK; |
| 1044 | radeon_crtc->ss.amount |= ((amount - (amount / 10)) << ATOM_PPLL_SS_AMOUNT_V2_NFRAC_SHIFT) & |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1045 | ATOM_PPLL_SS_AMOUNT_V2_NFRAC_MASK; |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1046 | if (radeon_crtc->ss.type & ATOM_PPLL_SS_TYPE_V2_CENTRE_SPREAD) |
| 1047 | step_size = (4 * amount * ref_div * (radeon_crtc->ss.rate * 2048)) / |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1048 | (125 * 25 * pll->reference_freq / 100); |
| 1049 | else |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1050 | step_size = (2 * amount * ref_div * (radeon_crtc->ss.rate * 2048)) / |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1051 | (125 * 25 * pll->reference_freq / 100); |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1052 | radeon_crtc->ss.step = step_size; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1055 | atombios_crtc_program_ss(rdev, ATOM_ENABLE, radeon_crtc->pll_id, |
| 1056 | radeon_crtc->crtc_id, &radeon_crtc->ss); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1057 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
Alex Deucher | c9417bd | 2011-02-06 14:23:26 -0500 | [diff] [blame] | 1060 | static int dce4_crtc_do_set_base(struct drm_crtc *crtc, |
| 1061 | struct drm_framebuffer *fb, |
| 1062 | int x, int y, int atomic) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1063 | { |
| 1064 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1065 | struct drm_device *dev = crtc->dev; |
| 1066 | struct radeon_device *rdev = dev->dev_private; |
| 1067 | struct radeon_framebuffer *radeon_fb; |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1068 | struct drm_framebuffer *target_fb; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1069 | struct drm_gem_object *obj; |
| 1070 | struct radeon_bo *rbo; |
| 1071 | uint64_t fb_location; |
| 1072 | uint32_t fb_format, fb_pitch_pixels, tiling_flags; |
Jerome Glisse | 285484e | 2011-12-16 17:03:42 -0500 | [diff] [blame] | 1073 | unsigned bankw, bankh, mtaspect, tile_split; |
Alex Deucher | fa6bee4 | 2011-01-25 11:55:50 -0500 | [diff] [blame] | 1074 | u32 fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_NONE); |
Alex Deucher | adcfde5 | 2011-05-27 10:05:03 -0400 | [diff] [blame] | 1075 | u32 tmp, viewport_w, viewport_h; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1076 | int r; |
| 1077 | |
| 1078 | /* no fb bound */ |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1079 | if (!atomic && !crtc->fb) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1080 | DRM_DEBUG_KMS("No FB bound\n"); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1081 | return 0; |
| 1082 | } |
| 1083 | |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1084 | if (atomic) { |
| 1085 | radeon_fb = to_radeon_framebuffer(fb); |
| 1086 | target_fb = fb; |
| 1087 | } |
| 1088 | else { |
| 1089 | radeon_fb = to_radeon_framebuffer(crtc->fb); |
| 1090 | target_fb = crtc->fb; |
| 1091 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1092 | |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1093 | /* If atomic, assume fb object is pinned & idle & fenced and |
| 1094 | * just update base pointers |
| 1095 | */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1096 | obj = radeon_fb->obj; |
Daniel Vetter | 7e4d15d | 2011-02-18 17:59:17 +0100 | [diff] [blame] | 1097 | rbo = gem_to_radeon_bo(obj); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1098 | r = radeon_bo_reserve(rbo, false); |
| 1099 | if (unlikely(r != 0)) |
| 1100 | return r; |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1101 | |
| 1102 | if (atomic) |
| 1103 | fb_location = radeon_bo_gpu_offset(rbo); |
| 1104 | else { |
| 1105 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); |
| 1106 | if (unlikely(r != 0)) { |
| 1107 | radeon_bo_unreserve(rbo); |
| 1108 | return -EINVAL; |
| 1109 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1110 | } |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1111 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1112 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); |
| 1113 | radeon_bo_unreserve(rbo); |
| 1114 | |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1115 | switch (target_fb->bits_per_pixel) { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1116 | case 8: |
| 1117 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_8BPP) | |
| 1118 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_INDEXED)); |
| 1119 | break; |
| 1120 | case 15: |
| 1121 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | |
| 1122 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB1555)); |
| 1123 | break; |
| 1124 | case 16: |
| 1125 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | |
| 1126 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB565)); |
Alex Deucher | fa6bee4 | 2011-01-25 11:55:50 -0500 | [diff] [blame] | 1127 | #ifdef __BIG_ENDIAN |
| 1128 | fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN16); |
| 1129 | #endif |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1130 | break; |
| 1131 | case 24: |
| 1132 | case 32: |
| 1133 | fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) | |
| 1134 | EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB8888)); |
Alex Deucher | fa6bee4 | 2011-01-25 11:55:50 -0500 | [diff] [blame] | 1135 | #ifdef __BIG_ENDIAN |
| 1136 | fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN32); |
| 1137 | #endif |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1138 | break; |
| 1139 | default: |
| 1140 | DRM_ERROR("Unsupported screen depth %d\n", |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1141 | target_fb->bits_per_pixel); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1142 | return -EINVAL; |
| 1143 | } |
| 1144 | |
Alex Deucher | 392e372 | 2011-11-28 14:49:27 -0500 | [diff] [blame] | 1145 | if (tiling_flags & RADEON_TILING_MACRO) { |
Alex Deucher | 8da0e50 | 2012-07-11 18:38:29 -0400 | [diff] [blame] | 1146 | if (rdev->family >= CHIP_BONAIRE) |
| 1147 | tmp = rdev->config.cik.tile_config; |
| 1148 | else if (rdev->family >= CHIP_TAHITI) |
Alex Deucher | b7019b2 | 2012-06-14 15:58:25 -0400 | [diff] [blame] | 1149 | tmp = rdev->config.si.tile_config; |
| 1150 | else if (rdev->family >= CHIP_CAYMAN) |
Alex Deucher | 392e372 | 2011-11-28 14:49:27 -0500 | [diff] [blame] | 1151 | tmp = rdev->config.cayman.tile_config; |
| 1152 | else |
| 1153 | tmp = rdev->config.evergreen.tile_config; |
| 1154 | |
| 1155 | switch ((tmp & 0xf0) >> 4) { |
| 1156 | case 0: /* 4 banks */ |
| 1157 | fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_4_BANK); |
| 1158 | break; |
| 1159 | case 1: /* 8 banks */ |
| 1160 | default: |
| 1161 | fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_8_BANK); |
| 1162 | break; |
| 1163 | case 2: /* 16 banks */ |
| 1164 | fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_16_BANK); |
| 1165 | break; |
| 1166 | } |
| 1167 | |
Alex Deucher | 97d6632 | 2010-05-20 12:12:48 -0400 | [diff] [blame] | 1168 | fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_2D_TILED_THIN1); |
Jerome Glisse | 285484e | 2011-12-16 17:03:42 -0500 | [diff] [blame] | 1169 | |
| 1170 | evergreen_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split); |
| 1171 | fb_format |= EVERGREEN_GRPH_TILE_SPLIT(tile_split); |
| 1172 | fb_format |= EVERGREEN_GRPH_BANK_WIDTH(bankw); |
| 1173 | fb_format |= EVERGREEN_GRPH_BANK_HEIGHT(bankh); |
| 1174 | fb_format |= EVERGREEN_GRPH_MACRO_TILE_ASPECT(mtaspect); |
Alex Deucher | 8da0e50 | 2012-07-11 18:38:29 -0400 | [diff] [blame] | 1175 | if (rdev->family >= CHIP_BONAIRE) { |
| 1176 | /* XXX need to know more about the surface tiling mode */ |
| 1177 | fb_format |= CIK_GRPH_MICRO_TILE_MODE(CIK_DISPLAY_MICRO_TILING); |
| 1178 | } |
Alex Deucher | 392e372 | 2011-11-28 14:49:27 -0500 | [diff] [blame] | 1179 | } else if (tiling_flags & RADEON_TILING_MICRO) |
Alex Deucher | 97d6632 | 2010-05-20 12:12:48 -0400 | [diff] [blame] | 1180 | fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_1D_TILED_THIN1); |
| 1181 | |
Alex Deucher | 8da0e50 | 2012-07-11 18:38:29 -0400 | [diff] [blame] | 1182 | if (rdev->family >= CHIP_BONAIRE) { |
| 1183 | u32 num_pipe_configs = rdev->config.cik.max_tile_pipes; |
| 1184 | u32 num_rb = rdev->config.cik.max_backends_per_se; |
| 1185 | if (num_pipe_configs > 8) |
| 1186 | num_pipe_configs = 8; |
| 1187 | if (num_pipe_configs == 8) |
| 1188 | fb_format |= CIK_GRPH_PIPE_CONFIG(CIK_ADDR_SURF_P8_32x32_16x16); |
| 1189 | else if (num_pipe_configs == 4) { |
| 1190 | if (num_rb == 4) |
| 1191 | fb_format |= CIK_GRPH_PIPE_CONFIG(CIK_ADDR_SURF_P4_16x16); |
| 1192 | else if (num_rb < 4) |
| 1193 | fb_format |= CIK_GRPH_PIPE_CONFIG(CIK_ADDR_SURF_P4_8x16); |
| 1194 | } else if (num_pipe_configs == 2) |
| 1195 | fb_format |= CIK_GRPH_PIPE_CONFIG(CIK_ADDR_SURF_P2); |
| 1196 | } else if ((rdev->family == CHIP_TAHITI) || |
| 1197 | (rdev->family == CHIP_PITCAIRN)) |
Alex Deucher | b7019b2 | 2012-06-14 15:58:25 -0400 | [diff] [blame] | 1198 | fb_format |= SI_GRPH_PIPE_CONFIG(SI_ADDR_SURF_P8_32x32_8x16); |
| 1199 | else if (rdev->family == CHIP_VERDE) |
| 1200 | fb_format |= SI_GRPH_PIPE_CONFIG(SI_ADDR_SURF_P4_8x16); |
| 1201 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1202 | switch (radeon_crtc->crtc_id) { |
| 1203 | case 0: |
| 1204 | WREG32(AVIVO_D1VGA_CONTROL, 0); |
| 1205 | break; |
| 1206 | case 1: |
| 1207 | WREG32(AVIVO_D2VGA_CONTROL, 0); |
| 1208 | break; |
| 1209 | case 2: |
| 1210 | WREG32(EVERGREEN_D3VGA_CONTROL, 0); |
| 1211 | break; |
| 1212 | case 3: |
| 1213 | WREG32(EVERGREEN_D4VGA_CONTROL, 0); |
| 1214 | break; |
| 1215 | case 4: |
| 1216 | WREG32(EVERGREEN_D5VGA_CONTROL, 0); |
| 1217 | break; |
| 1218 | case 5: |
| 1219 | WREG32(EVERGREEN_D6VGA_CONTROL, 0); |
| 1220 | break; |
| 1221 | default: |
| 1222 | break; |
| 1223 | } |
| 1224 | |
| 1225 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, |
| 1226 | upper_32_bits(fb_location)); |
| 1227 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, |
| 1228 | upper_32_bits(fb_location)); |
| 1229 | WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 1230 | (u32)fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); |
| 1231 | WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 1232 | (u32) fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); |
| 1233 | WREG32(EVERGREEN_GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); |
Alex Deucher | fa6bee4 | 2011-01-25 11:55:50 -0500 | [diff] [blame] | 1234 | WREG32(EVERGREEN_GRPH_SWAP_CONTROL + radeon_crtc->crtc_offset, fb_swap); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1235 | |
| 1236 | WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); |
| 1237 | WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); |
| 1238 | WREG32(EVERGREEN_GRPH_X_START + radeon_crtc->crtc_offset, 0); |
| 1239 | WREG32(EVERGREEN_GRPH_Y_START + radeon_crtc->crtc_offset, 0); |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1240 | WREG32(EVERGREEN_GRPH_X_END + radeon_crtc->crtc_offset, target_fb->width); |
| 1241 | WREG32(EVERGREEN_GRPH_Y_END + radeon_crtc->crtc_offset, target_fb->height); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1242 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 1243 | fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1244 | WREG32(EVERGREEN_GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); |
| 1245 | WREG32(EVERGREEN_GRPH_ENABLE + radeon_crtc->crtc_offset, 1); |
| 1246 | |
Alex Deucher | 8da0e50 | 2012-07-11 18:38:29 -0400 | [diff] [blame] | 1247 | if (rdev->family >= CHIP_BONAIRE) |
| 1248 | WREG32(CIK_LB_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, |
| 1249 | target_fb->height); |
| 1250 | else |
| 1251 | WREG32(EVERGREEN_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, |
| 1252 | target_fb->height); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1253 | x &= ~3; |
| 1254 | y &= ~1; |
| 1255 | WREG32(EVERGREEN_VIEWPORT_START + radeon_crtc->crtc_offset, |
| 1256 | (x << 16) | y); |
Alex Deucher | adcfde5 | 2011-05-27 10:05:03 -0400 | [diff] [blame] | 1257 | viewport_w = crtc->mode.hdisplay; |
| 1258 | viewport_h = (crtc->mode.vdisplay + 1) & ~1; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1259 | WREG32(EVERGREEN_VIEWPORT_SIZE + radeon_crtc->crtc_offset, |
Alex Deucher | adcfde5 | 2011-05-27 10:05:03 -0400 | [diff] [blame] | 1260 | (viewport_w << 16) | viewport_h); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1261 | |
Alex Deucher | fb9674b | 2011-04-02 09:15:50 -0400 | [diff] [blame] | 1262 | /* pageflip setup */ |
| 1263 | /* make sure flip is at vb rather than hb */ |
| 1264 | tmp = RREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset); |
| 1265 | tmp &= ~EVERGREEN_GRPH_SURFACE_UPDATE_H_RETRACE_EN; |
| 1266 | WREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset, tmp); |
| 1267 | |
| 1268 | /* set pageflip to happen anywhere in vblank interval */ |
| 1269 | WREG32(EVERGREEN_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0); |
| 1270 | |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1271 | if (!atomic && fb && fb != crtc->fb) { |
| 1272 | radeon_fb = to_radeon_framebuffer(fb); |
Daniel Vetter | 7e4d15d | 2011-02-18 17:59:17 +0100 | [diff] [blame] | 1273 | rbo = gem_to_radeon_bo(radeon_fb->obj); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1274 | r = radeon_bo_reserve(rbo, false); |
| 1275 | if (unlikely(r != 0)) |
| 1276 | return r; |
| 1277 | radeon_bo_unpin(rbo); |
| 1278 | radeon_bo_unreserve(rbo); |
| 1279 | } |
| 1280 | |
| 1281 | /* Bytes per pixel may have changed */ |
| 1282 | radeon_bandwidth_update(rdev); |
| 1283 | |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1287 | static int avivo_crtc_do_set_base(struct drm_crtc *crtc, |
| 1288 | struct drm_framebuffer *fb, |
| 1289 | int x, int y, int atomic) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1290 | { |
| 1291 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1292 | struct drm_device *dev = crtc->dev; |
| 1293 | struct radeon_device *rdev = dev->dev_private; |
| 1294 | struct radeon_framebuffer *radeon_fb; |
| 1295 | struct drm_gem_object *obj; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1296 | struct radeon_bo *rbo; |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1297 | struct drm_framebuffer *target_fb; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1298 | uint64_t fb_location; |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 1299 | uint32_t fb_format, fb_pitch_pixels, tiling_flags; |
Alex Deucher | fa6bee4 | 2011-01-25 11:55:50 -0500 | [diff] [blame] | 1300 | u32 fb_swap = R600_D1GRPH_SWAP_ENDIAN_NONE; |
Alex Deucher | adcfde5 | 2011-05-27 10:05:03 -0400 | [diff] [blame] | 1301 | u32 tmp, viewport_w, viewport_h; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1302 | int r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1303 | |
Jerome Glisse | 2de3b48 | 2009-11-17 14:08:55 -0800 | [diff] [blame] | 1304 | /* no fb bound */ |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1305 | if (!atomic && !crtc->fb) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1306 | DRM_DEBUG_KMS("No FB bound\n"); |
Jerome Glisse | 2de3b48 | 2009-11-17 14:08:55 -0800 | [diff] [blame] | 1307 | return 0; |
| 1308 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1309 | |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1310 | if (atomic) { |
| 1311 | radeon_fb = to_radeon_framebuffer(fb); |
| 1312 | target_fb = fb; |
| 1313 | } |
| 1314 | else { |
| 1315 | radeon_fb = to_radeon_framebuffer(crtc->fb); |
| 1316 | target_fb = crtc->fb; |
| 1317 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1318 | |
| 1319 | obj = radeon_fb->obj; |
Daniel Vetter | 7e4d15d | 2011-02-18 17:59:17 +0100 | [diff] [blame] | 1320 | rbo = gem_to_radeon_bo(obj); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1321 | r = radeon_bo_reserve(rbo, false); |
| 1322 | if (unlikely(r != 0)) |
| 1323 | return r; |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1324 | |
| 1325 | /* If atomic, assume fb object is pinned & idle & fenced and |
| 1326 | * just update base pointers |
| 1327 | */ |
| 1328 | if (atomic) |
| 1329 | fb_location = radeon_bo_gpu_offset(rbo); |
| 1330 | else { |
| 1331 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); |
| 1332 | if (unlikely(r != 0)) { |
| 1333 | radeon_bo_unreserve(rbo); |
| 1334 | return -EINVAL; |
| 1335 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1336 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1337 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); |
| 1338 | radeon_bo_unreserve(rbo); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1339 | |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1340 | switch (target_fb->bits_per_pixel) { |
Dave Airlie | 41456df | 2009-09-16 10:15:21 +1000 | [diff] [blame] | 1341 | case 8: |
| 1342 | fb_format = |
| 1343 | AVIVO_D1GRPH_CONTROL_DEPTH_8BPP | |
| 1344 | AVIVO_D1GRPH_CONTROL_8BPP_INDEXED; |
| 1345 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1346 | case 15: |
| 1347 | fb_format = |
| 1348 | AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | |
| 1349 | AVIVO_D1GRPH_CONTROL_16BPP_ARGB1555; |
| 1350 | break; |
| 1351 | case 16: |
| 1352 | fb_format = |
| 1353 | AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | |
| 1354 | AVIVO_D1GRPH_CONTROL_16BPP_RGB565; |
Alex Deucher | fa6bee4 | 2011-01-25 11:55:50 -0500 | [diff] [blame] | 1355 | #ifdef __BIG_ENDIAN |
| 1356 | fb_swap = R600_D1GRPH_SWAP_ENDIAN_16BIT; |
| 1357 | #endif |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1358 | break; |
| 1359 | case 24: |
| 1360 | case 32: |
| 1361 | fb_format = |
| 1362 | AVIVO_D1GRPH_CONTROL_DEPTH_32BPP | |
| 1363 | AVIVO_D1GRPH_CONTROL_32BPP_ARGB8888; |
Alex Deucher | fa6bee4 | 2011-01-25 11:55:50 -0500 | [diff] [blame] | 1364 | #ifdef __BIG_ENDIAN |
| 1365 | fb_swap = R600_D1GRPH_SWAP_ENDIAN_32BIT; |
| 1366 | #endif |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1367 | break; |
| 1368 | default: |
| 1369 | DRM_ERROR("Unsupported screen depth %d\n", |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1370 | target_fb->bits_per_pixel); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1371 | return -EINVAL; |
| 1372 | } |
| 1373 | |
Alex Deucher | 40c4ac1 | 2010-05-20 12:04:59 -0400 | [diff] [blame] | 1374 | if (rdev->family >= CHIP_R600) { |
| 1375 | if (tiling_flags & RADEON_TILING_MACRO) |
| 1376 | fb_format |= R600_D1GRPH_ARRAY_MODE_2D_TILED_THIN1; |
| 1377 | else if (tiling_flags & RADEON_TILING_MICRO) |
| 1378 | fb_format |= R600_D1GRPH_ARRAY_MODE_1D_TILED_THIN1; |
| 1379 | } else { |
| 1380 | if (tiling_flags & RADEON_TILING_MACRO) |
| 1381 | fb_format |= AVIVO_D1GRPH_MACRO_ADDRESS_MODE; |
Dave Airlie | cf2f05d | 2009-12-08 15:45:13 +1000 | [diff] [blame] | 1382 | |
Alex Deucher | 40c4ac1 | 2010-05-20 12:04:59 -0400 | [diff] [blame] | 1383 | if (tiling_flags & RADEON_TILING_MICRO) |
| 1384 | fb_format |= AVIVO_D1GRPH_TILED; |
| 1385 | } |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 1386 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1387 | if (radeon_crtc->crtc_id == 0) |
| 1388 | WREG32(AVIVO_D1VGA_CONTROL, 0); |
| 1389 | else |
| 1390 | WREG32(AVIVO_D2VGA_CONTROL, 0); |
Alex Deucher | c290dad | 2009-10-22 16:12:34 -0400 | [diff] [blame] | 1391 | |
| 1392 | if (rdev->family >= CHIP_RV770) { |
| 1393 | if (radeon_crtc->crtc_id) { |
Alex Deucher | 9534787 | 2010-09-01 17:20:42 -0400 | [diff] [blame] | 1394 | WREG32(R700_D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); |
| 1395 | WREG32(R700_D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); |
Alex Deucher | c290dad | 2009-10-22 16:12:34 -0400 | [diff] [blame] | 1396 | } else { |
Alex Deucher | 9534787 | 2010-09-01 17:20:42 -0400 | [diff] [blame] | 1397 | WREG32(R700_D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); |
| 1398 | WREG32(R700_D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); |
Alex Deucher | c290dad | 2009-10-22 16:12:34 -0400 | [diff] [blame] | 1399 | } |
| 1400 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1401 | WREG32(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, |
| 1402 | (u32) fb_location); |
| 1403 | WREG32(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS + |
| 1404 | radeon_crtc->crtc_offset, (u32) fb_location); |
| 1405 | WREG32(AVIVO_D1GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); |
Alex Deucher | fa6bee4 | 2011-01-25 11:55:50 -0500 | [diff] [blame] | 1406 | if (rdev->family >= CHIP_R600) |
| 1407 | WREG32(R600_D1GRPH_SWAP_CONTROL + radeon_crtc->crtc_offset, fb_swap); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1408 | |
| 1409 | WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); |
| 1410 | WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); |
| 1411 | WREG32(AVIVO_D1GRPH_X_START + radeon_crtc->crtc_offset, 0); |
| 1412 | WREG32(AVIVO_D1GRPH_Y_START + radeon_crtc->crtc_offset, 0); |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1413 | WREG32(AVIVO_D1GRPH_X_END + radeon_crtc->crtc_offset, target_fb->width); |
| 1414 | WREG32(AVIVO_D1GRPH_Y_END + radeon_crtc->crtc_offset, target_fb->height); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1415 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 1416 | fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1417 | WREG32(AVIVO_D1GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); |
| 1418 | WREG32(AVIVO_D1GRPH_ENABLE + radeon_crtc->crtc_offset, 1); |
| 1419 | |
| 1420 | WREG32(AVIVO_D1MODE_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, |
Michel Dänzer | 1b61925 | 2012-02-01 12:09:55 +0100 | [diff] [blame] | 1421 | target_fb->height); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1422 | x &= ~3; |
| 1423 | y &= ~1; |
| 1424 | WREG32(AVIVO_D1MODE_VIEWPORT_START + radeon_crtc->crtc_offset, |
| 1425 | (x << 16) | y); |
Alex Deucher | adcfde5 | 2011-05-27 10:05:03 -0400 | [diff] [blame] | 1426 | viewport_w = crtc->mode.hdisplay; |
| 1427 | viewport_h = (crtc->mode.vdisplay + 1) & ~1; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1428 | WREG32(AVIVO_D1MODE_VIEWPORT_SIZE + radeon_crtc->crtc_offset, |
Alex Deucher | adcfde5 | 2011-05-27 10:05:03 -0400 | [diff] [blame] | 1429 | (viewport_w << 16) | viewport_h); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1430 | |
Alex Deucher | fb9674b | 2011-04-02 09:15:50 -0400 | [diff] [blame] | 1431 | /* pageflip setup */ |
| 1432 | /* make sure flip is at vb rather than hb */ |
| 1433 | tmp = RREG32(AVIVO_D1GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset); |
| 1434 | tmp &= ~AVIVO_D1GRPH_SURFACE_UPDATE_H_RETRACE_EN; |
| 1435 | WREG32(AVIVO_D1GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset, tmp); |
| 1436 | |
| 1437 | /* set pageflip to happen anywhere in vblank interval */ |
| 1438 | WREG32(AVIVO_D1MODE_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0); |
| 1439 | |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1440 | if (!atomic && fb && fb != crtc->fb) { |
| 1441 | radeon_fb = to_radeon_framebuffer(fb); |
Daniel Vetter | 7e4d15d | 2011-02-18 17:59:17 +0100 | [diff] [blame] | 1442 | rbo = gem_to_radeon_bo(radeon_fb->obj); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 1443 | r = radeon_bo_reserve(rbo, false); |
| 1444 | if (unlikely(r != 0)) |
| 1445 | return r; |
| 1446 | radeon_bo_unpin(rbo); |
| 1447 | radeon_bo_unreserve(rbo); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1448 | } |
Michel Dänzer | f30f37d | 2009-10-08 10:44:09 +0200 | [diff] [blame] | 1449 | |
| 1450 | /* Bytes per pixel may have changed */ |
| 1451 | radeon_bandwidth_update(rdev); |
| 1452 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1453 | return 0; |
| 1454 | } |
| 1455 | |
Alex Deucher | 54f088a | 2010-01-19 16:34:01 -0500 | [diff] [blame] | 1456 | int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
| 1457 | struct drm_framebuffer *old_fb) |
| 1458 | { |
| 1459 | struct drm_device *dev = crtc->dev; |
| 1460 | struct radeon_device *rdev = dev->dev_private; |
| 1461 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1462 | if (ASIC_IS_DCE4(rdev)) |
Alex Deucher | c9417bd | 2011-02-06 14:23:26 -0500 | [diff] [blame] | 1463 | return dce4_crtc_do_set_base(crtc, old_fb, x, y, 0); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1464 | else if (ASIC_IS_AVIVO(rdev)) |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1465 | return avivo_crtc_do_set_base(crtc, old_fb, x, y, 0); |
Alex Deucher | 54f088a | 2010-01-19 16:34:01 -0500 | [diff] [blame] | 1466 | else |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1467 | return radeon_crtc_do_set_base(crtc, old_fb, x, y, 0); |
| 1468 | } |
| 1469 | |
| 1470 | int atombios_crtc_set_base_atomic(struct drm_crtc *crtc, |
| 1471 | struct drm_framebuffer *fb, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 1472 | int x, int y, enum mode_set_atomic state) |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1473 | { |
| 1474 | struct drm_device *dev = crtc->dev; |
| 1475 | struct radeon_device *rdev = dev->dev_private; |
| 1476 | |
| 1477 | if (ASIC_IS_DCE4(rdev)) |
Alex Deucher | c9417bd | 2011-02-06 14:23:26 -0500 | [diff] [blame] | 1478 | return dce4_crtc_do_set_base(crtc, fb, x, y, 1); |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1479 | else if (ASIC_IS_AVIVO(rdev)) |
| 1480 | return avivo_crtc_do_set_base(crtc, fb, x, y, 1); |
| 1481 | else |
| 1482 | return radeon_crtc_do_set_base(crtc, fb, x, y, 1); |
Alex Deucher | 54f088a | 2010-01-19 16:34:01 -0500 | [diff] [blame] | 1483 | } |
| 1484 | |
Alex Deucher | 615e0cb | 2010-01-20 16:22:53 -0500 | [diff] [blame] | 1485 | /* properly set additional regs when using atombios */ |
| 1486 | static void radeon_legacy_atom_fixup(struct drm_crtc *crtc) |
| 1487 | { |
| 1488 | struct drm_device *dev = crtc->dev; |
| 1489 | struct radeon_device *rdev = dev->dev_private; |
| 1490 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1491 | u32 disp_merge_cntl; |
| 1492 | |
| 1493 | switch (radeon_crtc->crtc_id) { |
| 1494 | case 0: |
| 1495 | disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL); |
| 1496 | disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN; |
| 1497 | WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl); |
| 1498 | break; |
| 1499 | case 1: |
| 1500 | disp_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL); |
| 1501 | disp_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN; |
| 1502 | WREG32(RADEON_DISP2_MERGE_CNTL, disp_merge_cntl); |
| 1503 | WREG32(RADEON_FP_H2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_H_SYNC_STRT_WID)); |
| 1504 | WREG32(RADEON_FP_V2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_V_SYNC_STRT_WID)); |
| 1505 | break; |
| 1506 | } |
| 1507 | } |
| 1508 | |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1509 | /** |
| 1510 | * radeon_get_pll_use_mask - look up a mask of which pplls are in use |
| 1511 | * |
| 1512 | * @crtc: drm crtc |
| 1513 | * |
| 1514 | * Returns the mask of which PPLLs (Pixel PLLs) are in use. |
| 1515 | */ |
| 1516 | static u32 radeon_get_pll_use_mask(struct drm_crtc *crtc) |
| 1517 | { |
| 1518 | struct drm_device *dev = crtc->dev; |
| 1519 | struct drm_crtc *test_crtc; |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1520 | struct radeon_crtc *test_radeon_crtc; |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1521 | u32 pll_in_use = 0; |
| 1522 | |
| 1523 | list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { |
| 1524 | if (crtc == test_crtc) |
| 1525 | continue; |
| 1526 | |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1527 | test_radeon_crtc = to_radeon_crtc(test_crtc); |
| 1528 | if (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID) |
| 1529 | pll_in_use |= (1 << test_radeon_crtc->pll_id); |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1530 | } |
| 1531 | return pll_in_use; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
| 1535 | * radeon_get_shared_dp_ppll - return the PPLL used by another crtc for DP |
| 1536 | * |
| 1537 | * @crtc: drm crtc |
| 1538 | * |
| 1539 | * Returns the PPLL (Pixel PLL) used by another crtc/encoder which is |
| 1540 | * also in DP mode. For DP, a single PPLL can be used for all DP |
| 1541 | * crtcs/encoders. |
| 1542 | */ |
| 1543 | static int radeon_get_shared_dp_ppll(struct drm_crtc *crtc) |
| 1544 | { |
| 1545 | struct drm_device *dev = crtc->dev; |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1546 | struct drm_crtc *test_crtc; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1547 | struct radeon_crtc *test_radeon_crtc; |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1548 | |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1549 | list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { |
| 1550 | if (crtc == test_crtc) |
| 1551 | continue; |
| 1552 | test_radeon_crtc = to_radeon_crtc(test_crtc); |
| 1553 | if (test_radeon_crtc->encoder && |
| 1554 | ENCODER_MODE_IS_DP(atombios_get_encoder_mode(test_radeon_crtc->encoder))) { |
| 1555 | /* for DP use the same PLL for all */ |
| 1556 | if (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID) |
| 1557 | return test_radeon_crtc->pll_id; |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1558 | } |
| 1559 | } |
| 1560 | return ATOM_PPLL_INVALID; |
| 1561 | } |
| 1562 | |
| 1563 | /** |
Alex Deucher | 2f454cf | 2012-09-12 18:54:14 -0400 | [diff] [blame] | 1564 | * radeon_get_shared_nondp_ppll - return the PPLL used by another non-DP crtc |
| 1565 | * |
| 1566 | * @crtc: drm crtc |
| 1567 | * @encoder: drm encoder |
| 1568 | * |
| 1569 | * Returns the PPLL (Pixel PLL) used by another non-DP crtc/encoder which can |
| 1570 | * be shared (i.e., same clock). |
| 1571 | */ |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1572 | static int radeon_get_shared_nondp_ppll(struct drm_crtc *crtc) |
Alex Deucher | 2f454cf | 2012-09-12 18:54:14 -0400 | [diff] [blame] | 1573 | { |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1574 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Alex Deucher | 2f454cf | 2012-09-12 18:54:14 -0400 | [diff] [blame] | 1575 | struct drm_device *dev = crtc->dev; |
Alex Deucher | 9642ac0 | 2012-09-13 12:43:41 -0400 | [diff] [blame] | 1576 | struct drm_crtc *test_crtc; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1577 | struct radeon_crtc *test_radeon_crtc; |
Alex Deucher | 9642ac0 | 2012-09-13 12:43:41 -0400 | [diff] [blame] | 1578 | u32 adjusted_clock, test_adjusted_clock; |
Alex Deucher | 2f454cf | 2012-09-12 18:54:14 -0400 | [diff] [blame] | 1579 | |
Alex Deucher | 9642ac0 | 2012-09-13 12:43:41 -0400 | [diff] [blame] | 1580 | adjusted_clock = radeon_crtc->adjusted_clock; |
| 1581 | |
| 1582 | if (adjusted_clock == 0) |
| 1583 | return ATOM_PPLL_INVALID; |
Alex Deucher | 2f454cf | 2012-09-12 18:54:14 -0400 | [diff] [blame] | 1584 | |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1585 | list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { |
| 1586 | if (crtc == test_crtc) |
| 1587 | continue; |
| 1588 | test_radeon_crtc = to_radeon_crtc(test_crtc); |
| 1589 | if (test_radeon_crtc->encoder && |
| 1590 | !ENCODER_MODE_IS_DP(atombios_get_encoder_mode(test_radeon_crtc->encoder))) { |
| 1591 | /* check if we are already driving this connector with another crtc */ |
| 1592 | if (test_radeon_crtc->connector == radeon_crtc->connector) { |
| 1593 | /* if we are, return that pll */ |
| 1594 | if (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID) |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1595 | return test_radeon_crtc->pll_id; |
Alex Deucher | 2f454cf | 2012-09-12 18:54:14 -0400 | [diff] [blame] | 1596 | } |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1597 | /* for non-DP check the clock */ |
| 1598 | test_adjusted_clock = test_radeon_crtc->adjusted_clock; |
| 1599 | if ((crtc->mode.clock == test_crtc->mode.clock) && |
| 1600 | (adjusted_clock == test_adjusted_clock) && |
| 1601 | (radeon_crtc->ss_enabled == test_radeon_crtc->ss_enabled) && |
| 1602 | (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID)) |
| 1603 | return test_radeon_crtc->pll_id; |
Alex Deucher | 2f454cf | 2012-09-12 18:54:14 -0400 | [diff] [blame] | 1604 | } |
| 1605 | } |
| 1606 | return ATOM_PPLL_INVALID; |
| 1607 | } |
| 1608 | |
| 1609 | /** |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1610 | * radeon_atom_pick_pll - Allocate a PPLL for use by the crtc. |
| 1611 | * |
| 1612 | * @crtc: drm crtc |
| 1613 | * |
| 1614 | * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors |
| 1615 | * a single PPLL can be used for all DP crtcs/encoders. For non-DP |
| 1616 | * monitors a dedicated PPLL must be used. If a particular board has |
| 1617 | * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming |
| 1618 | * as there is no need to program the PLL itself. If we are not able to |
| 1619 | * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to |
| 1620 | * avoid messing up an existing monitor. |
| 1621 | * |
| 1622 | * Asic specific PLL information |
| 1623 | * |
Alex Deucher | 0331f67 | 2012-09-14 11:57:21 -0400 | [diff] [blame] | 1624 | * DCE 8.x |
| 1625 | * KB/KV |
| 1626 | * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) |
| 1627 | * CI |
| 1628 | * - PPLL0, PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC |
| 1629 | * |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1630 | * DCE 6.1 |
| 1631 | * - PPLL2 is only available to UNIPHYA (both DP and non-DP) |
| 1632 | * - PPLL0, PPLL1 are available for UNIPHYB/C/D/E/F (both DP and non-DP) |
| 1633 | * |
| 1634 | * DCE 6.0 |
| 1635 | * - PPLL0 is available to all UNIPHY (DP only) |
| 1636 | * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC |
| 1637 | * |
| 1638 | * DCE 5.0 |
| 1639 | * - DCPLL is available to all UNIPHY (DP only) |
| 1640 | * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC |
| 1641 | * |
| 1642 | * DCE 3.0/4.0/4.1 |
| 1643 | * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC |
| 1644 | * |
| 1645 | */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1646 | static int radeon_atom_pick_pll(struct drm_crtc *crtc) |
| 1647 | { |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1648 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1649 | struct drm_device *dev = crtc->dev; |
| 1650 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1651 | struct radeon_encoder *radeon_encoder = |
| 1652 | to_radeon_encoder(radeon_crtc->encoder); |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1653 | u32 pll_in_use; |
| 1654 | int pll; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1655 | |
Alex Deucher | 0331f67 | 2012-09-14 11:57:21 -0400 | [diff] [blame] | 1656 | if (ASIC_IS_DCE8(rdev)) { |
| 1657 | if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) { |
| 1658 | if (rdev->clock.dp_extclk) |
| 1659 | /* skip PPLL programming if using ext clock */ |
| 1660 | return ATOM_PPLL_INVALID; |
| 1661 | else { |
| 1662 | /* use the same PPLL for all DP monitors */ |
| 1663 | pll = radeon_get_shared_dp_ppll(crtc); |
| 1664 | if (pll != ATOM_PPLL_INVALID) |
| 1665 | return pll; |
| 1666 | } |
| 1667 | } else { |
| 1668 | /* use the same PPLL for all monitors with the same clock */ |
| 1669 | pll = radeon_get_shared_nondp_ppll(crtc); |
| 1670 | if (pll != ATOM_PPLL_INVALID) |
| 1671 | return pll; |
| 1672 | } |
| 1673 | /* otherwise, pick one of the plls */ |
| 1674 | if ((rdev->family == CHIP_KAVERI) || |
| 1675 | (rdev->family == CHIP_KABINI)) { |
| 1676 | /* KB/KV has PPLL1 and PPLL2 */ |
| 1677 | pll_in_use = radeon_get_pll_use_mask(crtc); |
| 1678 | if (!(pll_in_use & (1 << ATOM_PPLL2))) |
| 1679 | return ATOM_PPLL2; |
| 1680 | if (!(pll_in_use & (1 << ATOM_PPLL1))) |
| 1681 | return ATOM_PPLL1; |
| 1682 | DRM_ERROR("unable to allocate a PPLL\n"); |
| 1683 | return ATOM_PPLL_INVALID; |
| 1684 | } else { |
| 1685 | /* CI has PPLL0, PPLL1, and PPLL2 */ |
| 1686 | pll_in_use = radeon_get_pll_use_mask(crtc); |
| 1687 | if (!(pll_in_use & (1 << ATOM_PPLL2))) |
| 1688 | return ATOM_PPLL2; |
| 1689 | if (!(pll_in_use & (1 << ATOM_PPLL1))) |
| 1690 | return ATOM_PPLL1; |
| 1691 | if (!(pll_in_use & (1 << ATOM_PPLL0))) |
| 1692 | return ATOM_PPLL0; |
| 1693 | DRM_ERROR("unable to allocate a PPLL\n"); |
| 1694 | return ATOM_PPLL_INVALID; |
| 1695 | } |
| 1696 | } else if (ASIC_IS_DCE61(rdev)) { |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1697 | struct radeon_encoder_atom_dig *dig = |
| 1698 | radeon_encoder->enc_priv; |
Alex Deucher | 24e1f79 | 2012-03-20 17:18:32 -0400 | [diff] [blame] | 1699 | |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1700 | if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY) && |
| 1701 | (dig->linkb == false)) |
| 1702 | /* UNIPHY A uses PPLL2 */ |
| 1703 | return ATOM_PPLL2; |
| 1704 | else if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) { |
| 1705 | /* UNIPHY B/C/D/E/F */ |
| 1706 | if (rdev->clock.dp_extclk) |
| 1707 | /* skip PPLL programming if using ext clock */ |
| 1708 | return ATOM_PPLL_INVALID; |
| 1709 | else { |
| 1710 | /* use the same PPLL for all DP monitors */ |
| 1711 | pll = radeon_get_shared_dp_ppll(crtc); |
| 1712 | if (pll != ATOM_PPLL_INVALID) |
| 1713 | return pll; |
Alex Deucher | 24e1f79 | 2012-03-20 17:18:32 -0400 | [diff] [blame] | 1714 | } |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1715 | } else { |
| 1716 | /* use the same PPLL for all monitors with the same clock */ |
| 1717 | pll = radeon_get_shared_nondp_ppll(crtc); |
| 1718 | if (pll != ATOM_PPLL_INVALID) |
| 1719 | return pll; |
Alex Deucher | 24e1f79 | 2012-03-20 17:18:32 -0400 | [diff] [blame] | 1720 | } |
| 1721 | /* UNIPHY B/C/D/E/F */ |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1722 | pll_in_use = radeon_get_pll_use_mask(crtc); |
| 1723 | if (!(pll_in_use & (1 << ATOM_PPLL0))) |
Alex Deucher | 24e1f79 | 2012-03-20 17:18:32 -0400 | [diff] [blame] | 1724 | return ATOM_PPLL0; |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1725 | if (!(pll_in_use & (1 << ATOM_PPLL1))) |
| 1726 | return ATOM_PPLL1; |
| 1727 | DRM_ERROR("unable to allocate a PPLL\n"); |
| 1728 | return ATOM_PPLL_INVALID; |
Alex Deucher | 24e1f79 | 2012-03-20 17:18:32 -0400 | [diff] [blame] | 1729 | } else if (ASIC_IS_DCE4(rdev)) { |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1730 | /* in DP mode, the DP ref clock can come from PPLL, DCPLL, or ext clock, |
| 1731 | * depending on the asic: |
| 1732 | * DCE4: PPLL or ext clock |
| 1733 | * DCE5: PPLL, DCPLL, or ext clock |
| 1734 | * DCE6: PPLL, PPLL0, or ext clock |
| 1735 | * |
| 1736 | * Setting ATOM_PPLL_INVALID will cause SetPixelClock to skip |
| 1737 | * PPLL/DCPLL programming and only program the DP DTO for the |
| 1738 | * crtc virtual pixel clock. |
| 1739 | */ |
| 1740 | if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) { |
| 1741 | if (rdev->clock.dp_extclk) |
| 1742 | /* skip PPLL programming if using ext clock */ |
| 1743 | return ATOM_PPLL_INVALID; |
| 1744 | else if (ASIC_IS_DCE6(rdev)) |
| 1745 | /* use PPLL0 for all DP */ |
| 1746 | return ATOM_PPLL0; |
| 1747 | else if (ASIC_IS_DCE5(rdev)) |
| 1748 | /* use DCPLL for all DP */ |
| 1749 | return ATOM_DCPLL; |
| 1750 | else { |
| 1751 | /* use the same PPLL for all DP monitors */ |
| 1752 | pll = radeon_get_shared_dp_ppll(crtc); |
| 1753 | if (pll != ATOM_PPLL_INVALID) |
| 1754 | return pll; |
Alex Deucher | 9dbbcfc | 2012-09-12 17:39:57 -0400 | [diff] [blame] | 1755 | } |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1756 | } else { |
| 1757 | /* use the same PPLL for all monitors with the same clock */ |
| 1758 | pll = radeon_get_shared_nondp_ppll(crtc); |
| 1759 | if (pll != ATOM_PPLL_INVALID) |
| 1760 | return pll; |
Alex Deucher | 9dbbcfc | 2012-09-12 17:39:57 -0400 | [diff] [blame] | 1761 | } |
| 1762 | /* all other cases */ |
| 1763 | pll_in_use = radeon_get_pll_use_mask(crtc); |
Alex Deucher | 9dbbcfc | 2012-09-12 17:39:57 -0400 | [diff] [blame] | 1764 | if (!(pll_in_use & (1 << ATOM_PPLL1))) |
| 1765 | return ATOM_PPLL1; |
Alex Deucher | 29dbe3b | 2012-10-05 10:22:02 -0400 | [diff] [blame] | 1766 | if (!(pll_in_use & (1 << ATOM_PPLL2))) |
| 1767 | return ATOM_PPLL2; |
Alex Deucher | 9dbbcfc | 2012-09-12 17:39:57 -0400 | [diff] [blame] | 1768 | DRM_ERROR("unable to allocate a PPLL\n"); |
| 1769 | return ATOM_PPLL_INVALID; |
Alex Deucher | 1e4db5f | 2012-11-05 10:16:12 -0500 | [diff] [blame] | 1770 | } else { |
| 1771 | /* on pre-R5xx asics, the crtc to pll mapping is hardcoded */ |
Jerome Glisse | fc58acd | 2012-11-27 16:12:29 -0500 | [diff] [blame] | 1772 | /* some atombios (observed in some DCE2/DCE3) code have a bug, |
| 1773 | * the matching btw pll and crtc is done through |
| 1774 | * PCLK_CRTC[1|2]_CNTL (0x480/0x484) but atombios code use the |
| 1775 | * pll (1 or 2) to select which register to write. ie if using |
| 1776 | * pll1 it will use PCLK_CRTC1_CNTL (0x480) and if using pll2 |
| 1777 | * it will use PCLK_CRTC2_CNTL (0x484), it then use crtc id to |
| 1778 | * choose which value to write. Which is reverse order from |
| 1779 | * register logic. So only case that works is when pllid is |
| 1780 | * same as crtcid or when both pll and crtc are enabled and |
| 1781 | * both use same clock. |
| 1782 | * |
| 1783 | * So just return crtc id as if crtc and pll were hard linked |
| 1784 | * together even if they aren't |
| 1785 | */ |
Alex Deucher | 1e4db5f | 2012-11-05 10:16:12 -0500 | [diff] [blame] | 1786 | return radeon_crtc->crtc_id; |
Alex Deucher | 2f454cf | 2012-09-12 18:54:14 -0400 | [diff] [blame] | 1787 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1788 | } |
| 1789 | |
Alex Deucher | f3f1f03 | 2012-03-20 17:18:04 -0400 | [diff] [blame] | 1790 | void radeon_atom_disp_eng_pll_init(struct radeon_device *rdev) |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 1791 | { |
| 1792 | /* always set DCPLL */ |
Alex Deucher | f3f1f03 | 2012-03-20 17:18:04 -0400 | [diff] [blame] | 1793 | if (ASIC_IS_DCE6(rdev)) |
| 1794 | atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk); |
| 1795 | else if (ASIC_IS_DCE4(rdev)) { |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 1796 | struct radeon_atom_ss ss; |
| 1797 | bool ss_enabled = radeon_atombios_get_asic_ss_info(rdev, &ss, |
| 1798 | ASIC_INTERNAL_SS_ON_DCPLL, |
| 1799 | rdev->clock.default_dispclk); |
| 1800 | if (ss_enabled) |
Jerome Glisse | 5efcc76 | 2012-08-17 14:40:04 -0400 | [diff] [blame] | 1801 | atombios_crtc_program_ss(rdev, ATOM_DISABLE, ATOM_DCPLL, -1, &ss); |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 1802 | /* XXX: DCE5, make sure voltage, dispclk is high enough */ |
Alex Deucher | f3f1f03 | 2012-03-20 17:18:04 -0400 | [diff] [blame] | 1803 | atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk); |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 1804 | if (ss_enabled) |
Jerome Glisse | 5efcc76 | 2012-08-17 14:40:04 -0400 | [diff] [blame] | 1805 | atombios_crtc_program_ss(rdev, ATOM_ENABLE, ATOM_DCPLL, -1, &ss); |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | } |
| 1809 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1810 | int atombios_crtc_mode_set(struct drm_crtc *crtc, |
| 1811 | struct drm_display_mode *mode, |
| 1812 | struct drm_display_mode *adjusted_mode, |
| 1813 | int x, int y, struct drm_framebuffer *old_fb) |
| 1814 | { |
| 1815 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1816 | struct drm_device *dev = crtc->dev; |
| 1817 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1818 | struct radeon_encoder *radeon_encoder = |
| 1819 | to_radeon_encoder(radeon_crtc->encoder); |
Alex Deucher | 54bfe49 | 2010-09-03 15:52:53 -0400 | [diff] [blame] | 1820 | bool is_tvcv = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1821 | |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1822 | if (radeon_encoder->active_device & |
| 1823 | (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) |
| 1824 | is_tvcv = true; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1825 | |
| 1826 | atombios_crtc_set_pll(crtc, adjusted_mode); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1827 | |
Alex Deucher | 54bfe49 | 2010-09-03 15:52:53 -0400 | [diff] [blame] | 1828 | if (ASIC_IS_DCE4(rdev)) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1829 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); |
Alex Deucher | 54bfe49 | 2010-09-03 15:52:53 -0400 | [diff] [blame] | 1830 | else if (ASIC_IS_AVIVO(rdev)) { |
| 1831 | if (is_tvcv) |
| 1832 | atombios_crtc_set_timing(crtc, adjusted_mode); |
| 1833 | else |
| 1834 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); |
| 1835 | } else { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1836 | atombios_crtc_set_timing(crtc, adjusted_mode); |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1837 | if (radeon_crtc->crtc_id == 0) |
| 1838 | atombios_set_crtc_dtd_timing(crtc, adjusted_mode); |
Alex Deucher | 615e0cb | 2010-01-20 16:22:53 -0500 | [diff] [blame] | 1839 | radeon_legacy_atom_fixup(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1840 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1841 | atombios_crtc_set_base(crtc, x, y, old_fb); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1842 | atombios_overscan_setup(crtc, mode, adjusted_mode); |
| 1843 | atombios_scaler_setup(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1844 | return 0; |
| 1845 | } |
| 1846 | |
| 1847 | static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 1848 | const struct drm_display_mode *mode, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1849 | struct drm_display_mode *adjusted_mode) |
| 1850 | { |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1851 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1852 | struct drm_device *dev = crtc->dev; |
| 1853 | struct drm_encoder *encoder; |
| 1854 | |
| 1855 | /* assign the encoder to the radeon crtc to avoid repeated lookups later */ |
| 1856 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 1857 | if (encoder->crtc == crtc) { |
| 1858 | radeon_crtc->encoder = encoder; |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1859 | radeon_crtc->connector = radeon_get_connector_for_encoder(encoder); |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1860 | break; |
| 1861 | } |
| 1862 | } |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1863 | if ((radeon_crtc->encoder == NULL) || (radeon_crtc->connector == NULL)) { |
| 1864 | radeon_crtc->encoder = NULL; |
| 1865 | radeon_crtc->connector = NULL; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1866 | return false; |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1867 | } |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1868 | if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) |
| 1869 | return false; |
Alex Deucher | 19eca43 | 2012-09-13 10:56:16 -0400 | [diff] [blame] | 1870 | if (!atombios_crtc_prepare_pll(crtc, adjusted_mode)) |
| 1871 | return false; |
Alex Deucher | c0fd083 | 2012-09-14 12:30:51 -0400 | [diff] [blame] | 1872 | /* pick pll */ |
| 1873 | radeon_crtc->pll_id = radeon_atom_pick_pll(crtc); |
| 1874 | /* if we can't get a PPLL for a non-DP encoder, fail */ |
| 1875 | if ((radeon_crtc->pll_id == ATOM_PPLL_INVALID) && |
| 1876 | !ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) |
| 1877 | return false; |
| 1878 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1879 | return true; |
| 1880 | } |
| 1881 | |
| 1882 | static void atombios_crtc_prepare(struct drm_crtc *crtc) |
| 1883 | { |
Alex Deucher | 6c0ae2a | 2012-07-26 13:38:52 -0400 | [diff] [blame] | 1884 | struct drm_device *dev = crtc->dev; |
| 1885 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 267364a | 2010-03-08 17:10:41 -0500 | [diff] [blame] | 1886 | |
Alex Deucher | 6c0ae2a | 2012-07-26 13:38:52 -0400 | [diff] [blame] | 1887 | /* disable crtc pair power gating before programming */ |
| 1888 | if (ASIC_IS_DCE6(rdev)) |
| 1889 | atombios_powergate_crtc(crtc, ATOM_DISABLE); |
| 1890 | |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 1891 | atombios_lock_crtc(crtc, ATOM_ENABLE); |
Alex Deucher | a348c84 | 2010-01-21 16:50:30 -0500 | [diff] [blame] | 1892 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | static void atombios_crtc_commit(struct drm_crtc *crtc) |
| 1896 | { |
| 1897 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
Alex Deucher | 37b4390 | 2010-02-09 12:04:43 -0500 | [diff] [blame] | 1898 | atombios_lock_crtc(crtc, ATOM_DISABLE); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1899 | } |
| 1900 | |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1901 | static void atombios_crtc_disable(struct drm_crtc *crtc) |
| 1902 | { |
| 1903 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Alex Deucher | 6419987 | 2012-03-20 17:18:33 -0400 | [diff] [blame] | 1904 | struct drm_device *dev = crtc->dev; |
| 1905 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 1906 | struct radeon_atom_ss ss; |
Alex Deucher | 4e58591 | 2012-08-21 19:06:21 -0400 | [diff] [blame] | 1907 | int i; |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 1908 | |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1909 | atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
Alex Deucher | 0e3d50b | 2013-02-05 11:47:09 -0500 | [diff] [blame] | 1910 | if (ASIC_IS_DCE6(rdev)) |
| 1911 | atombios_powergate_crtc(crtc, ATOM_ENABLE); |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1912 | |
Alex Deucher | 4e58591 | 2012-08-21 19:06:21 -0400 | [diff] [blame] | 1913 | for (i = 0; i < rdev->num_crtc; i++) { |
| 1914 | if (rdev->mode_info.crtcs[i] && |
| 1915 | rdev->mode_info.crtcs[i]->enabled && |
| 1916 | i != radeon_crtc->crtc_id && |
| 1917 | radeon_crtc->pll_id == rdev->mode_info.crtcs[i]->pll_id) { |
| 1918 | /* one other crtc is using this pll don't turn |
| 1919 | * off the pll |
| 1920 | */ |
| 1921 | goto done; |
| 1922 | } |
| 1923 | } |
| 1924 | |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1925 | switch (radeon_crtc->pll_id) { |
| 1926 | case ATOM_PPLL1: |
| 1927 | case ATOM_PPLL2: |
| 1928 | /* disable the ppll */ |
| 1929 | atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, |
Alex Deucher | 8e8e523 | 2011-05-20 04:34:16 -0400 | [diff] [blame] | 1930 | 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1931 | break; |
Alex Deucher | 6419987 | 2012-03-20 17:18:33 -0400 | [diff] [blame] | 1932 | case ATOM_PPLL0: |
| 1933 | /* disable the ppll */ |
Alex Deucher | 2f0047b | 2013-02-05 11:58:11 -0500 | [diff] [blame] | 1934 | if ((rdev->family == CHIP_ARUBA) || (rdev->family == CHIP_BONAIRE)) |
Alex Deucher | 6419987 | 2012-03-20 17:18:33 -0400 | [diff] [blame] | 1935 | atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, |
| 1936 | 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); |
| 1937 | break; |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1938 | default: |
| 1939 | break; |
| 1940 | } |
Alex Deucher | 4e58591 | 2012-08-21 19:06:21 -0400 | [diff] [blame] | 1941 | done: |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1942 | radeon_crtc->pll_id = ATOM_PPLL_INVALID; |
Alex Deucher | 9642ac0 | 2012-09-13 12:43:41 -0400 | [diff] [blame] | 1943 | radeon_crtc->adjusted_clock = 0; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1944 | radeon_crtc->encoder = NULL; |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1945 | radeon_crtc->connector = NULL; |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1946 | } |
| 1947 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1948 | static const struct drm_crtc_helper_funcs atombios_helper_funcs = { |
| 1949 | .dpms = atombios_crtc_dpms, |
| 1950 | .mode_fixup = atombios_crtc_mode_fixup, |
| 1951 | .mode_set = atombios_crtc_mode_set, |
| 1952 | .mode_set_base = atombios_crtc_set_base, |
Chris Ball | 4dd19b0 | 2010-09-26 06:47:23 -0500 | [diff] [blame] | 1953 | .mode_set_base_atomic = atombios_crtc_set_base_atomic, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1954 | .prepare = atombios_crtc_prepare, |
| 1955 | .commit = atombios_crtc_commit, |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1956 | .load_lut = radeon_crtc_load_lut, |
Alex Deucher | 37f9003 | 2010-06-11 17:58:38 -0400 | [diff] [blame] | 1957 | .disable = atombios_crtc_disable, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1958 | }; |
| 1959 | |
| 1960 | void radeon_atombios_init_crtc(struct drm_device *dev, |
| 1961 | struct radeon_crtc *radeon_crtc) |
| 1962 | { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1963 | struct radeon_device *rdev = dev->dev_private; |
| 1964 | |
| 1965 | if (ASIC_IS_DCE4(rdev)) { |
| 1966 | switch (radeon_crtc->crtc_id) { |
| 1967 | case 0: |
| 1968 | default: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1969 | radeon_crtc->crtc_offset = EVERGREEN_CRTC0_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1970 | break; |
| 1971 | case 1: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1972 | radeon_crtc->crtc_offset = EVERGREEN_CRTC1_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1973 | break; |
| 1974 | case 2: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1975 | radeon_crtc->crtc_offset = EVERGREEN_CRTC2_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1976 | break; |
| 1977 | case 3: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1978 | radeon_crtc->crtc_offset = EVERGREEN_CRTC3_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1979 | break; |
| 1980 | case 4: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1981 | radeon_crtc->crtc_offset = EVERGREEN_CRTC4_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1982 | break; |
| 1983 | case 5: |
Alex Deucher | 12d7798 | 2010-02-09 17:18:48 -0500 | [diff] [blame] | 1984 | radeon_crtc->crtc_offset = EVERGREEN_CRTC5_REGISTER_OFFSET; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1985 | break; |
| 1986 | } |
| 1987 | } else { |
| 1988 | if (radeon_crtc->crtc_id == 1) |
| 1989 | radeon_crtc->crtc_offset = |
| 1990 | AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL; |
| 1991 | else |
| 1992 | radeon_crtc->crtc_offset = 0; |
| 1993 | } |
Alex Deucher | f3dd850 | 2012-08-31 11:56:50 -0400 | [diff] [blame] | 1994 | radeon_crtc->pll_id = ATOM_PPLL_INVALID; |
Alex Deucher | 9642ac0 | 2012-09-13 12:43:41 -0400 | [diff] [blame] | 1995 | radeon_crtc->adjusted_clock = 0; |
Alex Deucher | 5df3196 | 2012-09-13 11:52:08 -0400 | [diff] [blame] | 1996 | radeon_crtc->encoder = NULL; |
Alex Deucher | 57b35e2 | 2012-09-17 17:34:45 -0400 | [diff] [blame] | 1997 | radeon_crtc->connector = NULL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1998 | drm_crtc_helper_add(&radeon_crtc->base, &atombios_helper_funcs); |
| 1999 | } |