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