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