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> |
| 29 | #include "radeon_fixed.h" |
| 30 | #include "radeon.h" |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 31 | #include "atom.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 32 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 33 | static void radeon_legacy_rmx_mode_set(struct drm_crtc *crtc, |
| 34 | struct drm_display_mode *mode, |
| 35 | struct drm_display_mode *adjusted_mode) |
| 36 | { |
| 37 | struct drm_device *dev = crtc->dev; |
| 38 | struct radeon_device *rdev = dev->dev_private; |
| 39 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 40 | int xres = mode->hdisplay; |
| 41 | int yres = mode->vdisplay; |
| 42 | bool hscale = true, vscale = true; |
| 43 | int hsync_wid; |
| 44 | int vsync_wid; |
| 45 | int hsync_start; |
| 46 | int blank_width; |
| 47 | u32 scale, inc, crtc_more_cntl; |
| 48 | u32 fp_horz_stretch, fp_vert_stretch, fp_horz_vert_active; |
| 49 | u32 fp_h_sync_strt_wid, fp_crtc_h_total_disp; |
| 50 | u32 fp_v_sync_strt_wid, fp_crtc_v_total_disp; |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 51 | struct drm_display_mode *native_mode = &radeon_crtc->native_mode; |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 52 | |
| 53 | fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH) & |
| 54 | (RADEON_VERT_STRETCH_RESERVED | |
| 55 | RADEON_VERT_AUTO_RATIO_INC); |
| 56 | fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH) & |
| 57 | (RADEON_HORZ_FP_LOOP_STRETCH | |
| 58 | RADEON_HORZ_AUTO_RATIO_INC); |
| 59 | |
| 60 | crtc_more_cntl = 0; |
| 61 | if ((rdev->family == CHIP_RS100) || |
| 62 | (rdev->family == CHIP_RS200)) { |
| 63 | /* This is to workaround the asic bug for RMX, some versions |
| 64 | of BIOS dosen't have this register initialized correctly. */ |
| 65 | crtc_more_cntl |= RADEON_CRTC_H_CUTOFF_ACTIVE_EN; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | fp_crtc_h_total_disp = ((((mode->crtc_htotal / 8) - 1) & 0x3ff) |
| 70 | | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16)); |
| 71 | |
| 72 | hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8; |
| 73 | if (!hsync_wid) |
| 74 | hsync_wid = 1; |
| 75 | hsync_start = mode->crtc_hsync_start - 8; |
| 76 | |
| 77 | fp_h_sync_strt_wid = ((hsync_start & 0x1fff) |
| 78 | | ((hsync_wid & 0x3f) << 16) |
| 79 | | ((mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 80 | ? RADEON_CRTC_H_SYNC_POL |
| 81 | : 0)); |
| 82 | |
| 83 | fp_crtc_v_total_disp = (((mode->crtc_vtotal - 1) & 0xffff) |
| 84 | | ((mode->crtc_vdisplay - 1) << 16)); |
| 85 | |
| 86 | vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 87 | if (!vsync_wid) |
| 88 | vsync_wid = 1; |
| 89 | |
| 90 | fp_v_sync_strt_wid = (((mode->crtc_vsync_start - 1) & 0xfff) |
| 91 | | ((vsync_wid & 0x1f) << 16) |
| 92 | | ((mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 93 | ? RADEON_CRTC_V_SYNC_POL |
| 94 | : 0)); |
| 95 | |
| 96 | fp_horz_vert_active = 0; |
| 97 | |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 98 | if (native_mode->hdisplay == 0 || |
| 99 | native_mode->vdisplay == 0) { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 100 | hscale = false; |
| 101 | vscale = false; |
| 102 | } else { |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 103 | if (xres > native_mode->hdisplay) |
| 104 | xres = native_mode->hdisplay; |
| 105 | if (yres > native_mode->vdisplay) |
| 106 | yres = native_mode->vdisplay; |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 107 | |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 108 | if (xres == native_mode->hdisplay) |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 109 | hscale = false; |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 110 | if (yres == native_mode->vdisplay) |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 111 | vscale = false; |
| 112 | } |
| 113 | |
| 114 | switch (radeon_crtc->rmx_type) { |
| 115 | case RMX_FULL: |
| 116 | case RMX_ASPECT: |
| 117 | if (!hscale) |
| 118 | fp_horz_stretch |= ((xres/8-1) << 16); |
| 119 | else { |
| 120 | inc = (fp_horz_stretch & RADEON_HORZ_AUTO_RATIO_INC) ? 1 : 0; |
| 121 | scale = ((xres + inc) * RADEON_HORZ_STRETCH_RATIO_MAX) |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 122 | / native_mode->hdisplay + 1; |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 123 | fp_horz_stretch |= (((scale) & RADEON_HORZ_STRETCH_RATIO_MASK) | |
| 124 | RADEON_HORZ_STRETCH_BLEND | |
| 125 | RADEON_HORZ_STRETCH_ENABLE | |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 126 | ((native_mode->hdisplay/8-1) << 16)); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | if (!vscale) |
| 130 | fp_vert_stretch |= ((yres-1) << 12); |
| 131 | else { |
| 132 | inc = (fp_vert_stretch & RADEON_VERT_AUTO_RATIO_INC) ? 1 : 0; |
| 133 | scale = ((yres + inc) * RADEON_VERT_STRETCH_RATIO_MAX) |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 134 | / native_mode->vdisplay + 1; |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 135 | fp_vert_stretch |= (((scale) & RADEON_VERT_STRETCH_RATIO_MASK) | |
| 136 | RADEON_VERT_STRETCH_ENABLE | |
| 137 | RADEON_VERT_STRETCH_BLEND | |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 138 | ((native_mode->vdisplay-1) << 12)); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 139 | } |
| 140 | break; |
| 141 | case RMX_CENTER: |
| 142 | fp_horz_stretch |= ((xres/8-1) << 16); |
| 143 | fp_vert_stretch |= ((yres-1) << 12); |
| 144 | |
| 145 | crtc_more_cntl |= (RADEON_CRTC_AUTO_HORZ_CENTER_EN | |
| 146 | RADEON_CRTC_AUTO_VERT_CENTER_EN); |
| 147 | |
| 148 | blank_width = (mode->crtc_hblank_end - mode->crtc_hblank_start) / 8; |
| 149 | if (blank_width > 110) |
| 150 | blank_width = 110; |
| 151 | |
| 152 | fp_crtc_h_total_disp = (((blank_width) & 0x3ff) |
| 153 | | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16)); |
| 154 | |
| 155 | hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8; |
| 156 | if (!hsync_wid) |
| 157 | hsync_wid = 1; |
| 158 | |
| 159 | fp_h_sync_strt_wid = ((((mode->crtc_hsync_start - mode->crtc_hblank_start) / 8) & 0x1fff) |
| 160 | | ((hsync_wid & 0x3f) << 16) |
| 161 | | ((mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 162 | ? RADEON_CRTC_H_SYNC_POL |
| 163 | : 0)); |
| 164 | |
| 165 | fp_crtc_v_total_disp = (((mode->crtc_vblank_end - mode->crtc_vblank_start) & 0xffff) |
| 166 | | ((mode->crtc_vdisplay - 1) << 16)); |
| 167 | |
| 168 | vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 169 | if (!vsync_wid) |
| 170 | vsync_wid = 1; |
| 171 | |
| 172 | fp_v_sync_strt_wid = ((((mode->crtc_vsync_start - mode->crtc_vblank_start) & 0xfff) |
| 173 | | ((vsync_wid & 0x1f) << 16) |
| 174 | | ((mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 175 | ? RADEON_CRTC_V_SYNC_POL |
| 176 | : 0))); |
| 177 | |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 178 | fp_horz_vert_active = (((native_mode->vdisplay) & 0xfff) | |
| 179 | (((native_mode->hdisplay / 8) & 0x1ff) << 16)); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 180 | break; |
| 181 | case RMX_OFF: |
| 182 | default: |
| 183 | fp_horz_stretch |= ((xres/8-1) << 16); |
| 184 | fp_vert_stretch |= ((yres-1) << 12); |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | WREG32(RADEON_FP_HORZ_STRETCH, fp_horz_stretch); |
| 189 | WREG32(RADEON_FP_VERT_STRETCH, fp_vert_stretch); |
| 190 | WREG32(RADEON_CRTC_MORE_CNTL, crtc_more_cntl); |
| 191 | WREG32(RADEON_FP_HORZ_VERT_ACTIVE, fp_horz_vert_active); |
| 192 | WREG32(RADEON_FP_H_SYNC_STRT_WID, fp_h_sync_strt_wid); |
| 193 | WREG32(RADEON_FP_V_SYNC_STRT_WID, fp_v_sync_strt_wid); |
| 194 | WREG32(RADEON_FP_CRTC_H_TOTAL_DISP, fp_crtc_h_total_disp); |
| 195 | WREG32(RADEON_FP_CRTC_V_TOTAL_DISP, fp_crtc_v_total_disp); |
| 196 | } |
| 197 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 198 | void radeon_restore_common_regs(struct drm_device *dev) |
| 199 | { |
| 200 | /* don't need this yet */ |
| 201 | } |
| 202 | |
| 203 | static void radeon_pll_wait_for_read_update_complete(struct drm_device *dev) |
| 204 | { |
| 205 | struct radeon_device *rdev = dev->dev_private; |
| 206 | int i = 0; |
| 207 | |
| 208 | /* FIXME: Certain revisions of R300 can't recover here. Not sure of |
| 209 | the cause yet, but this workaround will mask the problem for now. |
| 210 | Other chips usually will pass at the very first test, so the |
| 211 | workaround shouldn't have any effect on them. */ |
| 212 | for (i = 0; |
| 213 | (i < 10000 && |
| 214 | RREG32_PLL(RADEON_PPLL_REF_DIV) & RADEON_PPLL_ATOMIC_UPDATE_R); |
| 215 | i++); |
| 216 | } |
| 217 | |
| 218 | static void radeon_pll_write_update(struct drm_device *dev) |
| 219 | { |
| 220 | struct radeon_device *rdev = dev->dev_private; |
| 221 | |
| 222 | while (RREG32_PLL(RADEON_PPLL_REF_DIV) & RADEON_PPLL_ATOMIC_UPDATE_R); |
| 223 | |
| 224 | WREG32_PLL_P(RADEON_PPLL_REF_DIV, |
| 225 | RADEON_PPLL_ATOMIC_UPDATE_W, |
| 226 | ~(RADEON_PPLL_ATOMIC_UPDATE_W)); |
| 227 | } |
| 228 | |
| 229 | static void radeon_pll2_wait_for_read_update_complete(struct drm_device *dev) |
| 230 | { |
| 231 | struct radeon_device *rdev = dev->dev_private; |
| 232 | int i = 0; |
| 233 | |
| 234 | |
| 235 | /* FIXME: Certain revisions of R300 can't recover here. Not sure of |
| 236 | the cause yet, but this workaround will mask the problem for now. |
| 237 | Other chips usually will pass at the very first test, so the |
| 238 | workaround shouldn't have any effect on them. */ |
| 239 | for (i = 0; |
| 240 | (i < 10000 && |
| 241 | RREG32_PLL(RADEON_P2PLL_REF_DIV) & RADEON_P2PLL_ATOMIC_UPDATE_R); |
| 242 | i++); |
| 243 | } |
| 244 | |
| 245 | static void radeon_pll2_write_update(struct drm_device *dev) |
| 246 | { |
| 247 | struct radeon_device *rdev = dev->dev_private; |
| 248 | |
| 249 | while (RREG32_PLL(RADEON_P2PLL_REF_DIV) & RADEON_P2PLL_ATOMIC_UPDATE_R); |
| 250 | |
| 251 | WREG32_PLL_P(RADEON_P2PLL_REF_DIV, |
| 252 | RADEON_P2PLL_ATOMIC_UPDATE_W, |
| 253 | ~(RADEON_P2PLL_ATOMIC_UPDATE_W)); |
| 254 | } |
| 255 | |
| 256 | static uint8_t radeon_compute_pll_gain(uint16_t ref_freq, uint16_t ref_div, |
| 257 | uint16_t fb_div) |
| 258 | { |
| 259 | unsigned int vcoFreq; |
| 260 | |
| 261 | if (!ref_div) |
| 262 | return 1; |
| 263 | |
| 264 | vcoFreq = ((unsigned)ref_freq & fb_div) / ref_div; |
| 265 | |
| 266 | /* |
| 267 | * This is horribly crude: the VCO frequency range is divided into |
| 268 | * 3 parts, each part having a fixed PLL gain value. |
| 269 | */ |
| 270 | if (vcoFreq >= 30000) |
| 271 | /* |
| 272 | * [300..max] MHz : 7 |
| 273 | */ |
| 274 | return 7; |
| 275 | else if (vcoFreq >= 18000) |
| 276 | /* |
| 277 | * [180..300) MHz : 4 |
| 278 | */ |
| 279 | return 4; |
| 280 | else |
| 281 | /* |
| 282 | * [0..180) MHz : 1 |
| 283 | */ |
| 284 | return 1; |
| 285 | } |
| 286 | |
| 287 | void radeon_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 288 | { |
| 289 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 290 | struct drm_device *dev = crtc->dev; |
| 291 | struct radeon_device *rdev = dev->dev_private; |
| 292 | uint32_t mask; |
| 293 | |
| 294 | if (radeon_crtc->crtc_id) |
Alex Deucher | 8de2152 | 2009-12-03 12:15:54 -0500 | [diff] [blame^] | 295 | mask = (RADEON_CRTC2_DISP_DIS | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 296 | RADEON_CRTC2_VSYNC_DIS | |
| 297 | RADEON_CRTC2_HSYNC_DIS | |
| 298 | RADEON_CRTC2_DISP_REQ_EN_B); |
| 299 | else |
| 300 | mask = (RADEON_CRTC_DISPLAY_DIS | |
| 301 | RADEON_CRTC_VSYNC_DIS | |
| 302 | RADEON_CRTC_HSYNC_DIS); |
| 303 | |
| 304 | switch (mode) { |
| 305 | case DRM_MODE_DPMS_ON: |
| 306 | if (radeon_crtc->crtc_id) |
Alex Deucher | 8de2152 | 2009-12-03 12:15:54 -0500 | [diff] [blame^] | 307 | WREG32_P(RADEON_CRTC2_GEN_CNTL, RADEON_CRTC2_EN, ~(RADEON_CRTC2_EN | mask)); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 308 | else { |
| 309 | WREG32_P(RADEON_CRTC_GEN_CNTL, RADEON_CRTC_EN, ~(RADEON_CRTC_EN | |
| 310 | RADEON_CRTC_DISP_REQ_EN_B)); |
| 311 | WREG32_P(RADEON_CRTC_EXT_CNTL, 0, ~mask); |
| 312 | } |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 313 | drm_vblank_post_modeset(dev, radeon_crtc->crtc_id); |
| 314 | radeon_crtc_load_lut(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 315 | break; |
| 316 | case DRM_MODE_DPMS_STANDBY: |
| 317 | case DRM_MODE_DPMS_SUSPEND: |
| 318 | case DRM_MODE_DPMS_OFF: |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 319 | drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 320 | if (radeon_crtc->crtc_id) |
Alex Deucher | 8de2152 | 2009-12-03 12:15:54 -0500 | [diff] [blame^] | 321 | WREG32_P(RADEON_CRTC2_GEN_CNTL, mask, ~(RADEON_CRTC2_EN | mask)); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 322 | else { |
| 323 | WREG32_P(RADEON_CRTC_GEN_CNTL, RADEON_CRTC_DISP_REQ_EN_B, ~(RADEON_CRTC_EN | |
| 324 | RADEON_CRTC_DISP_REQ_EN_B)); |
| 325 | WREG32_P(RADEON_CRTC_EXT_CNTL, mask, ~mask); |
| 326 | } |
| 327 | break; |
| 328 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /* properly set crtc bpp when using atombios */ |
| 332 | void radeon_legacy_atom_set_surface(struct drm_crtc *crtc) |
| 333 | { |
| 334 | struct drm_device *dev = crtc->dev; |
| 335 | struct radeon_device *rdev = dev->dev_private; |
| 336 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 337 | int format; |
| 338 | uint32_t crtc_gen_cntl; |
| 339 | uint32_t disp_merge_cntl; |
| 340 | uint32_t crtc_pitch; |
| 341 | |
| 342 | switch (crtc->fb->bits_per_pixel) { |
Dave Airlie | 41456df | 2009-09-16 10:15:21 +1000 | [diff] [blame] | 343 | case 8: |
| 344 | format = 2; |
| 345 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 346 | case 15: /* 555 */ |
| 347 | format = 3; |
| 348 | break; |
| 349 | case 16: /* 565 */ |
| 350 | format = 4; |
| 351 | break; |
| 352 | case 24: /* RGB */ |
| 353 | format = 5; |
| 354 | break; |
| 355 | case 32: /* xRGB */ |
| 356 | format = 6; |
| 357 | break; |
| 358 | default: |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | crtc_pitch = ((((crtc->fb->pitch / (crtc->fb->bits_per_pixel / 8)) * crtc->fb->bits_per_pixel) + |
| 363 | ((crtc->fb->bits_per_pixel * 8) - 1)) / |
| 364 | (crtc->fb->bits_per_pixel * 8)); |
| 365 | crtc_pitch |= crtc_pitch << 16; |
| 366 | |
| 367 | WREG32(RADEON_CRTC_PITCH + radeon_crtc->crtc_offset, crtc_pitch); |
| 368 | |
| 369 | switch (radeon_crtc->crtc_id) { |
| 370 | case 0: |
| 371 | disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL); |
| 372 | disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN; |
| 373 | WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl); |
| 374 | |
| 375 | crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL) & 0xfffff0ff; |
| 376 | crtc_gen_cntl |= (format << 8); |
| 377 | crtc_gen_cntl |= RADEON_CRTC_EXT_DISP_EN; |
| 378 | WREG32(RADEON_CRTC_GEN_CNTL, crtc_gen_cntl); |
| 379 | break; |
| 380 | case 1: |
| 381 | disp_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL); |
| 382 | disp_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN; |
| 383 | WREG32(RADEON_DISP2_MERGE_CNTL, disp_merge_cntl); |
| 384 | |
| 385 | crtc_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL) & 0xfffff0ff; |
| 386 | crtc_gen_cntl |= (format << 8); |
| 387 | WREG32(RADEON_CRTC2_GEN_CNTL, crtc_gen_cntl); |
| 388 | WREG32(RADEON_FP_H2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_H_SYNC_STRT_WID)); |
| 389 | WREG32(RADEON_FP_V2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_V_SYNC_STRT_WID)); |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | int radeon_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
| 395 | struct drm_framebuffer *old_fb) |
| 396 | { |
| 397 | struct drm_device *dev = crtc->dev; |
| 398 | struct radeon_device *rdev = dev->dev_private; |
| 399 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 400 | struct radeon_framebuffer *radeon_fb; |
| 401 | struct drm_gem_object *obj; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 402 | struct radeon_bo *rbo; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 403 | uint64_t base; |
| 404 | uint32_t crtc_offset, crtc_offset_cntl, crtc_tile_x0_y0 = 0; |
| 405 | uint32_t crtc_pitch, pitch_pixels; |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 406 | uint32_t tiling_flags; |
Dave Airlie | 41456df | 2009-09-16 10:15:21 +1000 | [diff] [blame] | 407 | int format; |
| 408 | uint32_t gen_cntl_reg, gen_cntl_val; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 409 | int r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 410 | |
| 411 | DRM_DEBUG("\n"); |
Jerome Glisse | 2de3b48 | 2009-11-17 14:08:55 -0800 | [diff] [blame] | 412 | /* no fb bound */ |
| 413 | if (!crtc->fb) { |
| 414 | DRM_DEBUG("No FB bound\n"); |
| 415 | return 0; |
| 416 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 417 | |
| 418 | radeon_fb = to_radeon_framebuffer(crtc->fb); |
| 419 | |
Dave Airlie | 41456df | 2009-09-16 10:15:21 +1000 | [diff] [blame] | 420 | switch (crtc->fb->bits_per_pixel) { |
| 421 | case 8: |
| 422 | format = 2; |
| 423 | break; |
| 424 | case 15: /* 555 */ |
| 425 | format = 3; |
| 426 | break; |
| 427 | case 16: /* 565 */ |
| 428 | format = 4; |
| 429 | break; |
| 430 | case 24: /* RGB */ |
| 431 | format = 5; |
| 432 | break; |
| 433 | case 32: /* xRGB */ |
| 434 | format = 6; |
| 435 | break; |
| 436 | default: |
| 437 | return false; |
| 438 | } |
| 439 | |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 440 | /* Pin framebuffer & get tilling informations */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 441 | obj = radeon_fb->obj; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 442 | rbo = obj->driver_private; |
| 443 | r = radeon_bo_reserve(rbo, false); |
| 444 | if (unlikely(r != 0)) |
| 445 | return r; |
| 446 | r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &base); |
| 447 | if (unlikely(r != 0)) { |
| 448 | radeon_bo_unreserve(rbo); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 449 | return -EINVAL; |
| 450 | } |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 451 | radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); |
| 452 | radeon_bo_unreserve(rbo); |
| 453 | if (tiling_flags & RADEON_TILING_MICRO) |
| 454 | DRM_ERROR("trying to scanout microtiled buffer\n"); |
| 455 | |
Dave Airlie | 4162338 | 2009-07-09 15:04:19 +1000 | [diff] [blame] | 456 | /* if scanout was in GTT this really wouldn't work */ |
| 457 | /* crtc offset is from display base addr not FB location */ |
| 458 | radeon_crtc->legacy_display_base_addr = rdev->mc.vram_location; |
| 459 | |
| 460 | base -= radeon_crtc->legacy_display_base_addr; |
| 461 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 462 | crtc_offset_cntl = 0; |
| 463 | |
| 464 | pitch_pixels = crtc->fb->pitch / (crtc->fb->bits_per_pixel / 8); |
| 465 | crtc_pitch = (((pitch_pixels * crtc->fb->bits_per_pixel) + |
| 466 | ((crtc->fb->bits_per_pixel * 8) - 1)) / |
| 467 | (crtc->fb->bits_per_pixel * 8)); |
| 468 | crtc_pitch |= crtc_pitch << 16; |
| 469 | |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 470 | |
| 471 | if (tiling_flags & RADEON_TILING_MACRO) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 472 | if (ASIC_IS_R300(rdev)) |
| 473 | crtc_offset_cntl |= (R300_CRTC_X_Y_MODE_EN | |
| 474 | R300_CRTC_MICRO_TILE_BUFFER_DIS | |
| 475 | R300_CRTC_MACRO_TILE_EN); |
| 476 | else |
| 477 | crtc_offset_cntl |= RADEON_CRTC_TILE_EN; |
| 478 | } else { |
| 479 | if (ASIC_IS_R300(rdev)) |
| 480 | crtc_offset_cntl &= ~(R300_CRTC_X_Y_MODE_EN | |
| 481 | R300_CRTC_MICRO_TILE_BUFFER_DIS | |
| 482 | R300_CRTC_MACRO_TILE_EN); |
| 483 | else |
| 484 | crtc_offset_cntl &= ~RADEON_CRTC_TILE_EN; |
| 485 | } |
| 486 | |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 487 | if (tiling_flags & RADEON_TILING_MACRO) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 488 | if (ASIC_IS_R300(rdev)) { |
| 489 | crtc_tile_x0_y0 = x | (y << 16); |
| 490 | base &= ~0x7ff; |
| 491 | } else { |
| 492 | int byteshift = crtc->fb->bits_per_pixel >> 4; |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 493 | int tile_addr = (((y >> 3) * pitch_pixels + x) >> (8 - byteshift)) << 11; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 494 | base += tile_addr + ((x << byteshift) % 256) + ((y % 8) << 8); |
| 495 | crtc_offset_cntl |= (y % 16); |
| 496 | } |
| 497 | } else { |
| 498 | int offset = y * pitch_pixels + x; |
| 499 | switch (crtc->fb->bits_per_pixel) { |
Dave Airlie | 41456df | 2009-09-16 10:15:21 +1000 | [diff] [blame] | 500 | case 8: |
| 501 | offset *= 1; |
| 502 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 503 | case 15: |
| 504 | case 16: |
| 505 | offset *= 2; |
| 506 | break; |
| 507 | case 24: |
| 508 | offset *= 3; |
| 509 | break; |
| 510 | case 32: |
| 511 | offset *= 4; |
| 512 | break; |
| 513 | default: |
| 514 | return false; |
| 515 | } |
| 516 | base += offset; |
| 517 | } |
| 518 | |
| 519 | base &= ~7; |
| 520 | |
Dave Airlie | 41456df | 2009-09-16 10:15:21 +1000 | [diff] [blame] | 521 | if (radeon_crtc->crtc_id == 1) |
| 522 | gen_cntl_reg = RADEON_CRTC2_GEN_CNTL; |
| 523 | else |
| 524 | gen_cntl_reg = RADEON_CRTC_GEN_CNTL; |
| 525 | |
| 526 | gen_cntl_val = RREG32(gen_cntl_reg); |
| 527 | gen_cntl_val &= ~(0xf << 8); |
| 528 | gen_cntl_val |= (format << 8); |
| 529 | WREG32(gen_cntl_reg, gen_cntl_val); |
| 530 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 531 | crtc_offset = (u32)base; |
| 532 | |
Dave Airlie | 4162338 | 2009-07-09 15:04:19 +1000 | [diff] [blame] | 533 | WREG32(RADEON_DISPLAY_BASE_ADDR + radeon_crtc->crtc_offset, radeon_crtc->legacy_display_base_addr); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 534 | |
| 535 | if (ASIC_IS_R300(rdev)) { |
| 536 | if (radeon_crtc->crtc_id) |
| 537 | WREG32(R300_CRTC2_TILE_X0_Y0, crtc_tile_x0_y0); |
| 538 | else |
| 539 | WREG32(R300_CRTC_TILE_X0_Y0, crtc_tile_x0_y0); |
| 540 | } |
| 541 | WREG32(RADEON_CRTC_OFFSET_CNTL + radeon_crtc->crtc_offset, crtc_offset_cntl); |
| 542 | WREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset, crtc_offset); |
| 543 | WREG32(RADEON_CRTC_PITCH + radeon_crtc->crtc_offset, crtc_pitch); |
| 544 | |
| 545 | if (old_fb && old_fb != crtc->fb) { |
| 546 | radeon_fb = to_radeon_framebuffer(old_fb); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 547 | rbo = radeon_fb->obj->driver_private; |
| 548 | r = radeon_bo_reserve(rbo, false); |
| 549 | if (unlikely(r != 0)) |
| 550 | return r; |
| 551 | radeon_bo_unpin(rbo); |
| 552 | radeon_bo_unreserve(rbo); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 553 | } |
Michel Dänzer | f30f37d | 2009-10-08 10:44:09 +0200 | [diff] [blame] | 554 | |
| 555 | /* Bytes per pixel may have changed */ |
| 556 | radeon_bandwidth_update(rdev); |
| 557 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static bool radeon_set_crtc_timing(struct drm_crtc *crtc, struct drm_display_mode *mode) |
| 562 | { |
| 563 | struct drm_device *dev = crtc->dev; |
| 564 | struct radeon_device *rdev = dev->dev_private; |
| 565 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 566 | struct drm_encoder *encoder; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 567 | int format; |
| 568 | int hsync_start; |
| 569 | int hsync_wid; |
| 570 | int vsync_wid; |
| 571 | uint32_t crtc_h_total_disp; |
| 572 | uint32_t crtc_h_sync_strt_wid; |
| 573 | uint32_t crtc_v_total_disp; |
| 574 | uint32_t crtc_v_sync_strt_wid; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 575 | bool is_tv = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 576 | |
| 577 | DRM_DEBUG("\n"); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 578 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 579 | if (encoder->crtc == crtc) { |
| 580 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 581 | if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) { |
| 582 | is_tv = true; |
| 583 | DRM_INFO("crtc %d is connected to a TV\n", radeon_crtc->crtc_id); |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 588 | |
| 589 | switch (crtc->fb->bits_per_pixel) { |
Dave Airlie | 41456df | 2009-09-16 10:15:21 +1000 | [diff] [blame] | 590 | case 8: |
| 591 | format = 2; |
| 592 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 593 | case 15: /* 555 */ |
| 594 | format = 3; |
| 595 | break; |
| 596 | case 16: /* 565 */ |
| 597 | format = 4; |
| 598 | break; |
| 599 | case 24: /* RGB */ |
| 600 | format = 5; |
| 601 | break; |
| 602 | case 32: /* xRGB */ |
| 603 | format = 6; |
| 604 | break; |
| 605 | default: |
| 606 | return false; |
| 607 | } |
| 608 | |
| 609 | crtc_h_total_disp = ((((mode->crtc_htotal / 8) - 1) & 0x3ff) |
| 610 | | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16)); |
| 611 | |
| 612 | hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8; |
| 613 | if (!hsync_wid) |
| 614 | hsync_wid = 1; |
| 615 | hsync_start = mode->crtc_hsync_start - 8; |
| 616 | |
| 617 | crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) |
| 618 | | ((hsync_wid & 0x3f) << 16) |
| 619 | | ((mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 620 | ? RADEON_CRTC_H_SYNC_POL |
| 621 | : 0)); |
| 622 | |
| 623 | /* This works for double scan mode. */ |
| 624 | crtc_v_total_disp = (((mode->crtc_vtotal - 1) & 0xffff) |
| 625 | | ((mode->crtc_vdisplay - 1) << 16)); |
| 626 | |
| 627 | vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 628 | if (!vsync_wid) |
| 629 | vsync_wid = 1; |
| 630 | |
| 631 | crtc_v_sync_strt_wid = (((mode->crtc_vsync_start - 1) & 0xfff) |
| 632 | | ((vsync_wid & 0x1f) << 16) |
| 633 | | ((mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 634 | ? RADEON_CRTC_V_SYNC_POL |
| 635 | : 0)); |
| 636 | |
| 637 | /* TODO -> Dell Server */ |
| 638 | if (0) { |
| 639 | uint32_t disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG); |
| 640 | uint32_t tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); |
| 641 | uint32_t dac2_cntl = RREG32(RADEON_DAC_CNTL2); |
| 642 | uint32_t crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); |
| 643 | |
| 644 | dac2_cntl &= ~RADEON_DAC2_DAC_CLK_SEL; |
| 645 | dac2_cntl |= RADEON_DAC2_DAC2_CLK_SEL; |
| 646 | |
| 647 | /* For CRT on DAC2, don't turn it on if BIOS didn't |
| 648 | enable it, even it's detected. |
| 649 | */ |
| 650 | disp_hw_debug |= RADEON_CRT2_DISP1_SEL; |
| 651 | tv_dac_cntl &= ~((1<<2) | (3<<8) | (7<<24) | (0xff<<16)); |
| 652 | tv_dac_cntl |= (0x03 | (2<<8) | (0x58<<16)); |
| 653 | |
| 654 | WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); |
| 655 | WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug); |
| 656 | WREG32(RADEON_DAC_CNTL2, dac2_cntl); |
| 657 | WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl); |
| 658 | } |
| 659 | |
| 660 | if (radeon_crtc->crtc_id) { |
| 661 | uint32_t crtc2_gen_cntl; |
| 662 | uint32_t disp2_merge_cntl; |
| 663 | |
Jerome Glisse | ee2215f | 2009-11-26 15:58:36 +0100 | [diff] [blame] | 664 | /* if TV DAC is enabled for another crtc and keep it enabled */ |
| 665 | crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL) & 0x00718080; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 666 | crtc2_gen_cntl |= ((format << 8) |
| 667 | | RADEON_CRTC2_VSYNC_DIS |
| 668 | | RADEON_CRTC2_HSYNC_DIS |
| 669 | | RADEON_CRTC2_DISP_DIS |
| 670 | | RADEON_CRTC2_DISP_REQ_EN_B |
| 671 | | ((mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 672 | ? RADEON_CRTC2_DBL_SCAN_EN |
| 673 | : 0) |
| 674 | | ((mode->flags & DRM_MODE_FLAG_CSYNC) |
| 675 | ? RADEON_CRTC2_CSYNC_EN |
| 676 | : 0) |
| 677 | | ((mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 678 | ? RADEON_CRTC2_INTERLACE_EN |
| 679 | : 0)); |
| 680 | |
| 681 | disp2_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL); |
| 682 | disp2_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN; |
| 683 | |
| 684 | WREG32(RADEON_DISP2_MERGE_CNTL, disp2_merge_cntl); |
| 685 | WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl); |
Alex Deucher | 1b4d7d7 | 2009-10-15 01:33:35 -0400 | [diff] [blame] | 686 | |
| 687 | WREG32(RADEON_FP_H2_SYNC_STRT_WID, crtc_h_sync_strt_wid); |
| 688 | WREG32(RADEON_FP_V2_SYNC_STRT_WID, crtc_v_sync_strt_wid); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 689 | } else { |
| 690 | uint32_t crtc_gen_cntl; |
| 691 | uint32_t crtc_ext_cntl; |
| 692 | uint32_t disp_merge_cntl; |
| 693 | |
Jerome Glisse | ee2215f | 2009-11-26 15:58:36 +0100 | [diff] [blame] | 694 | crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL) & 0x00718000; |
| 695 | crtc_gen_cntl |= (RADEON_CRTC_EXT_DISP_EN |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 696 | | (format << 8) |
| 697 | | RADEON_CRTC_DISP_REQ_EN_B |
| 698 | | ((mode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 699 | ? RADEON_CRTC_DBL_SCAN_EN |
| 700 | : 0) |
| 701 | | ((mode->flags & DRM_MODE_FLAG_CSYNC) |
| 702 | ? RADEON_CRTC_CSYNC_EN |
| 703 | : 0) |
| 704 | | ((mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 705 | ? RADEON_CRTC_INTERLACE_EN |
| 706 | : 0)); |
| 707 | |
| 708 | crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL); |
| 709 | crtc_ext_cntl |= (RADEON_XCRT_CNT_EN | |
| 710 | RADEON_CRTC_VSYNC_DIS | |
| 711 | RADEON_CRTC_HSYNC_DIS | |
| 712 | RADEON_CRTC_DISPLAY_DIS); |
| 713 | |
| 714 | disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL); |
| 715 | disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN; |
| 716 | |
| 717 | WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl); |
| 718 | WREG32(RADEON_CRTC_GEN_CNTL, crtc_gen_cntl); |
| 719 | WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl); |
| 720 | } |
| 721 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 722 | if (is_tv) |
| 723 | radeon_legacy_tv_adjust_crtc_reg(encoder, &crtc_h_total_disp, |
| 724 | &crtc_h_sync_strt_wid, &crtc_v_total_disp, |
| 725 | &crtc_v_sync_strt_wid); |
| 726 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 727 | WREG32(RADEON_CRTC_H_TOTAL_DISP + radeon_crtc->crtc_offset, crtc_h_total_disp); |
| 728 | WREG32(RADEON_CRTC_H_SYNC_STRT_WID + radeon_crtc->crtc_offset, crtc_h_sync_strt_wid); |
| 729 | WREG32(RADEON_CRTC_V_TOTAL_DISP + radeon_crtc->crtc_offset, crtc_v_total_disp); |
| 730 | WREG32(RADEON_CRTC_V_SYNC_STRT_WID + radeon_crtc->crtc_offset, crtc_v_sync_strt_wid); |
| 731 | |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | static void radeon_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) |
| 736 | { |
| 737 | struct drm_device *dev = crtc->dev; |
| 738 | struct radeon_device *rdev = dev->dev_private; |
| 739 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 740 | struct drm_encoder *encoder; |
| 741 | uint32_t feedback_div = 0; |
| 742 | uint32_t frac_fb_div = 0; |
| 743 | uint32_t reference_div = 0; |
| 744 | uint32_t post_divider = 0; |
| 745 | uint32_t freq = 0; |
| 746 | uint8_t pll_gain; |
| 747 | int pll_flags = RADEON_PLL_LEGACY; |
| 748 | bool use_bios_divs = false; |
| 749 | /* PLL registers */ |
| 750 | uint32_t pll_ref_div = 0; |
| 751 | uint32_t pll_fb_post_div = 0; |
| 752 | uint32_t htotal_cntl = 0; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 753 | bool is_tv = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 754 | struct radeon_pll *pll; |
| 755 | |
| 756 | struct { |
| 757 | int divider; |
| 758 | int bitvalue; |
| 759 | } *post_div, post_divs[] = { |
| 760 | /* From RAGE 128 VR/RAGE 128 GL Register |
| 761 | * Reference Manual (Technical Reference |
| 762 | * Manual P/N RRG-G04100-C Rev. 0.04), page |
| 763 | * 3-17 (PLL_DIV_[3:0]). |
| 764 | */ |
| 765 | { 1, 0 }, /* VCLK_SRC */ |
| 766 | { 2, 1 }, /* VCLK_SRC/2 */ |
| 767 | { 4, 2 }, /* VCLK_SRC/4 */ |
| 768 | { 8, 3 }, /* VCLK_SRC/8 */ |
| 769 | { 3, 4 }, /* VCLK_SRC/3 */ |
| 770 | { 16, 5 }, /* VCLK_SRC/16 */ |
| 771 | { 6, 6 }, /* VCLK_SRC/6 */ |
| 772 | { 12, 7 }, /* VCLK_SRC/12 */ |
| 773 | { 0, 0 } |
| 774 | }; |
| 775 | |
| 776 | if (radeon_crtc->crtc_id) |
| 777 | pll = &rdev->clock.p2pll; |
| 778 | else |
| 779 | pll = &rdev->clock.p1pll; |
| 780 | |
| 781 | if (mode->clock > 200000) /* range limits??? */ |
| 782 | pll_flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; |
| 783 | else |
| 784 | pll_flags |= RADEON_PLL_PREFER_LOW_REF_DIV; |
| 785 | |
| 786 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 787 | if (encoder->crtc == crtc) { |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 788 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 789 | |
| 790 | if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) { |
| 791 | is_tv = true; |
| 792 | break; |
| 793 | } |
| 794 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 795 | if (encoder->encoder_type != DRM_MODE_ENCODER_DAC) |
| 796 | pll_flags |= RADEON_PLL_NO_ODD_POST_DIV; |
| 797 | if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS) { |
Alex Deucher | 4c4f541 | 2009-12-02 00:59:37 -0500 | [diff] [blame] | 798 | if (!rdev->is_atom_bios) { |
| 799 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 800 | struct radeon_encoder_lvds *lvds = (struct radeon_encoder_lvds *)radeon_encoder->enc_priv; |
| 801 | if (lvds) { |
| 802 | if (lvds->use_bios_dividers) { |
| 803 | pll_ref_div = lvds->panel_ref_divider; |
| 804 | pll_fb_post_div = (lvds->panel_fb_divider | |
| 805 | (lvds->panel_post_divider << 16)); |
| 806 | htotal_cntl = 0; |
| 807 | use_bios_divs = true; |
| 808 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 809 | } |
Alex Deucher | 4c4f541 | 2009-12-02 00:59:37 -0500 | [diff] [blame] | 810 | pll_flags |= RADEON_PLL_USE_REF_DIV; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 811 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | DRM_DEBUG("\n"); |
| 817 | |
| 818 | if (!use_bios_divs) { |
| 819 | radeon_compute_pll(pll, mode->clock, |
| 820 | &freq, &feedback_div, &frac_fb_div, |
| 821 | &reference_div, &post_divider, |
| 822 | pll_flags); |
| 823 | |
| 824 | for (post_div = &post_divs[0]; post_div->divider; ++post_div) { |
| 825 | if (post_div->divider == post_divider) |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | if (!post_div->divider) |
| 830 | post_div = &post_divs[0]; |
| 831 | |
| 832 | DRM_DEBUG("dc=%u, fd=%d, rd=%d, pd=%d\n", |
| 833 | (unsigned)freq, |
| 834 | feedback_div, |
| 835 | reference_div, |
| 836 | post_divider); |
| 837 | |
| 838 | pll_ref_div = reference_div; |
| 839 | #if defined(__powerpc__) && (0) /* TODO */ |
| 840 | /* apparently programming this otherwise causes a hang??? */ |
| 841 | if (info->MacModel == RADEON_MAC_IBOOK) |
| 842 | pll_fb_post_div = 0x000600ad; |
| 843 | else |
| 844 | #endif |
| 845 | pll_fb_post_div = (feedback_div | (post_div->bitvalue << 16)); |
| 846 | |
| 847 | htotal_cntl = mode->htotal & 0x7; |
| 848 | |
| 849 | } |
| 850 | |
| 851 | pll_gain = radeon_compute_pll_gain(pll->reference_freq, |
| 852 | pll_ref_div & 0x3ff, |
| 853 | pll_fb_post_div & 0x7ff); |
| 854 | |
| 855 | if (radeon_crtc->crtc_id) { |
| 856 | uint32_t pixclks_cntl = ((RREG32_PLL(RADEON_PIXCLKS_CNTL) & |
| 857 | ~(RADEON_PIX2CLK_SRC_SEL_MASK)) | |
| 858 | RADEON_PIX2CLK_SRC_SEL_P2PLLCLK); |
| 859 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 860 | if (is_tv) { |
| 861 | radeon_legacy_tv_adjust_pll2(encoder, &htotal_cntl, |
| 862 | &pll_ref_div, &pll_fb_post_div, |
| 863 | &pixclks_cntl); |
| 864 | } |
| 865 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 866 | WREG32_PLL_P(RADEON_PIXCLKS_CNTL, |
| 867 | RADEON_PIX2CLK_SRC_SEL_CPUCLK, |
| 868 | ~(RADEON_PIX2CLK_SRC_SEL_MASK)); |
| 869 | |
| 870 | WREG32_PLL_P(RADEON_P2PLL_CNTL, |
| 871 | RADEON_P2PLL_RESET |
| 872 | | RADEON_P2PLL_ATOMIC_UPDATE_EN |
| 873 | | ((uint32_t)pll_gain << RADEON_P2PLL_PVG_SHIFT), |
| 874 | ~(RADEON_P2PLL_RESET |
| 875 | | RADEON_P2PLL_ATOMIC_UPDATE_EN |
| 876 | | RADEON_P2PLL_PVG_MASK)); |
| 877 | |
| 878 | WREG32_PLL_P(RADEON_P2PLL_REF_DIV, |
| 879 | pll_ref_div, |
| 880 | ~RADEON_P2PLL_REF_DIV_MASK); |
| 881 | |
| 882 | WREG32_PLL_P(RADEON_P2PLL_DIV_0, |
| 883 | pll_fb_post_div, |
| 884 | ~RADEON_P2PLL_FB0_DIV_MASK); |
| 885 | |
| 886 | WREG32_PLL_P(RADEON_P2PLL_DIV_0, |
| 887 | pll_fb_post_div, |
| 888 | ~RADEON_P2PLL_POST0_DIV_MASK); |
| 889 | |
| 890 | radeon_pll2_write_update(dev); |
| 891 | radeon_pll2_wait_for_read_update_complete(dev); |
| 892 | |
| 893 | WREG32_PLL(RADEON_HTOTAL2_CNTL, htotal_cntl); |
| 894 | |
| 895 | WREG32_PLL_P(RADEON_P2PLL_CNTL, |
| 896 | 0, |
| 897 | ~(RADEON_P2PLL_RESET |
| 898 | | RADEON_P2PLL_SLEEP |
| 899 | | RADEON_P2PLL_ATOMIC_UPDATE_EN)); |
| 900 | |
| 901 | DRM_DEBUG("Wrote2: 0x%08x 0x%08x 0x%08x (0x%08x)\n", |
| 902 | (unsigned)pll_ref_div, |
| 903 | (unsigned)pll_fb_post_div, |
| 904 | (unsigned)htotal_cntl, |
| 905 | RREG32_PLL(RADEON_P2PLL_CNTL)); |
| 906 | DRM_DEBUG("Wrote2: rd=%u, fd=%u, pd=%u\n", |
| 907 | (unsigned)pll_ref_div & RADEON_P2PLL_REF_DIV_MASK, |
| 908 | (unsigned)pll_fb_post_div & RADEON_P2PLL_FB0_DIV_MASK, |
| 909 | (unsigned)((pll_fb_post_div & |
| 910 | RADEON_P2PLL_POST0_DIV_MASK) >> 16)); |
| 911 | |
| 912 | mdelay(50); /* Let the clock to lock */ |
| 913 | |
| 914 | WREG32_PLL_P(RADEON_PIXCLKS_CNTL, |
| 915 | RADEON_PIX2CLK_SRC_SEL_P2PLLCLK, |
| 916 | ~(RADEON_PIX2CLK_SRC_SEL_MASK)); |
| 917 | |
| 918 | WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl); |
| 919 | } else { |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 920 | uint32_t pixclks_cntl; |
| 921 | |
| 922 | |
| 923 | if (is_tv) { |
| 924 | pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL); |
| 925 | radeon_legacy_tv_adjust_pll1(encoder, &htotal_cntl, &pll_ref_div, |
| 926 | &pll_fb_post_div, &pixclks_cntl); |
| 927 | } |
| 928 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 929 | if (rdev->flags & RADEON_IS_MOBILITY) { |
| 930 | /* A temporal workaround for the occational blanking on certain laptop panels. |
| 931 | This appears to related to the PLL divider registers (fail to lock?). |
| 932 | It occurs even when all dividers are the same with their old settings. |
| 933 | In this case we really don't need to fiddle with PLL registers. |
| 934 | By doing this we can avoid the blanking problem with some panels. |
| 935 | */ |
| 936 | if ((pll_ref_div == (RREG32_PLL(RADEON_PPLL_REF_DIV) & RADEON_PPLL_REF_DIV_MASK)) && |
| 937 | (pll_fb_post_div == (RREG32_PLL(RADEON_PPLL_DIV_3) & |
| 938 | (RADEON_PPLL_POST3_DIV_MASK | RADEON_PPLL_FB3_DIV_MASK)))) { |
| 939 | WREG32_P(RADEON_CLOCK_CNTL_INDEX, |
| 940 | RADEON_PLL_DIV_SEL, |
| 941 | ~(RADEON_PLL_DIV_SEL)); |
| 942 | r100_pll_errata_after_index(rdev); |
| 943 | return; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | WREG32_PLL_P(RADEON_VCLK_ECP_CNTL, |
| 948 | RADEON_VCLK_SRC_SEL_CPUCLK, |
| 949 | ~(RADEON_VCLK_SRC_SEL_MASK)); |
| 950 | WREG32_PLL_P(RADEON_PPLL_CNTL, |
| 951 | RADEON_PPLL_RESET |
| 952 | | RADEON_PPLL_ATOMIC_UPDATE_EN |
| 953 | | RADEON_PPLL_VGA_ATOMIC_UPDATE_EN |
| 954 | | ((uint32_t)pll_gain << RADEON_PPLL_PVG_SHIFT), |
| 955 | ~(RADEON_PPLL_RESET |
| 956 | | RADEON_PPLL_ATOMIC_UPDATE_EN |
| 957 | | RADEON_PPLL_VGA_ATOMIC_UPDATE_EN |
| 958 | | RADEON_PPLL_PVG_MASK)); |
| 959 | |
| 960 | WREG32_P(RADEON_CLOCK_CNTL_INDEX, |
| 961 | RADEON_PLL_DIV_SEL, |
| 962 | ~(RADEON_PLL_DIV_SEL)); |
| 963 | r100_pll_errata_after_index(rdev); |
| 964 | |
| 965 | if (ASIC_IS_R300(rdev) || |
| 966 | (rdev->family == CHIP_RS300) || |
| 967 | (rdev->family == CHIP_RS400) || |
| 968 | (rdev->family == CHIP_RS480)) { |
| 969 | if (pll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) { |
| 970 | /* When restoring console mode, use saved PPLL_REF_DIV |
| 971 | * setting. |
| 972 | */ |
| 973 | WREG32_PLL_P(RADEON_PPLL_REF_DIV, |
| 974 | pll_ref_div, |
| 975 | 0); |
| 976 | } else { |
| 977 | /* R300 uses ref_div_acc field as real ref divider */ |
| 978 | WREG32_PLL_P(RADEON_PPLL_REF_DIV, |
| 979 | (pll_ref_div << R300_PPLL_REF_DIV_ACC_SHIFT), |
| 980 | ~R300_PPLL_REF_DIV_ACC_MASK); |
| 981 | } |
| 982 | } else |
| 983 | WREG32_PLL_P(RADEON_PPLL_REF_DIV, |
| 984 | pll_ref_div, |
| 985 | ~RADEON_PPLL_REF_DIV_MASK); |
| 986 | |
| 987 | WREG32_PLL_P(RADEON_PPLL_DIV_3, |
| 988 | pll_fb_post_div, |
| 989 | ~RADEON_PPLL_FB3_DIV_MASK); |
| 990 | |
| 991 | WREG32_PLL_P(RADEON_PPLL_DIV_3, |
| 992 | pll_fb_post_div, |
| 993 | ~RADEON_PPLL_POST3_DIV_MASK); |
| 994 | |
| 995 | radeon_pll_write_update(dev); |
| 996 | radeon_pll_wait_for_read_update_complete(dev); |
| 997 | |
| 998 | WREG32_PLL(RADEON_HTOTAL_CNTL, htotal_cntl); |
| 999 | |
| 1000 | WREG32_PLL_P(RADEON_PPLL_CNTL, |
| 1001 | 0, |
| 1002 | ~(RADEON_PPLL_RESET |
| 1003 | | RADEON_PPLL_SLEEP |
| 1004 | | RADEON_PPLL_ATOMIC_UPDATE_EN |
| 1005 | | RADEON_PPLL_VGA_ATOMIC_UPDATE_EN)); |
| 1006 | |
| 1007 | DRM_DEBUG("Wrote: 0x%08x 0x%08x 0x%08x (0x%08x)\n", |
| 1008 | pll_ref_div, |
| 1009 | pll_fb_post_div, |
| 1010 | (unsigned)htotal_cntl, |
| 1011 | RREG32_PLL(RADEON_PPLL_CNTL)); |
| 1012 | DRM_DEBUG("Wrote: rd=%d, fd=%d, pd=%d\n", |
| 1013 | pll_ref_div & RADEON_PPLL_REF_DIV_MASK, |
| 1014 | pll_fb_post_div & RADEON_PPLL_FB3_DIV_MASK, |
| 1015 | (pll_fb_post_div & RADEON_PPLL_POST3_DIV_MASK) >> 16); |
| 1016 | |
| 1017 | mdelay(50); /* Let the clock to lock */ |
| 1018 | |
| 1019 | WREG32_PLL_P(RADEON_VCLK_ECP_CNTL, |
| 1020 | RADEON_VCLK_SRC_SEL_PPLLCLK, |
| 1021 | ~(RADEON_VCLK_SRC_SEL_MASK)); |
| 1022 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1023 | if (is_tv) |
| 1024 | WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | static bool radeon_crtc_mode_fixup(struct drm_crtc *crtc, |
| 1029 | struct drm_display_mode *mode, |
| 1030 | struct drm_display_mode *adjusted_mode) |
| 1031 | { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1032 | if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) |
| 1033 | return false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1034 | return true; |
| 1035 | } |
| 1036 | |
| 1037 | static int radeon_crtc_mode_set(struct drm_crtc *crtc, |
| 1038 | struct drm_display_mode *mode, |
| 1039 | struct drm_display_mode *adjusted_mode, |
| 1040 | int x, int y, struct drm_framebuffer *old_fb) |
| 1041 | { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1042 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1043 | |
| 1044 | /* TODO TV */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1045 | radeon_crtc_set_base(crtc, x, y, old_fb); |
| 1046 | radeon_set_crtc_timing(crtc, adjusted_mode); |
| 1047 | radeon_set_pll(crtc, adjusted_mode); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1048 | if (radeon_crtc->crtc_id == 0) { |
| 1049 | radeon_legacy_rmx_mode_set(crtc, mode, adjusted_mode); |
| 1050 | } else { |
| 1051 | if (radeon_crtc->rmx_type != RMX_OFF) { |
| 1052 | /* FIXME: only first crtc has rmx what should we |
| 1053 | * do ? |
| 1054 | */ |
| 1055 | DRM_ERROR("Mode need scaling but only first crtc can do that.\n"); |
| 1056 | } |
| 1057 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | static void radeon_crtc_prepare(struct drm_crtc *crtc) |
| 1062 | { |
Pierre Ossman | ec51efa | 2009-11-30 21:15:44 +0100 | [diff] [blame] | 1063 | struct drm_device *dev = crtc->dev; |
| 1064 | struct drm_crtc *crtci; |
| 1065 | |
| 1066 | /* |
| 1067 | * The hardware wedges sometimes if you reconfigure one CRTC |
| 1068 | * whilst another is running (see fdo bug #24611). |
| 1069 | */ |
| 1070 | list_for_each_entry(crtci, &dev->mode_config.crtc_list, head) |
| 1071 | radeon_crtc_dpms(crtci, DRM_MODE_DPMS_OFF); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | static void radeon_crtc_commit(struct drm_crtc *crtc) |
| 1075 | { |
Pierre Ossman | ec51efa | 2009-11-30 21:15:44 +0100 | [diff] [blame] | 1076 | struct drm_device *dev = crtc->dev; |
| 1077 | struct drm_crtc *crtci; |
| 1078 | |
| 1079 | /* |
| 1080 | * Reenable the CRTCs that should be running. |
| 1081 | */ |
| 1082 | list_for_each_entry(crtci, &dev->mode_config.crtc_list, head) { |
| 1083 | if (crtci->enabled) |
| 1084 | radeon_crtc_dpms(crtci, DRM_MODE_DPMS_ON); |
| 1085 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | static const struct drm_crtc_helper_funcs legacy_helper_funcs = { |
| 1089 | .dpms = radeon_crtc_dpms, |
| 1090 | .mode_fixup = radeon_crtc_mode_fixup, |
| 1091 | .mode_set = radeon_crtc_mode_set, |
| 1092 | .mode_set_base = radeon_crtc_set_base, |
| 1093 | .prepare = radeon_crtc_prepare, |
| 1094 | .commit = radeon_crtc_commit, |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1095 | .load_lut = radeon_crtc_load_lut, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1096 | }; |
| 1097 | |
| 1098 | |
| 1099 | void radeon_legacy_init_crtc(struct drm_device *dev, |
| 1100 | struct radeon_crtc *radeon_crtc) |
| 1101 | { |
| 1102 | if (radeon_crtc->crtc_id == 1) |
| 1103 | radeon_crtc->crtc_offset = RADEON_CRTC2_H_TOTAL_DISP - RADEON_CRTC_H_TOTAL_DISP; |
| 1104 | drm_crtc_helper_add(&radeon_crtc->base, &legacy_helper_funcs); |
| 1105 | } |