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