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 | */ |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 26 | #include <drm/drmP.h> |
| 27 | #include <drm/radeon_drm.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 28 | #include "radeon.h" |
| 29 | |
| 30 | #include "atom.h" |
| 31 | #include <asm/div64.h> |
| 32 | |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/drm_crtc_helper.h> |
| 35 | #include <drm/drm_edid.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 36 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 37 | #include <linux/gcd.h> |
| 38 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 39 | static void avivo_crtc_load_lut(struct drm_crtc *crtc) |
| 40 | { |
| 41 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 42 | struct drm_device *dev = crtc->dev; |
| 43 | struct radeon_device *rdev = dev->dev_private; |
| 44 | int i; |
| 45 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 46 | DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 47 | WREG32(AVIVO_DC_LUTA_CONTROL + radeon_crtc->crtc_offset, 0); |
| 48 | |
| 49 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
| 50 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
| 51 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
| 52 | |
| 53 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
| 54 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
| 55 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
| 56 | |
| 57 | WREG32(AVIVO_DC_LUT_RW_SELECT, radeon_crtc->crtc_id); |
| 58 | WREG32(AVIVO_DC_LUT_RW_MODE, 0); |
| 59 | WREG32(AVIVO_DC_LUT_WRITE_EN_MASK, 0x0000003f); |
| 60 | |
| 61 | WREG8(AVIVO_DC_LUT_RW_INDEX, 0); |
| 62 | for (i = 0; i < 256; i++) { |
| 63 | WREG32(AVIVO_DC_LUT_30_COLOR, |
| 64 | (radeon_crtc->lut_r[i] << 20) | |
| 65 | (radeon_crtc->lut_g[i] << 10) | |
| 66 | (radeon_crtc->lut_b[i] << 0)); |
| 67 | } |
| 68 | |
| 69 | WREG32(AVIVO_D1GRPH_LUT_SEL + radeon_crtc->crtc_offset, radeon_crtc->crtc_id); |
| 70 | } |
| 71 | |
Alex Deucher | fee298f | 2011-01-06 21:19:30 -0500 | [diff] [blame] | 72 | static void dce4_crtc_load_lut(struct drm_crtc *crtc) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 73 | { |
| 74 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 75 | struct drm_device *dev = crtc->dev; |
| 76 | struct radeon_device *rdev = dev->dev_private; |
| 77 | int i; |
| 78 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 79 | DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 80 | WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0); |
| 81 | |
| 82 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
| 83 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
| 84 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
| 85 | |
| 86 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
| 87 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
| 88 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
| 89 | |
Alex Deucher | 677d076 | 2010-04-22 22:58:50 -0400 | [diff] [blame] | 90 | WREG32(EVERGREEN_DC_LUT_RW_MODE + radeon_crtc->crtc_offset, 0); |
| 91 | WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK + radeon_crtc->crtc_offset, 0x00000007); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 92 | |
Alex Deucher | 677d076 | 2010-04-22 22:58:50 -0400 | [diff] [blame] | 93 | WREG32(EVERGREEN_DC_LUT_RW_INDEX + radeon_crtc->crtc_offset, 0); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 94 | for (i = 0; i < 256; i++) { |
Alex Deucher | 677d076 | 2010-04-22 22:58:50 -0400 | [diff] [blame] | 95 | WREG32(EVERGREEN_DC_LUT_30_COLOR + radeon_crtc->crtc_offset, |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 96 | (radeon_crtc->lut_r[i] << 20) | |
| 97 | (radeon_crtc->lut_g[i] << 10) | |
| 98 | (radeon_crtc->lut_b[i] << 0)); |
| 99 | } |
| 100 | } |
| 101 | |
Alex Deucher | fee298f | 2011-01-06 21:19:30 -0500 | [diff] [blame] | 102 | static void dce5_crtc_load_lut(struct drm_crtc *crtc) |
| 103 | { |
| 104 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 105 | struct drm_device *dev = crtc->dev; |
| 106 | struct radeon_device *rdev = dev->dev_private; |
| 107 | int i; |
| 108 | |
| 109 | DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id); |
| 110 | |
| 111 | WREG32(NI_INPUT_CSC_CONTROL + radeon_crtc->crtc_offset, |
| 112 | (NI_INPUT_CSC_GRPH_MODE(NI_INPUT_CSC_BYPASS) | |
| 113 | NI_INPUT_CSC_OVL_MODE(NI_INPUT_CSC_BYPASS))); |
| 114 | WREG32(NI_PRESCALE_GRPH_CONTROL + radeon_crtc->crtc_offset, |
| 115 | NI_GRPH_PRESCALE_BYPASS); |
| 116 | WREG32(NI_PRESCALE_OVL_CONTROL + radeon_crtc->crtc_offset, |
| 117 | NI_OVL_PRESCALE_BYPASS); |
| 118 | WREG32(NI_INPUT_GAMMA_CONTROL + radeon_crtc->crtc_offset, |
| 119 | (NI_GRPH_INPUT_GAMMA_MODE(NI_INPUT_GAMMA_USE_LUT) | |
| 120 | NI_OVL_INPUT_GAMMA_MODE(NI_INPUT_GAMMA_USE_LUT))); |
| 121 | |
| 122 | WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0); |
| 123 | |
| 124 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
| 125 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
| 126 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
| 127 | |
| 128 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
| 129 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
| 130 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
| 131 | |
| 132 | WREG32(EVERGREEN_DC_LUT_RW_MODE + radeon_crtc->crtc_offset, 0); |
| 133 | WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK + radeon_crtc->crtc_offset, 0x00000007); |
| 134 | |
| 135 | WREG32(EVERGREEN_DC_LUT_RW_INDEX + radeon_crtc->crtc_offset, 0); |
| 136 | for (i = 0; i < 256; i++) { |
| 137 | WREG32(EVERGREEN_DC_LUT_30_COLOR + radeon_crtc->crtc_offset, |
| 138 | (radeon_crtc->lut_r[i] << 20) | |
| 139 | (radeon_crtc->lut_g[i] << 10) | |
| 140 | (radeon_crtc->lut_b[i] << 0)); |
| 141 | } |
| 142 | |
| 143 | WREG32(NI_DEGAMMA_CONTROL + radeon_crtc->crtc_offset, |
| 144 | (NI_GRPH_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) | |
| 145 | NI_OVL_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) | |
| 146 | NI_ICON_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) | |
| 147 | NI_CURSOR_DEGAMMA_MODE(NI_DEGAMMA_BYPASS))); |
| 148 | WREG32(NI_GAMUT_REMAP_CONTROL + radeon_crtc->crtc_offset, |
| 149 | (NI_GRPH_GAMUT_REMAP_MODE(NI_GAMUT_REMAP_BYPASS) | |
| 150 | NI_OVL_GAMUT_REMAP_MODE(NI_GAMUT_REMAP_BYPASS))); |
| 151 | WREG32(NI_REGAMMA_CONTROL + radeon_crtc->crtc_offset, |
| 152 | (NI_GRPH_REGAMMA_MODE(NI_REGAMMA_BYPASS) | |
| 153 | NI_OVL_REGAMMA_MODE(NI_REGAMMA_BYPASS))); |
| 154 | WREG32(NI_OUTPUT_CSC_CONTROL + radeon_crtc->crtc_offset, |
| 155 | (NI_OUTPUT_CSC_GRPH_MODE(NI_OUTPUT_CSC_BYPASS) | |
| 156 | NI_OUTPUT_CSC_OVL_MODE(NI_OUTPUT_CSC_BYPASS))); |
| 157 | /* XXX match this to the depth of the crtc fmt block, move to modeset? */ |
| 158 | WREG32(0x6940 + radeon_crtc->crtc_offset, 0); |
Alex Deucher | 9e05fa1 | 2013-01-24 10:06:33 -0500 | [diff] [blame] | 159 | if (ASIC_IS_DCE8(rdev)) { |
| 160 | /* XXX this only needs to be programmed once per crtc at startup, |
| 161 | * not sure where the best place for it is |
| 162 | */ |
| 163 | WREG32(CIK_ALPHA_CONTROL + radeon_crtc->crtc_offset, |
| 164 | CIK_CURSOR_ALPHA_BLND_ENA); |
| 165 | } |
Alex Deucher | fee298f | 2011-01-06 21:19:30 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 168 | static void legacy_crtc_load_lut(struct drm_crtc *crtc) |
| 169 | { |
| 170 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 171 | struct drm_device *dev = crtc->dev; |
| 172 | struct radeon_device *rdev = dev->dev_private; |
| 173 | int i; |
| 174 | uint32_t dac2_cntl; |
| 175 | |
| 176 | dac2_cntl = RREG32(RADEON_DAC_CNTL2); |
| 177 | if (radeon_crtc->crtc_id == 0) |
| 178 | dac2_cntl &= (uint32_t)~RADEON_DAC2_PALETTE_ACC_CTL; |
| 179 | else |
| 180 | dac2_cntl |= RADEON_DAC2_PALETTE_ACC_CTL; |
| 181 | WREG32(RADEON_DAC_CNTL2, dac2_cntl); |
| 182 | |
| 183 | WREG8(RADEON_PALETTE_INDEX, 0); |
| 184 | for (i = 0; i < 256; i++) { |
| 185 | WREG32(RADEON_PALETTE_30_DATA, |
| 186 | (radeon_crtc->lut_r[i] << 20) | |
| 187 | (radeon_crtc->lut_g[i] << 10) | |
| 188 | (radeon_crtc->lut_b[i] << 0)); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | void radeon_crtc_load_lut(struct drm_crtc *crtc) |
| 193 | { |
| 194 | struct drm_device *dev = crtc->dev; |
| 195 | struct radeon_device *rdev = dev->dev_private; |
| 196 | |
| 197 | if (!crtc->enabled) |
| 198 | return; |
| 199 | |
Alex Deucher | fee298f | 2011-01-06 21:19:30 -0500 | [diff] [blame] | 200 | if (ASIC_IS_DCE5(rdev)) |
| 201 | dce5_crtc_load_lut(crtc); |
| 202 | else if (ASIC_IS_DCE4(rdev)) |
| 203 | dce4_crtc_load_lut(crtc); |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 204 | else if (ASIC_IS_AVIVO(rdev)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 205 | avivo_crtc_load_lut(crtc); |
| 206 | else |
| 207 | legacy_crtc_load_lut(crtc); |
| 208 | } |
| 209 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 210 | /** Sets the color ramps on behalf of fbcon */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 211 | void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
| 212 | u16 blue, int regno) |
| 213 | { |
| 214 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 215 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 216 | radeon_crtc->lut_r[regno] = red >> 6; |
| 217 | radeon_crtc->lut_g[regno] = green >> 6; |
| 218 | radeon_crtc->lut_b[regno] = blue >> 6; |
| 219 | } |
| 220 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 221 | /** Gets the color ramps on behalf of fbcon */ |
| 222 | void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
| 223 | u16 *blue, int regno) |
| 224 | { |
| 225 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 226 | |
| 227 | *red = radeon_crtc->lut_r[regno] << 6; |
| 228 | *green = radeon_crtc->lut_g[regno] << 6; |
| 229 | *blue = radeon_crtc->lut_b[regno] << 6; |
| 230 | } |
| 231 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 232 | static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 233 | u16 *blue, uint32_t start, uint32_t size) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 234 | { |
| 235 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 236 | int end = (start + size > 256) ? 256 : start + size, i; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 237 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 238 | /* userspace palettes are always correct as is */ |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 239 | for (i = start; i < end; i++) { |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 240 | radeon_crtc->lut_r[i] = red[i] >> 6; |
| 241 | radeon_crtc->lut_g[i] = green[i] >> 6; |
| 242 | radeon_crtc->lut_b[i] = blue[i] >> 6; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 243 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 244 | radeon_crtc_load_lut(crtc); |
| 245 | } |
| 246 | |
| 247 | static void radeon_crtc_destroy(struct drm_crtc *crtc) |
| 248 | { |
| 249 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 250 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 251 | drm_crtc_cleanup(crtc); |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 252 | destroy_workqueue(radeon_crtc->flip_queue); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 253 | kfree(radeon_crtc); |
| 254 | } |
| 255 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 256 | /** |
| 257 | * radeon_unpin_work_func - unpin old buffer object |
| 258 | * |
| 259 | * @__work - kernel work item |
| 260 | * |
| 261 | * Unpin the old frame buffer object outside of the interrupt handler |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 262 | */ |
| 263 | static void radeon_unpin_work_func(struct work_struct *__work) |
| 264 | { |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 265 | struct radeon_flip_work *work = |
| 266 | container_of(__work, struct radeon_flip_work, unpin_work); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 267 | int r; |
| 268 | |
| 269 | /* unpin of the old buffer */ |
| 270 | r = radeon_bo_reserve(work->old_rbo, false); |
| 271 | if (likely(r == 0)) { |
| 272 | r = radeon_bo_unpin(work->old_rbo); |
| 273 | if (unlikely(r != 0)) { |
| 274 | DRM_ERROR("failed to unpin buffer after flip\n"); |
| 275 | } |
| 276 | radeon_bo_unreserve(work->old_rbo); |
| 277 | } else |
| 278 | DRM_ERROR("failed to reserve buffer after flip\n"); |
Dave Airlie | 498c555 | 2011-05-29 17:48:32 +1000 | [diff] [blame] | 279 | |
| 280 | drm_gem_object_unreference_unlocked(&work->old_rbo->gem_base); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 281 | kfree(work); |
| 282 | } |
| 283 | |
Christian König | 1a0e791 | 2014-05-27 16:49:21 +0200 | [diff] [blame] | 284 | void radeon_crtc_handle_vblank(struct radeon_device *rdev, int crtc_id) |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 285 | { |
| 286 | struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 287 | struct radeon_flip_work *work; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 288 | unsigned long flags; |
| 289 | u32 update_pending; |
| 290 | int vpos, hpos; |
| 291 | |
| 292 | spin_lock_irqsave(&rdev->ddev->event_lock, flags); |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 293 | work = radeon_crtc->flip_work; |
| 294 | if (work == NULL) { |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 295 | spin_unlock_irqrestore(&rdev->ddev->event_lock, flags); |
| 296 | return; |
| 297 | } |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 298 | |
| 299 | update_pending = radeon_page_flip_pending(rdev, crtc_id); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 300 | |
| 301 | /* Has the pageflip already completed in crtc, or is it certain |
| 302 | * to complete in this vblank? |
| 303 | */ |
| 304 | if (update_pending && |
Ville Syrjälä | abca9e45 | 2013-10-28 20:50:48 +0200 | [diff] [blame] | 305 | (DRM_SCANOUTPOS_VALID & radeon_get_crtc_scanoutpos(rdev->ddev, crtc_id, 0, |
Mario Kleiner | d47abc5 | 2013-10-30 05:13:07 +0100 | [diff] [blame] | 306 | &vpos, &hpos, NULL, NULL)) && |
Felix Kuehling | 81ffbbe | 2012-02-23 19:16:12 -0500 | [diff] [blame] | 307 | ((vpos >= (99 * rdev->mode_info.crtcs[crtc_id]->base.hwmode.crtc_vdisplay)/100) || |
| 308 | (vpos < 0 && !ASIC_IS_AVIVO(rdev)))) { |
| 309 | /* crtc didn't flip in this target vblank interval, |
| 310 | * but flip is pending in crtc. Based on the current |
| 311 | * scanout position we know that the current frame is |
| 312 | * (nearly) complete and the flip will (likely) |
| 313 | * complete before the start of the next frame. |
| 314 | */ |
| 315 | update_pending = 0; |
| 316 | } |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 317 | spin_unlock_irqrestore(&rdev->ddev->event_lock, flags); |
| 318 | if (!update_pending) |
Christian König | 1a0e791 | 2014-05-27 16:49:21 +0200 | [diff] [blame] | 319 | radeon_crtc_handle_flip(rdev, crtc_id); |
Christian König | 1a0e791 | 2014-05-27 16:49:21 +0200 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /** |
| 323 | * radeon_crtc_handle_flip - page flip completed |
| 324 | * |
| 325 | * @rdev: radeon device pointer |
| 326 | * @crtc_id: crtc number this event is for |
| 327 | * |
| 328 | * Called when we are sure that a page flip for this crtc is completed. |
| 329 | */ |
| 330 | void radeon_crtc_handle_flip(struct radeon_device *rdev, int crtc_id) |
| 331 | { |
| 332 | struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 333 | struct radeon_flip_work *work; |
Christian König | 1a0e791 | 2014-05-27 16:49:21 +0200 | [diff] [blame] | 334 | unsigned long flags; |
| 335 | |
| 336 | /* this can happen at init */ |
| 337 | if (radeon_crtc == NULL) |
| 338 | return; |
| 339 | |
| 340 | spin_lock_irqsave(&rdev->ddev->event_lock, flags); |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 341 | work = radeon_crtc->flip_work; |
Christian König | 1a0e791 | 2014-05-27 16:49:21 +0200 | [diff] [blame] | 342 | if (work == NULL) { |
| 343 | spin_unlock_irqrestore(&rdev->ddev->event_lock, flags); |
| 344 | return; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 345 | } |
| 346 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 347 | /* Pageflip completed. Clean up. */ |
| 348 | radeon_crtc->flip_work = NULL; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 349 | |
| 350 | /* wakeup userspace */ |
Rob Clark | 26ae466 | 2012-10-08 19:50:42 +0000 | [diff] [blame] | 351 | if (work->event) |
| 352 | drm_send_vblank_event(rdev->ddev, crtc_id, work->event); |
| 353 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 354 | spin_unlock_irqrestore(&rdev->ddev->event_lock, flags); |
| 355 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 356 | radeon_fence_unref(&work->fence); |
Christian König | e928c61 | 2014-05-27 16:49:18 +0200 | [diff] [blame] | 357 | radeon_irq_kms_pflip_irq_get(rdev, work->crtc_id); |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 358 | queue_work(radeon_crtc->flip_queue, &work->unpin_work); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 359 | } |
| 360 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 361 | /** |
| 362 | * radeon_flip_work_func - page flip framebuffer |
| 363 | * |
| 364 | * @work - kernel work item |
| 365 | * |
| 366 | * Wait for the buffer object to become idle and do the actual page flip |
| 367 | */ |
| 368 | static void radeon_flip_work_func(struct work_struct *__work) |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 369 | { |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 370 | struct radeon_flip_work *work = |
| 371 | container_of(__work, struct radeon_flip_work, flip_work); |
| 372 | struct radeon_device *rdev = work->rdev; |
| 373 | struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[work->crtc_id]; |
| 374 | |
| 375 | struct drm_crtc *crtc = &radeon_crtc->base; |
| 376 | struct drm_framebuffer *fb = work->fb; |
| 377 | |
| 378 | uint32_t tiling_flags, pitch_pixels; |
| 379 | uint64_t base; |
| 380 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 381 | unsigned long flags; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 382 | int r; |
| 383 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 384 | down_read(&rdev->exclusive_lock); |
| 385 | while (work->fence) { |
| 386 | r = radeon_fence_wait(work->fence, false); |
| 387 | if (r == -EDEADLK) { |
| 388 | up_read(&rdev->exclusive_lock); |
| 389 | r = radeon_gpu_reset(rdev); |
| 390 | down_read(&rdev->exclusive_lock); |
| 391 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 392 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 393 | if (r) { |
| 394 | DRM_ERROR("failed to wait on page flip fence (%d)!\n", |
| 395 | r); |
| 396 | goto cleanup; |
| 397 | } else |
| 398 | radeon_fence_unref(&work->fence); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 399 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 400 | |
| 401 | /* pin the new buffer */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 402 | DRM_DEBUG_DRIVER("flip-ioctl() cur_fbo = %p, cur_bbo = %p\n", |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 403 | work->old_rbo, work->new_rbo); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 404 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 405 | r = radeon_bo_reserve(work->new_rbo, false); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 406 | if (unlikely(r != 0)) { |
| 407 | DRM_ERROR("failed to reserve new rbo buffer before flip\n"); |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 408 | goto cleanup; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 409 | } |
Michel Dänzer | 0349af7 | 2012-03-14 17:12:42 +0100 | [diff] [blame] | 410 | /* Only 27 bit offset for legacy CRTC */ |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 411 | r = radeon_bo_pin_restricted(work->new_rbo, RADEON_GEM_DOMAIN_VRAM, |
Michel Dänzer | 0349af7 | 2012-03-14 17:12:42 +0100 | [diff] [blame] | 412 | ASIC_IS_AVIVO(rdev) ? 0 : 1 << 27, &base); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 413 | if (unlikely(r != 0)) { |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 414 | radeon_bo_unreserve(work->new_rbo); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 415 | r = -EINVAL; |
| 416 | DRM_ERROR("failed to pin new rbo buffer before flip\n"); |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 417 | goto cleanup; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 418 | } |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 419 | radeon_bo_get_tiling_flags(work->new_rbo, &tiling_flags, NULL); |
| 420 | radeon_bo_unreserve(work->new_rbo); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 421 | |
| 422 | if (!ASIC_IS_AVIVO(rdev)) { |
| 423 | /* crtc offset is from display base addr not FB location */ |
| 424 | base -= radeon_crtc->legacy_display_base_addr; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 425 | pitch_pixels = fb->pitches[0] / (fb->bits_per_pixel / 8); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 426 | |
| 427 | if (tiling_flags & RADEON_TILING_MACRO) { |
| 428 | if (ASIC_IS_R300(rdev)) { |
| 429 | base &= ~0x7ff; |
| 430 | } else { |
| 431 | int byteshift = fb->bits_per_pixel >> 4; |
| 432 | int tile_addr = (((crtc->y >> 3) * pitch_pixels + crtc->x) >> (8 - byteshift)) << 11; |
| 433 | base += tile_addr + ((crtc->x << byteshift) % 256) + ((crtc->y % 8) << 8); |
| 434 | } |
| 435 | } else { |
| 436 | int offset = crtc->y * pitch_pixels + crtc->x; |
| 437 | switch (fb->bits_per_pixel) { |
| 438 | case 8: |
| 439 | default: |
| 440 | offset *= 1; |
| 441 | break; |
| 442 | case 15: |
| 443 | case 16: |
| 444 | offset *= 2; |
| 445 | break; |
| 446 | case 24: |
| 447 | offset *= 3; |
| 448 | break; |
| 449 | case 32: |
| 450 | offset *= 4; |
| 451 | break; |
| 452 | } |
| 453 | base += offset; |
| 454 | } |
| 455 | base &= ~7; |
| 456 | } |
| 457 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 458 | /* We borrow the event spin lock for protecting flip_work */ |
| 459 | spin_lock_irqsave(&crtc->dev->event_lock, flags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 460 | |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 461 | /* set the proper interrupt */ |
Christian König | e928c61 | 2014-05-27 16:49:18 +0200 | [diff] [blame] | 462 | radeon_irq_kms_pflip_irq_get(rdev, radeon_crtc->crtc_id); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 463 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 464 | /* do the flip (mmio) */ |
| 465 | radeon_page_flip(rdev, radeon_crtc->crtc_id, base); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 466 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 467 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); |
| 468 | up_read(&rdev->exclusive_lock); |
| 469 | |
| 470 | return; |
| 471 | |
| 472 | cleanup: |
| 473 | drm_gem_object_unreference_unlocked(&work->old_rbo->gem_base); |
Michel Dänzer | fcc485d | 2011-07-13 15:18:09 +0000 | [diff] [blame] | 474 | radeon_fence_unref(&work->fence); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 475 | kfree(work); |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 476 | up_read(&rdev->exclusive_lock); |
| 477 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 478 | |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 479 | static int radeon_crtc_page_flip(struct drm_crtc *crtc, |
| 480 | struct drm_framebuffer *fb, |
| 481 | struct drm_pending_vblank_event *event, |
| 482 | uint32_t page_flip_flags) |
| 483 | { |
| 484 | struct drm_device *dev = crtc->dev; |
| 485 | struct radeon_device *rdev = dev->dev_private; |
| 486 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 487 | struct radeon_framebuffer *old_radeon_fb; |
| 488 | struct radeon_framebuffer *new_radeon_fb; |
| 489 | struct drm_gem_object *obj; |
| 490 | struct radeon_flip_work *work; |
| 491 | unsigned long flags; |
| 492 | |
| 493 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 494 | if (work == NULL) |
| 495 | return -ENOMEM; |
| 496 | |
| 497 | INIT_WORK(&work->flip_work, radeon_flip_work_func); |
| 498 | INIT_WORK(&work->unpin_work, radeon_unpin_work_func); |
| 499 | |
| 500 | work->rdev = rdev; |
| 501 | work->crtc_id = radeon_crtc->crtc_id; |
| 502 | work->fb = fb; |
| 503 | work->event = event; |
| 504 | |
| 505 | /* schedule unpin of the old buffer */ |
| 506 | old_radeon_fb = to_radeon_framebuffer(crtc->primary->fb); |
| 507 | obj = old_radeon_fb->obj; |
| 508 | |
| 509 | /* take a reference to the old object */ |
| 510 | drm_gem_object_reference(obj); |
| 511 | work->old_rbo = gem_to_radeon_bo(obj); |
| 512 | |
| 513 | new_radeon_fb = to_radeon_framebuffer(fb); |
| 514 | obj = new_radeon_fb->obj; |
| 515 | work->new_rbo = gem_to_radeon_bo(obj); |
| 516 | |
| 517 | spin_lock(&work->new_rbo->tbo.bdev->fence_lock); |
| 518 | if (work->new_rbo->tbo.sync_obj) |
| 519 | work->fence = radeon_fence_ref(work->new_rbo->tbo.sync_obj); |
| 520 | spin_unlock(&work->new_rbo->tbo.bdev->fence_lock); |
| 521 | |
| 522 | /* update crtc fb */ |
| 523 | crtc->primary->fb = fb; |
| 524 | |
| 525 | /* We borrow the event spin lock for protecting flip_work */ |
| 526 | spin_lock_irqsave(&crtc->dev->event_lock, flags); |
| 527 | |
| 528 | if (radeon_crtc->flip_work) { |
| 529 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
| 530 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); |
| 531 | drm_gem_object_unreference_unlocked(&work->old_rbo->gem_base); |
| 532 | radeon_fence_unref(&work->fence); |
| 533 | kfree(work); |
| 534 | return -EBUSY; |
| 535 | } |
| 536 | radeon_crtc->flip_work = work; |
| 537 | |
| 538 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); |
| 539 | |
| 540 | queue_work(radeon_crtc->flip_queue, &work->flip_work); |
| 541 | |
| 542 | return 0; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 543 | } |
| 544 | |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 545 | static int |
| 546 | radeon_crtc_set_config(struct drm_mode_set *set) |
| 547 | { |
| 548 | struct drm_device *dev; |
| 549 | struct radeon_device *rdev; |
| 550 | struct drm_crtc *crtc; |
| 551 | bool active = false; |
| 552 | int ret; |
| 553 | |
| 554 | if (!set || !set->crtc) |
| 555 | return -EINVAL; |
| 556 | |
| 557 | dev = set->crtc->dev; |
| 558 | |
| 559 | ret = pm_runtime_get_sync(dev->dev); |
| 560 | if (ret < 0) |
| 561 | return ret; |
| 562 | |
| 563 | ret = drm_crtc_helper_set_config(set); |
| 564 | |
| 565 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 566 | if (crtc->enabled) |
| 567 | active = true; |
| 568 | |
| 569 | pm_runtime_mark_last_busy(dev->dev); |
| 570 | |
| 571 | rdev = dev->dev_private; |
| 572 | /* if we have active crtcs and we don't have a power ref, |
| 573 | take the current one */ |
| 574 | if (active && !rdev->have_disp_power_ref) { |
| 575 | rdev->have_disp_power_ref = true; |
| 576 | return ret; |
| 577 | } |
| 578 | /* if we have no active crtcs, then drop the power ref |
| 579 | we got before */ |
| 580 | if (!active && rdev->have_disp_power_ref) { |
| 581 | pm_runtime_put_autosuspend(dev->dev); |
| 582 | rdev->have_disp_power_ref = false; |
| 583 | } |
| 584 | |
| 585 | /* drop the power reference we got coming in here */ |
| 586 | pm_runtime_put_autosuspend(dev->dev); |
| 587 | return ret; |
| 588 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 589 | static const struct drm_crtc_funcs radeon_crtc_funcs = { |
| 590 | .cursor_set = radeon_crtc_cursor_set, |
| 591 | .cursor_move = radeon_crtc_cursor_move, |
| 592 | .gamma_set = radeon_crtc_gamma_set, |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 593 | .set_config = radeon_crtc_set_config, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 594 | .destroy = radeon_crtc_destroy, |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 595 | .page_flip = radeon_crtc_page_flip, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 596 | }; |
| 597 | |
| 598 | static void radeon_crtc_init(struct drm_device *dev, int index) |
| 599 | { |
| 600 | struct radeon_device *rdev = dev->dev_private; |
| 601 | struct radeon_crtc *radeon_crtc; |
| 602 | int i; |
| 603 | |
| 604 | radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
| 605 | if (radeon_crtc == NULL) |
| 606 | return; |
| 607 | |
| 608 | drm_crtc_init(dev, &radeon_crtc->base, &radeon_crtc_funcs); |
| 609 | |
| 610 | drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256); |
| 611 | radeon_crtc->crtc_id = index; |
Christian König | 1aab551 | 2014-05-27 16:49:22 +0200 | [diff] [blame^] | 612 | radeon_crtc->flip_queue = create_singlethread_workqueue("radeon-crtc"); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 613 | rdev->mode_info.crtcs[index] = radeon_crtc; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 614 | |
Alex Deucher | 9e05fa1 | 2013-01-24 10:06:33 -0500 | [diff] [blame] | 615 | if (rdev->family >= CHIP_BONAIRE) { |
| 616 | radeon_crtc->max_cursor_width = CIK_CURSOR_WIDTH; |
| 617 | radeon_crtc->max_cursor_height = CIK_CURSOR_HEIGHT; |
| 618 | } else { |
| 619 | radeon_crtc->max_cursor_width = CURSOR_WIDTH; |
| 620 | radeon_crtc->max_cursor_height = CURSOR_HEIGHT; |
| 621 | } |
Alex Deucher | bea61c5 | 2014-02-12 12:56:53 -0500 | [diff] [blame] | 622 | dev->mode_config.cursor_width = radeon_crtc->max_cursor_width; |
| 623 | dev->mode_config.cursor_height = radeon_crtc->max_cursor_height; |
Alex Deucher | 9e05fa1 | 2013-01-24 10:06:33 -0500 | [diff] [blame] | 624 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 625 | #if 0 |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 626 | radeon_crtc->mode_set.crtc = &radeon_crtc->base; |
| 627 | radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1); |
| 628 | radeon_crtc->mode_set.num_connectors = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 629 | #endif |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 630 | |
| 631 | for (i = 0; i < 256; i++) { |
| 632 | radeon_crtc->lut_r[i] = i << 2; |
| 633 | radeon_crtc->lut_g[i] = i << 2; |
| 634 | radeon_crtc->lut_b[i] = i << 2; |
| 635 | } |
| 636 | |
| 637 | if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)) |
| 638 | radeon_atombios_init_crtc(dev, radeon_crtc); |
| 639 | else |
| 640 | radeon_legacy_init_crtc(dev, radeon_crtc); |
| 641 | } |
| 642 | |
Alex Deucher | e68adef | 2012-09-06 14:32:06 -0400 | [diff] [blame] | 643 | static const char *encoder_names[38] = { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 644 | "NONE", |
| 645 | "INTERNAL_LVDS", |
| 646 | "INTERNAL_TMDS1", |
| 647 | "INTERNAL_TMDS2", |
| 648 | "INTERNAL_DAC1", |
| 649 | "INTERNAL_DAC2", |
| 650 | "INTERNAL_SDVOA", |
| 651 | "INTERNAL_SDVOB", |
| 652 | "SI170B", |
| 653 | "CH7303", |
| 654 | "CH7301", |
| 655 | "INTERNAL_DVO1", |
| 656 | "EXTERNAL_SDVOA", |
| 657 | "EXTERNAL_SDVOB", |
| 658 | "TITFP513", |
| 659 | "INTERNAL_LVTM1", |
| 660 | "VT1623", |
| 661 | "HDMI_SI1930", |
| 662 | "HDMI_INTERNAL", |
| 663 | "INTERNAL_KLDSCP_TMDS1", |
| 664 | "INTERNAL_KLDSCP_DVO1", |
| 665 | "INTERNAL_KLDSCP_DAC1", |
| 666 | "INTERNAL_KLDSCP_DAC2", |
| 667 | "SI178", |
| 668 | "MVPU_FPGA", |
| 669 | "INTERNAL_DDI", |
| 670 | "VT1625", |
| 671 | "HDMI_SI1932", |
| 672 | "DP_AN9801", |
| 673 | "DP_DP501", |
| 674 | "INTERNAL_UNIPHY", |
| 675 | "INTERNAL_KLDSCP_LVTMA", |
| 676 | "INTERNAL_UNIPHY1", |
| 677 | "INTERNAL_UNIPHY2", |
Alex Deucher | bf982eb | 2010-11-22 17:56:24 -0500 | [diff] [blame] | 678 | "NUTMEG", |
| 679 | "TRAVIS", |
Alex Deucher | e68adef | 2012-09-06 14:32:06 -0400 | [diff] [blame] | 680 | "INTERNAL_VCE", |
| 681 | "INTERNAL_UNIPHY3", |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 682 | }; |
| 683 | |
Alex Deucher | cbd4623 | 2010-06-07 02:24:54 -0400 | [diff] [blame] | 684 | static const char *hpd_names[6] = { |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 685 | "HPD1", |
| 686 | "HPD2", |
| 687 | "HPD3", |
| 688 | "HPD4", |
| 689 | "HPD5", |
| 690 | "HPD6", |
| 691 | }; |
| 692 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 693 | static void radeon_print_display_setup(struct drm_device *dev) |
| 694 | { |
| 695 | struct drm_connector *connector; |
| 696 | struct radeon_connector *radeon_connector; |
| 697 | struct drm_encoder *encoder; |
| 698 | struct radeon_encoder *radeon_encoder; |
| 699 | uint32_t devices; |
| 700 | int i = 0; |
| 701 | |
| 702 | DRM_INFO("Radeon Display Connectors\n"); |
| 703 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 704 | radeon_connector = to_radeon_connector(connector); |
| 705 | DRM_INFO("Connector %d:\n", i); |
Ilija Hadzic | c1d2dbd | 2012-05-04 11:25:12 -0400 | [diff] [blame] | 706 | DRM_INFO(" %s\n", drm_get_connector_name(connector)); |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 707 | if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) |
| 708 | DRM_INFO(" %s\n", hpd_names[radeon_connector->hpd.hpd]); |
Dave Airlie | 4b9d2a2 | 2010-02-08 13:16:55 +1000 | [diff] [blame] | 709 | if (radeon_connector->ddc_bus) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 710 | DRM_INFO(" DDC: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
| 711 | radeon_connector->ddc_bus->rec.mask_clk_reg, |
| 712 | radeon_connector->ddc_bus->rec.mask_data_reg, |
| 713 | radeon_connector->ddc_bus->rec.a_clk_reg, |
| 714 | radeon_connector->ddc_bus->rec.a_data_reg, |
Alex Deucher | 9b9fe72 | 2009-11-10 15:59:44 -0500 | [diff] [blame] | 715 | radeon_connector->ddc_bus->rec.en_clk_reg, |
| 716 | radeon_connector->ddc_bus->rec.en_data_reg, |
| 717 | radeon_connector->ddc_bus->rec.y_clk_reg, |
| 718 | radeon_connector->ddc_bus->rec.y_data_reg); |
Alex Deucher | fb939df | 2010-11-08 16:08:29 +0000 | [diff] [blame] | 719 | if (radeon_connector->router.ddc_valid) |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 720 | DRM_INFO(" DDC Router 0x%x/0x%x\n", |
Alex Deucher | fb939df | 2010-11-08 16:08:29 +0000 | [diff] [blame] | 721 | radeon_connector->router.ddc_mux_control_pin, |
| 722 | radeon_connector->router.ddc_mux_state); |
| 723 | if (radeon_connector->router.cd_valid) |
| 724 | DRM_INFO(" Clock/Data Router 0x%x/0x%x\n", |
| 725 | radeon_connector->router.cd_mux_control_pin, |
| 726 | radeon_connector->router.cd_mux_state); |
Dave Airlie | 4b9d2a2 | 2010-02-08 13:16:55 +1000 | [diff] [blame] | 727 | } else { |
| 728 | if (connector->connector_type == DRM_MODE_CONNECTOR_VGA || |
| 729 | connector->connector_type == DRM_MODE_CONNECTOR_DVII || |
| 730 | connector->connector_type == DRM_MODE_CONNECTOR_DVID || |
| 731 | connector->connector_type == DRM_MODE_CONNECTOR_DVIA || |
| 732 | connector->connector_type == DRM_MODE_CONNECTOR_HDMIA || |
| 733 | connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) |
| 734 | DRM_INFO(" DDC: no ddc bus - possible BIOS bug - please report to xorg-driver-ati@lists.x.org\n"); |
| 735 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 736 | DRM_INFO(" Encoders:\n"); |
| 737 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 738 | radeon_encoder = to_radeon_encoder(encoder); |
| 739 | devices = radeon_encoder->devices & radeon_connector->devices; |
| 740 | if (devices) { |
| 741 | if (devices & ATOM_DEVICE_CRT1_SUPPORT) |
| 742 | DRM_INFO(" CRT1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 743 | if (devices & ATOM_DEVICE_CRT2_SUPPORT) |
| 744 | DRM_INFO(" CRT2: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 745 | if (devices & ATOM_DEVICE_LCD1_SUPPORT) |
| 746 | DRM_INFO(" LCD1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 747 | if (devices & ATOM_DEVICE_DFP1_SUPPORT) |
| 748 | DRM_INFO(" DFP1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 749 | if (devices & ATOM_DEVICE_DFP2_SUPPORT) |
| 750 | DRM_INFO(" DFP2: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 751 | if (devices & ATOM_DEVICE_DFP3_SUPPORT) |
| 752 | DRM_INFO(" DFP3: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 753 | if (devices & ATOM_DEVICE_DFP4_SUPPORT) |
| 754 | DRM_INFO(" DFP4: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 755 | if (devices & ATOM_DEVICE_DFP5_SUPPORT) |
| 756 | DRM_INFO(" DFP5: %s\n", encoder_names[radeon_encoder->encoder_id]); |
Alex Deucher | 73758a5 | 2010-09-24 14:59:32 -0400 | [diff] [blame] | 757 | if (devices & ATOM_DEVICE_DFP6_SUPPORT) |
| 758 | DRM_INFO(" DFP6: %s\n", encoder_names[radeon_encoder->encoder_id]); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 759 | if (devices & ATOM_DEVICE_TV1_SUPPORT) |
| 760 | DRM_INFO(" TV1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 761 | if (devices & ATOM_DEVICE_CV_SUPPORT) |
| 762 | DRM_INFO(" CV: %s\n", encoder_names[radeon_encoder->encoder_id]); |
| 763 | } |
| 764 | } |
| 765 | i++; |
| 766 | } |
| 767 | } |
| 768 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 769 | static bool radeon_setup_enc_conn(struct drm_device *dev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 770 | { |
| 771 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 772 | bool ret = false; |
| 773 | |
| 774 | if (rdev->bios) { |
| 775 | if (rdev->is_atom_bios) { |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 776 | ret = radeon_get_atom_connector_info_from_supported_devices_table(dev); |
| 777 | if (ret == false) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 778 | ret = radeon_get_atom_connector_info_from_object_table(dev); |
Alex Deucher | b9597a1 | 2010-01-04 19:12:02 -0500 | [diff] [blame] | 779 | } else { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 780 | ret = radeon_get_legacy_connector_info_from_bios(dev); |
Alex Deucher | b9597a1 | 2010-01-04 19:12:02 -0500 | [diff] [blame] | 781 | if (ret == false) |
| 782 | ret = radeon_get_legacy_connector_info_from_table(dev); |
| 783 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 784 | } else { |
| 785 | if (!ASIC_IS_AVIVO(rdev)) |
| 786 | ret = radeon_get_legacy_connector_info_from_table(dev); |
| 787 | } |
| 788 | if (ret) { |
Dave Airlie | 1f3b6a4 | 2009-10-13 14:10:37 +1000 | [diff] [blame] | 789 | radeon_setup_encoder_clones(dev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 790 | radeon_print_display_setup(dev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | return ret; |
| 794 | } |
| 795 | |
| 796 | int radeon_ddc_get_modes(struct radeon_connector *radeon_connector) |
| 797 | { |
Alex Deucher | 3c53788 | 2010-02-05 04:21:19 -0500 | [diff] [blame] | 798 | struct drm_device *dev = radeon_connector->base.dev; |
| 799 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 800 | int ret = 0; |
| 801 | |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 802 | /* on hw with routers, select right port */ |
Alex Deucher | fb939df | 2010-11-08 16:08:29 +0000 | [diff] [blame] | 803 | if (radeon_connector->router.ddc_valid) |
| 804 | radeon_router_select_ddc_port(radeon_connector); |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 805 | |
Niels Ole Salscheider | 0a9069d | 2013-01-03 19:09:28 +0100 | [diff] [blame] | 806 | if (radeon_connector_encoder_get_dp_bridge_encoder_id(&radeon_connector->base) != |
| 807 | ENCODER_OBJECT_ID_NONE) { |
Alex Deucher | 379dfc2 | 2014-04-07 10:33:46 -0400 | [diff] [blame] | 808 | if (radeon_connector->ddc_bus->has_aux) |
Niels Ole Salscheider | 0a9069d | 2013-01-03 19:09:28 +0100 | [diff] [blame] | 809 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, |
Alex Deucher | 379dfc2 | 2014-04-07 10:33:46 -0400 | [diff] [blame] | 810 | &radeon_connector->ddc_bus->aux.ddc); |
Niels Ole Salscheider | 0a9069d | 2013-01-03 19:09:28 +0100 | [diff] [blame] | 811 | } else if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) || |
| 812 | (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) { |
Dave Airlie | 746c1aa | 2009-12-08 07:07:28 +1000 | [diff] [blame] | 813 | struct radeon_connector_atom_dig *dig = radeon_connector->con_priv; |
Alex Deucher | b06947b | 2011-09-02 14:23:09 +0000 | [diff] [blame] | 814 | |
Dave Airlie | 7a15cbd4 | 2010-01-14 11:42:17 +1000 | [diff] [blame] | 815 | if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT || |
Alex Deucher | 379dfc2 | 2014-04-07 10:33:46 -0400 | [diff] [blame] | 816 | dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) && |
| 817 | radeon_connector->ddc_bus->has_aux) |
Alex Deucher | b06947b | 2011-09-02 14:23:09 +0000 | [diff] [blame] | 818 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, |
Alex Deucher | 379dfc2 | 2014-04-07 10:33:46 -0400 | [diff] [blame] | 819 | &radeon_connector->ddc_bus->aux.ddc); |
Alex Deucher | b06947b | 2011-09-02 14:23:09 +0000 | [diff] [blame] | 820 | else if (radeon_connector->ddc_bus && !radeon_connector->edid) |
| 821 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, |
| 822 | &radeon_connector->ddc_bus->adapter); |
| 823 | } else { |
| 824 | if (radeon_connector->ddc_bus && !radeon_connector->edid) |
| 825 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, |
| 826 | &radeon_connector->ddc_bus->adapter); |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 827 | } |
Alex Deucher | c324acd | 2010-12-08 22:13:06 -0500 | [diff] [blame] | 828 | |
| 829 | if (!radeon_connector->edid) { |
| 830 | if (rdev->is_atom_bios) { |
| 831 | /* some laptops provide a hardcoded edid in rom for LCDs */ |
| 832 | if (((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_LVDS) || |
| 833 | (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP))) |
| 834 | radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev); |
| 835 | } else |
| 836 | /* some servers provide a hardcoded edid in rom for KVMs */ |
| 837 | radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev); |
| 838 | } |
Alex Deucher | 0294cf4f | 2009-10-15 16:16:35 -0400 | [diff] [blame] | 839 | if (radeon_connector->edid) { |
| 840 | drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid); |
| 841 | ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid); |
Alex Deucher | 1608627 | 2014-03-31 11:19:46 -0400 | [diff] [blame] | 842 | drm_edid_to_eld(&radeon_connector->base, radeon_connector->edid); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 843 | return ret; |
| 844 | } |
| 845 | drm_mode_connector_update_edid_property(&radeon_connector->base, NULL); |
Dave Airlie | 42dea5d | 2009-09-15 20:21:11 +1000 | [diff] [blame] | 846 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 847 | } |
| 848 | |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 849 | /* avivo */ |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 850 | |
| 851 | /** |
| 852 | * avivo_reduce_ratio - fractional number reduction |
| 853 | * |
| 854 | * @nom: nominator |
| 855 | * @den: denominator |
| 856 | * @nom_min: minimum value for nominator |
| 857 | * @den_min: minimum value for denominator |
| 858 | * |
| 859 | * Find the greatest common divisor and apply it on both nominator and |
| 860 | * denominator, but make nominator and denominator are at least as large |
| 861 | * as their minimum values. |
| 862 | */ |
| 863 | static void avivo_reduce_ratio(unsigned *nom, unsigned *den, |
| 864 | unsigned nom_min, unsigned den_min) |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 865 | { |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 866 | unsigned tmp; |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 867 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 868 | /* reduce the numbers to a simpler ratio */ |
| 869 | tmp = gcd(*nom, *den); |
| 870 | *nom /= tmp; |
| 871 | *den /= tmp; |
Alex Deucher | a4b40d5d | 2011-02-14 11:43:10 -0500 | [diff] [blame] | 872 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 873 | /* make sure nominator is large enough */ |
| 874 | if (*nom < nom_min) { |
| 875 | tmp = (nom_min + *nom - 1) / *nom; |
| 876 | *nom *= tmp; |
| 877 | *den *= tmp; |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 878 | } |
| 879 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 880 | /* make sure the denominator is large enough */ |
| 881 | if (*den < den_min) { |
| 882 | tmp = (den_min + *den - 1) / *den; |
| 883 | *nom *= tmp; |
| 884 | *den *= tmp; |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 885 | } |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 886 | } |
| 887 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 888 | /** |
Christian König | c2fb309 | 2014-04-20 13:24:32 +0200 | [diff] [blame] | 889 | * avivo_get_fb_ref_div - feedback and ref divider calculation |
| 890 | * |
| 891 | * @nom: nominator |
| 892 | * @den: denominator |
| 893 | * @post_div: post divider |
| 894 | * @fb_div_max: feedback divider maximum |
| 895 | * @ref_div_max: reference divider maximum |
| 896 | * @fb_div: resulting feedback divider |
| 897 | * @ref_div: resulting reference divider |
| 898 | * |
| 899 | * Calculate feedback and reference divider for a given post divider. Makes |
| 900 | * sure we stay within the limits. |
| 901 | */ |
| 902 | static void avivo_get_fb_ref_div(unsigned nom, unsigned den, unsigned post_div, |
| 903 | unsigned fb_div_max, unsigned ref_div_max, |
| 904 | unsigned *fb_div, unsigned *ref_div) |
| 905 | { |
| 906 | /* limit reference * post divider to a maximum */ |
| 907 | ref_div_max = min(210 / post_div, ref_div_max); |
| 908 | |
| 909 | /* get matching reference and feedback divider */ |
| 910 | *ref_div = min(max(DIV_ROUND_CLOSEST(den, post_div), 1u), ref_div_max); |
| 911 | *fb_div = DIV_ROUND_CLOSEST(nom * *ref_div * post_div, den); |
| 912 | |
| 913 | /* limit fb divider to its maximum */ |
| 914 | if (*fb_div > fb_div_max) { |
| 915 | *ref_div = DIV_ROUND_CLOSEST(*ref_div * fb_div_max, *fb_div); |
| 916 | *fb_div = fb_div_max; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | /** |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 921 | * radeon_compute_pll_avivo - compute PLL paramaters |
| 922 | * |
| 923 | * @pll: information about the PLL |
| 924 | * @dot_clock_p: resulting pixel clock |
| 925 | * fb_div_p: resulting feedback divider |
| 926 | * frac_fb_div_p: fractional part of the feedback divider |
| 927 | * ref_div_p: resulting reference divider |
| 928 | * post_div_p: resulting reference divider |
| 929 | * |
| 930 | * Try to calculate the PLL parameters to generate the given frequency: |
| 931 | * dot_clock = (ref_freq * feedback_div) / (ref_div * post_div) |
| 932 | */ |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 933 | void radeon_compute_pll_avivo(struct radeon_pll *pll, |
| 934 | u32 freq, |
| 935 | u32 *dot_clock_p, |
| 936 | u32 *fb_div_p, |
| 937 | u32 *frac_fb_div_p, |
| 938 | u32 *ref_div_p, |
| 939 | u32 *post_div_p) |
| 940 | { |
Christian König | c2fb309 | 2014-04-20 13:24:32 +0200 | [diff] [blame] | 941 | unsigned target_clock = pll->flags & RADEON_PLL_USE_FRAC_FB_DIV ? |
| 942 | freq : freq / 10; |
| 943 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 944 | unsigned fb_div_min, fb_div_max, fb_div; |
| 945 | unsigned post_div_min, post_div_max, post_div; |
| 946 | unsigned ref_div_min, ref_div_max, ref_div; |
| 947 | unsigned post_div_best, diff_best; |
Christian König | f8a2645e | 2014-04-16 11:54:21 +0200 | [diff] [blame] | 948 | unsigned nom, den; |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 949 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 950 | /* determine allowed feedback divider range */ |
| 951 | fb_div_min = pll->min_feedback_div; |
| 952 | fb_div_max = pll->max_feedback_div; |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 953 | |
| 954 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 955 | fb_div_min *= 10; |
| 956 | fb_div_max *= 10; |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 957 | } |
| 958 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 959 | /* determine allowed ref divider range */ |
| 960 | if (pll->flags & RADEON_PLL_USE_REF_DIV) |
| 961 | ref_div_min = pll->reference_div; |
| 962 | else |
| 963 | ref_div_min = pll->min_ref_div; |
Christian König | 2431581 | 2014-04-19 18:57:14 +0200 | [diff] [blame] | 964 | |
| 965 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV && |
| 966 | pll->flags & RADEON_PLL_USE_REF_DIV) |
| 967 | ref_div_max = pll->reference_div; |
| 968 | else |
| 969 | ref_div_max = pll->max_ref_div; |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 970 | |
| 971 | /* determine allowed post divider range */ |
| 972 | if (pll->flags & RADEON_PLL_USE_POST_DIV) { |
| 973 | post_div_min = pll->post_div; |
| 974 | post_div_max = pll->post_div; |
| 975 | } else { |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 976 | unsigned vco_min, vco_max; |
| 977 | |
| 978 | if (pll->flags & RADEON_PLL_IS_LCD) { |
| 979 | vco_min = pll->lcd_pll_out_min; |
| 980 | vco_max = pll->lcd_pll_out_max; |
| 981 | } else { |
| 982 | vco_min = pll->pll_out_min; |
| 983 | vco_max = pll->pll_out_max; |
| 984 | } |
| 985 | |
Christian König | c2fb309 | 2014-04-20 13:24:32 +0200 | [diff] [blame] | 986 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
| 987 | vco_min *= 10; |
| 988 | vco_max *= 10; |
| 989 | } |
| 990 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 991 | post_div_min = vco_min / target_clock; |
| 992 | if ((target_clock * post_div_min) < vco_min) |
| 993 | ++post_div_min; |
| 994 | if (post_div_min < pll->min_post_div) |
| 995 | post_div_min = pll->min_post_div; |
| 996 | |
| 997 | post_div_max = vco_max / target_clock; |
| 998 | if ((target_clock * post_div_max) > vco_max) |
| 999 | --post_div_max; |
| 1000 | if (post_div_max > pll->max_post_div) |
| 1001 | post_div_max = pll->max_post_div; |
| 1002 | } |
| 1003 | |
| 1004 | /* represent the searched ratio as fractional number */ |
Christian König | c2fb309 | 2014-04-20 13:24:32 +0200 | [diff] [blame] | 1005 | nom = target_clock; |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 1006 | den = pll->reference_freq; |
| 1007 | |
| 1008 | /* reduce the numbers to a simpler ratio */ |
| 1009 | avivo_reduce_ratio(&nom, &den, fb_div_min, post_div_min); |
| 1010 | |
| 1011 | /* now search for a post divider */ |
| 1012 | if (pll->flags & RADEON_PLL_PREFER_MINM_OVER_MAXP) |
| 1013 | post_div_best = post_div_min; |
| 1014 | else |
| 1015 | post_div_best = post_div_max; |
| 1016 | diff_best = ~0; |
| 1017 | |
| 1018 | for (post_div = post_div_min; post_div <= post_div_max; ++post_div) { |
Christian König | c2fb309 | 2014-04-20 13:24:32 +0200 | [diff] [blame] | 1019 | unsigned diff; |
| 1020 | avivo_get_fb_ref_div(nom, den, post_div, fb_div_max, |
| 1021 | ref_div_max, &fb_div, &ref_div); |
| 1022 | diff = abs(target_clock - (pll->reference_freq * fb_div) / |
| 1023 | (ref_div * post_div)); |
| 1024 | |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 1025 | if (diff < diff_best || (diff == diff_best && |
| 1026 | !(pll->flags & RADEON_PLL_PREFER_MINM_OVER_MAXP))) { |
| 1027 | |
| 1028 | post_div_best = post_div; |
| 1029 | diff_best = diff; |
| 1030 | } |
| 1031 | } |
| 1032 | post_div = post_div_best; |
| 1033 | |
Christian König | c2fb309 | 2014-04-20 13:24:32 +0200 | [diff] [blame] | 1034 | /* get the feedback and reference divider for the optimal value */ |
| 1035 | avivo_get_fb_ref_div(nom, den, post_div, fb_div_max, ref_div_max, |
| 1036 | &fb_div, &ref_div); |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 1037 | |
| 1038 | /* reduce the numbers to a simpler ratio once more */ |
| 1039 | /* this also makes sure that the reference divider is large enough */ |
| 1040 | avivo_reduce_ratio(&fb_div, &ref_div, fb_div_min, ref_div_min); |
| 1041 | |
| 1042 | /* and finally save the result */ |
| 1043 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
| 1044 | *fb_div_p = fb_div / 10; |
| 1045 | *frac_fb_div_p = fb_div % 10; |
| 1046 | } else { |
| 1047 | *fb_div_p = fb_div; |
| 1048 | *frac_fb_div_p = 0; |
| 1049 | } |
| 1050 | |
| 1051 | *dot_clock_p = ((pll->reference_freq * *fb_div_p * 10) + |
| 1052 | (pll->reference_freq * *frac_fb_div_p)) / |
| 1053 | (ref_div * post_div * 10); |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 1054 | *ref_div_p = ref_div; |
| 1055 | *post_div_p = post_div; |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 1056 | |
| 1057 | DRM_DEBUG_KMS("%d - %d, pll dividers - fb: %d.%d ref: %d, post %d\n", |
Christian König | c2fb309 | 2014-04-20 13:24:32 +0200 | [diff] [blame] | 1058 | freq, *dot_clock_p * 10, *fb_div_p, *frac_fb_div_p, |
Christian König | 3216701 | 2014-03-28 18:55:10 +0100 | [diff] [blame] | 1059 | ref_div, post_div); |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | /* pre-avivo */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1063 | static inline uint32_t radeon_div(uint64_t n, uint32_t d) |
| 1064 | { |
| 1065 | uint64_t mod; |
| 1066 | |
| 1067 | n += d / 2; |
| 1068 | |
| 1069 | mod = do_div(n, d); |
| 1070 | return n; |
| 1071 | } |
| 1072 | |
Alex Deucher | f523f74 | 2011-01-31 16:48:52 -0500 | [diff] [blame] | 1073 | void radeon_compute_pll_legacy(struct radeon_pll *pll, |
| 1074 | uint64_t freq, |
| 1075 | uint32_t *dot_clock_p, |
| 1076 | uint32_t *fb_div_p, |
| 1077 | uint32_t *frac_fb_div_p, |
| 1078 | uint32_t *ref_div_p, |
| 1079 | uint32_t *post_div_p) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1080 | { |
| 1081 | uint32_t min_ref_div = pll->min_ref_div; |
| 1082 | uint32_t max_ref_div = pll->max_ref_div; |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 1083 | uint32_t min_post_div = pll->min_post_div; |
| 1084 | uint32_t max_post_div = pll->max_post_div; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1085 | uint32_t min_fractional_feed_div = 0; |
| 1086 | uint32_t max_fractional_feed_div = 0; |
| 1087 | uint32_t best_vco = pll->best_vco; |
| 1088 | uint32_t best_post_div = 1; |
| 1089 | uint32_t best_ref_div = 1; |
| 1090 | uint32_t best_feedback_div = 1; |
| 1091 | uint32_t best_frac_feedback_div = 0; |
| 1092 | uint32_t best_freq = -1; |
| 1093 | uint32_t best_error = 0xffffffff; |
| 1094 | uint32_t best_vco_diff = 1; |
| 1095 | uint32_t post_div; |
Alex Deucher | 86cb2bb | 2010-03-08 12:55:16 -0500 | [diff] [blame] | 1096 | u32 pll_out_min, pll_out_max; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1097 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1098 | DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1099 | freq = freq * 1000; |
| 1100 | |
Alex Deucher | 86cb2bb | 2010-03-08 12:55:16 -0500 | [diff] [blame] | 1101 | if (pll->flags & RADEON_PLL_IS_LCD) { |
| 1102 | pll_out_min = pll->lcd_pll_out_min; |
| 1103 | pll_out_max = pll->lcd_pll_out_max; |
| 1104 | } else { |
| 1105 | pll_out_min = pll->pll_out_min; |
| 1106 | pll_out_max = pll->pll_out_max; |
| 1107 | } |
| 1108 | |
Alex Deucher | 619efb1 | 2011-01-31 16:48:53 -0500 | [diff] [blame] | 1109 | if (pll_out_min > 64800) |
| 1110 | pll_out_min = 64800; |
| 1111 | |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 1112 | if (pll->flags & RADEON_PLL_USE_REF_DIV) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1113 | min_ref_div = max_ref_div = pll->reference_div; |
| 1114 | else { |
| 1115 | while (min_ref_div < max_ref_div-1) { |
| 1116 | uint32_t mid = (min_ref_div + max_ref_div) / 2; |
| 1117 | uint32_t pll_in = pll->reference_freq / mid; |
| 1118 | if (pll_in < pll->pll_in_min) |
| 1119 | max_ref_div = mid; |
| 1120 | else if (pll_in > pll->pll_in_max) |
| 1121 | min_ref_div = mid; |
| 1122 | else |
| 1123 | break; |
| 1124 | } |
| 1125 | } |
| 1126 | |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 1127 | if (pll->flags & RADEON_PLL_USE_POST_DIV) |
| 1128 | min_post_div = max_post_div = pll->post_div; |
| 1129 | |
| 1130 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1131 | min_fractional_feed_div = pll->min_frac_feedback_div; |
| 1132 | max_fractional_feed_div = pll->max_frac_feedback_div; |
| 1133 | } |
| 1134 | |
Alex Deucher | bd6a60a | 2011-02-21 01:11:59 -0500 | [diff] [blame] | 1135 | for (post_div = max_post_div; post_div >= min_post_div; --post_div) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1136 | uint32_t ref_div; |
| 1137 | |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 1138 | if ((pll->flags & RADEON_PLL_NO_ODD_POST_DIV) && (post_div & 1)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1139 | continue; |
| 1140 | |
| 1141 | /* legacy radeons only have a few post_divs */ |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 1142 | if (pll->flags & RADEON_PLL_LEGACY) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1143 | if ((post_div == 5) || |
| 1144 | (post_div == 7) || |
| 1145 | (post_div == 9) || |
| 1146 | (post_div == 10) || |
| 1147 | (post_div == 11) || |
| 1148 | (post_div == 13) || |
| 1149 | (post_div == 14) || |
| 1150 | (post_div == 15)) |
| 1151 | continue; |
| 1152 | } |
| 1153 | |
| 1154 | for (ref_div = min_ref_div; ref_div <= max_ref_div; ++ref_div) { |
| 1155 | uint32_t feedback_div, current_freq = 0, error, vco_diff; |
| 1156 | uint32_t pll_in = pll->reference_freq / ref_div; |
| 1157 | uint32_t min_feed_div = pll->min_feedback_div; |
| 1158 | uint32_t max_feed_div = pll->max_feedback_div + 1; |
| 1159 | |
| 1160 | if (pll_in < pll->pll_in_min || pll_in > pll->pll_in_max) |
| 1161 | continue; |
| 1162 | |
| 1163 | while (min_feed_div < max_feed_div) { |
| 1164 | uint32_t vco; |
| 1165 | uint32_t min_frac_feed_div = min_fractional_feed_div; |
| 1166 | uint32_t max_frac_feed_div = max_fractional_feed_div + 1; |
| 1167 | uint32_t frac_feedback_div; |
| 1168 | uint64_t tmp; |
| 1169 | |
| 1170 | feedback_div = (min_feed_div + max_feed_div) / 2; |
| 1171 | |
| 1172 | tmp = (uint64_t)pll->reference_freq * feedback_div; |
| 1173 | vco = radeon_div(tmp, ref_div); |
| 1174 | |
Alex Deucher | 86cb2bb | 2010-03-08 12:55:16 -0500 | [diff] [blame] | 1175 | if (vco < pll_out_min) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1176 | min_feed_div = feedback_div + 1; |
| 1177 | continue; |
Alex Deucher | 86cb2bb | 2010-03-08 12:55:16 -0500 | [diff] [blame] | 1178 | } else if (vco > pll_out_max) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1179 | max_feed_div = feedback_div; |
| 1180 | continue; |
| 1181 | } |
| 1182 | |
| 1183 | while (min_frac_feed_div < max_frac_feed_div) { |
| 1184 | frac_feedback_div = (min_frac_feed_div + max_frac_feed_div) / 2; |
| 1185 | tmp = (uint64_t)pll->reference_freq * 10000 * feedback_div; |
| 1186 | tmp += (uint64_t)pll->reference_freq * 1000 * frac_feedback_div; |
| 1187 | current_freq = radeon_div(tmp, ref_div * post_div); |
| 1188 | |
Alex Deucher | fc10332 | 2010-01-19 17:16:10 -0500 | [diff] [blame] | 1189 | if (pll->flags & RADEON_PLL_PREFER_CLOSEST_LOWER) { |
Dan Carpenter | 167ffc4 | 2010-07-17 12:28:02 +0200 | [diff] [blame] | 1190 | if (freq < current_freq) |
| 1191 | error = 0xffffffff; |
| 1192 | else |
| 1193 | error = freq - current_freq; |
Alex Deucher | d0e275a | 2009-07-13 11:08:18 -0400 | [diff] [blame] | 1194 | } else |
| 1195 | error = abs(current_freq - freq); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1196 | vco_diff = abs(vco - best_vco); |
| 1197 | |
| 1198 | if ((best_vco == 0 && error < best_error) || |
| 1199 | (best_vco != 0 && |
Dan Carpenter | 167ffc4 | 2010-07-17 12:28:02 +0200 | [diff] [blame] | 1200 | ((best_error > 100 && error < best_error - 100) || |
Dave Airlie | 5480f72 | 2010-10-19 10:36:47 +1000 | [diff] [blame] | 1201 | (abs(error - best_error) < 100 && vco_diff < best_vco_diff)))) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1202 | best_post_div = post_div; |
| 1203 | best_ref_div = ref_div; |
| 1204 | best_feedback_div = feedback_div; |
| 1205 | best_frac_feedback_div = frac_feedback_div; |
| 1206 | best_freq = current_freq; |
| 1207 | best_error = error; |
| 1208 | best_vco_diff = vco_diff; |
Dave Airlie | 5480f72 | 2010-10-19 10:36:47 +1000 | [diff] [blame] | 1209 | } else if (current_freq == freq) { |
| 1210 | if (best_freq == -1) { |
| 1211 | best_post_div = post_div; |
| 1212 | best_ref_div = ref_div; |
| 1213 | best_feedback_div = feedback_div; |
| 1214 | best_frac_feedback_div = frac_feedback_div; |
| 1215 | best_freq = current_freq; |
| 1216 | best_error = error; |
| 1217 | best_vco_diff = vco_diff; |
| 1218 | } else if (((pll->flags & RADEON_PLL_PREFER_LOW_REF_DIV) && (ref_div < best_ref_div)) || |
| 1219 | ((pll->flags & RADEON_PLL_PREFER_HIGH_REF_DIV) && (ref_div > best_ref_div)) || |
| 1220 | ((pll->flags & RADEON_PLL_PREFER_LOW_FB_DIV) && (feedback_div < best_feedback_div)) || |
| 1221 | ((pll->flags & RADEON_PLL_PREFER_HIGH_FB_DIV) && (feedback_div > best_feedback_div)) || |
| 1222 | ((pll->flags & RADEON_PLL_PREFER_LOW_POST_DIV) && (post_div < best_post_div)) || |
| 1223 | ((pll->flags & RADEON_PLL_PREFER_HIGH_POST_DIV) && (post_div > best_post_div))) { |
| 1224 | best_post_div = post_div; |
| 1225 | best_ref_div = ref_div; |
| 1226 | best_feedback_div = feedback_div; |
| 1227 | best_frac_feedback_div = frac_feedback_div; |
| 1228 | best_freq = current_freq; |
| 1229 | best_error = error; |
| 1230 | best_vco_diff = vco_diff; |
| 1231 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1232 | } |
| 1233 | if (current_freq < freq) |
| 1234 | min_frac_feed_div = frac_feedback_div + 1; |
| 1235 | else |
| 1236 | max_frac_feed_div = frac_feedback_div; |
| 1237 | } |
| 1238 | if (current_freq < freq) |
| 1239 | min_feed_div = feedback_div + 1; |
| 1240 | else |
| 1241 | max_feed_div = feedback_div; |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | *dot_clock_p = best_freq / 10000; |
| 1247 | *fb_div_p = best_feedback_div; |
| 1248 | *frac_fb_div_p = best_frac_feedback_div; |
| 1249 | *ref_div_p = best_ref_div; |
| 1250 | *post_div_p = best_post_div; |
Joe Perches | bbb0aef5 | 2011-04-17 20:35:52 -0700 | [diff] [blame] | 1251 | DRM_DEBUG_KMS("%lld %d, pll dividers - fb: %d.%d ref: %d, post %d\n", |
| 1252 | (long long)freq, |
| 1253 | best_freq / 1000, best_feedback_div, best_frac_feedback_div, |
Alex Deucher | 51d4bf8 | 2011-01-31 16:48:51 -0500 | [diff] [blame] | 1254 | best_ref_div, best_post_div); |
| 1255 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 1259 | { |
| 1260 | struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1261 | |
Dave Airlie | 29d08b3 | 2010-09-27 16:17:17 +1000 | [diff] [blame] | 1262 | if (radeon_fb->obj) { |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 1263 | drm_gem_object_unreference_unlocked(radeon_fb->obj); |
Dave Airlie | 29d08b3 | 2010-09-27 16:17:17 +1000 | [diff] [blame] | 1264 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1265 | drm_framebuffer_cleanup(fb); |
| 1266 | kfree(radeon_fb); |
| 1267 | } |
| 1268 | |
| 1269 | static int radeon_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
| 1270 | struct drm_file *file_priv, |
| 1271 | unsigned int *handle) |
| 1272 | { |
| 1273 | struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); |
| 1274 | |
| 1275 | return drm_gem_handle_create(file_priv, radeon_fb->obj, handle); |
| 1276 | } |
| 1277 | |
| 1278 | static const struct drm_framebuffer_funcs radeon_fb_funcs = { |
| 1279 | .destroy = radeon_user_framebuffer_destroy, |
| 1280 | .create_handle = radeon_user_framebuffer_create_handle, |
| 1281 | }; |
| 1282 | |
Dave Airlie | aaefcd4 | 2012-03-06 10:44:40 +0000 | [diff] [blame] | 1283 | int |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1284 | radeon_framebuffer_init(struct drm_device *dev, |
| 1285 | struct radeon_framebuffer *rfb, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1286 | struct drm_mode_fb_cmd2 *mode_cmd, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1287 | struct drm_gem_object *obj) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1288 | { |
Dave Airlie | aaefcd4 | 2012-03-06 10:44:40 +0000 | [diff] [blame] | 1289 | int ret; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1290 | rfb->obj = obj; |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 1291 | drm_helper_mode_fill_fb_struct(&rfb->base, mode_cmd); |
Dave Airlie | aaefcd4 | 2012-03-06 10:44:40 +0000 | [diff] [blame] | 1292 | ret = drm_framebuffer_init(dev, &rfb->base, &radeon_fb_funcs); |
| 1293 | if (ret) { |
| 1294 | rfb->obj = NULL; |
| 1295 | return ret; |
| 1296 | } |
Dave Airlie | aaefcd4 | 2012-03-06 10:44:40 +0000 | [diff] [blame] | 1297 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static struct drm_framebuffer * |
| 1301 | radeon_user_framebuffer_create(struct drm_device *dev, |
| 1302 | struct drm_file *file_priv, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1303 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1304 | { |
| 1305 | struct drm_gem_object *obj; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1306 | struct radeon_framebuffer *radeon_fb; |
Dave Airlie | aaefcd4 | 2012-03-06 10:44:40 +0000 | [diff] [blame] | 1307 | int ret; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1308 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1309 | obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); |
Jerome Glisse | 7e71c9e | 2010-01-17 21:21:41 +0100 | [diff] [blame] | 1310 | if (obj == NULL) { |
| 1311 | dev_err(&dev->pdev->dev, "No GEM object associated to handle 0x%08X, " |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1312 | "can't create framebuffer\n", mode_cmd->handles[0]); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 1313 | return ERR_PTR(-ENOENT); |
Jerome Glisse | 7e71c9e | 2010-01-17 21:21:41 +0100 | [diff] [blame] | 1314 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1315 | |
| 1316 | radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL); |
liu chuansheng | f2d68cf | 2013-01-31 22:13:00 +0800 | [diff] [blame] | 1317 | if (radeon_fb == NULL) { |
| 1318 | drm_gem_object_unreference_unlocked(obj); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 1319 | return ERR_PTR(-ENOMEM); |
liu chuansheng | f2d68cf | 2013-01-31 22:13:00 +0800 | [diff] [blame] | 1320 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1321 | |
Dave Airlie | aaefcd4 | 2012-03-06 10:44:40 +0000 | [diff] [blame] | 1322 | ret = radeon_framebuffer_init(dev, radeon_fb, mode_cmd, obj); |
| 1323 | if (ret) { |
| 1324 | kfree(radeon_fb); |
| 1325 | drm_gem_object_unreference_unlocked(obj); |
xueminsu | b2f4b03 | 2013-01-22 22:16:53 +0800 | [diff] [blame] | 1326 | return ERR_PTR(ret); |
Dave Airlie | aaefcd4 | 2012-03-06 10:44:40 +0000 | [diff] [blame] | 1327 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1328 | |
| 1329 | return &radeon_fb->base; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1330 | } |
| 1331 | |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1332 | static void radeon_output_poll_changed(struct drm_device *dev) |
| 1333 | { |
| 1334 | struct radeon_device *rdev = dev->dev_private; |
| 1335 | radeon_fb_output_poll_changed(rdev); |
| 1336 | } |
| 1337 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1338 | static const struct drm_mode_config_funcs radeon_mode_funcs = { |
| 1339 | .fb_create = radeon_user_framebuffer_create, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1340 | .output_poll_changed = radeon_output_poll_changed |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1341 | }; |
| 1342 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1343 | static struct drm_prop_enum_list radeon_tmds_pll_enum_list[] = |
| 1344 | { { 0, "driver" }, |
| 1345 | { 1, "bios" }, |
| 1346 | }; |
| 1347 | |
| 1348 | static struct drm_prop_enum_list radeon_tv_std_enum_list[] = |
| 1349 | { { TV_STD_NTSC, "ntsc" }, |
| 1350 | { TV_STD_PAL, "pal" }, |
| 1351 | { TV_STD_PAL_M, "pal-m" }, |
| 1352 | { TV_STD_PAL_60, "pal-60" }, |
| 1353 | { TV_STD_NTSC_J, "ntsc-j" }, |
| 1354 | { TV_STD_SCART_PAL, "scart-pal" }, |
| 1355 | { TV_STD_PAL_CN, "pal-cn" }, |
| 1356 | { TV_STD_SECAM, "secam" }, |
| 1357 | }; |
| 1358 | |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1359 | static struct drm_prop_enum_list radeon_underscan_enum_list[] = |
| 1360 | { { UNDERSCAN_OFF, "off" }, |
| 1361 | { UNDERSCAN_ON, "on" }, |
| 1362 | { UNDERSCAN_AUTO, "auto" }, |
| 1363 | }; |
| 1364 | |
Alex Deucher | 8666c07 | 2013-09-03 14:58:44 -0400 | [diff] [blame] | 1365 | static struct drm_prop_enum_list radeon_audio_enum_list[] = |
| 1366 | { { RADEON_AUDIO_DISABLE, "off" }, |
| 1367 | { RADEON_AUDIO_ENABLE, "on" }, |
| 1368 | { RADEON_AUDIO_AUTO, "auto" }, |
| 1369 | }; |
| 1370 | |
Alex Deucher | 6214bb7 | 2013-09-24 17:26:26 -0400 | [diff] [blame] | 1371 | /* XXX support different dither options? spatial, temporal, both, etc. */ |
| 1372 | static struct drm_prop_enum_list radeon_dither_enum_list[] = |
| 1373 | { { RADEON_FMT_DITHER_DISABLE, "off" }, |
| 1374 | { RADEON_FMT_DITHER_ENABLE, "on" }, |
| 1375 | }; |
| 1376 | |
Alex Deucher | d79766f | 2009-12-17 19:00:29 -0500 | [diff] [blame] | 1377 | static int radeon_modeset_create_props(struct radeon_device *rdev) |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1378 | { |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1379 | int sz; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1380 | |
| 1381 | if (rdev->is_atom_bios) { |
| 1382 | rdev->mode_info.coherent_mode_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1383 | drm_property_create_range(rdev->ddev, 0 , "coherent", 0, 1); |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1384 | if (!rdev->mode_info.coherent_mode_property) |
| 1385 | return -ENOMEM; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | if (!ASIC_IS_AVIVO(rdev)) { |
| 1389 | sz = ARRAY_SIZE(radeon_tmds_pll_enum_list); |
| 1390 | rdev->mode_info.tmds_pll_property = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1391 | drm_property_create_enum(rdev->ddev, 0, |
| 1392 | "tmds_pll", |
| 1393 | radeon_tmds_pll_enum_list, sz); |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | rdev->mode_info.load_detect_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1397 | drm_property_create_range(rdev->ddev, 0, "load detection", 0, 1); |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1398 | if (!rdev->mode_info.load_detect_property) |
| 1399 | return -ENOMEM; |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1400 | |
| 1401 | drm_mode_create_scaling_mode_property(rdev->ddev); |
| 1402 | |
| 1403 | sz = ARRAY_SIZE(radeon_tv_std_enum_list); |
| 1404 | rdev->mode_info.tv_std_property = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1405 | drm_property_create_enum(rdev->ddev, 0, |
| 1406 | "tv standard", |
| 1407 | radeon_tv_std_enum_list, sz); |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1408 | |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1409 | sz = ARRAY_SIZE(radeon_underscan_enum_list); |
| 1410 | rdev->mode_info.underscan_property = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1411 | drm_property_create_enum(rdev->ddev, 0, |
| 1412 | "underscan", |
| 1413 | radeon_underscan_enum_list, sz); |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1414 | |
Marius Gröger | 5bccf5e | 2010-09-21 21:30:59 +0200 | [diff] [blame] | 1415 | rdev->mode_info.underscan_hborder_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1416 | drm_property_create_range(rdev->ddev, 0, |
| 1417 | "underscan hborder", 0, 128); |
Marius Gröger | 5bccf5e | 2010-09-21 21:30:59 +0200 | [diff] [blame] | 1418 | if (!rdev->mode_info.underscan_hborder_property) |
| 1419 | return -ENOMEM; |
Marius Gröger | 5bccf5e | 2010-09-21 21:30:59 +0200 | [diff] [blame] | 1420 | |
| 1421 | rdev->mode_info.underscan_vborder_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1422 | drm_property_create_range(rdev->ddev, 0, |
| 1423 | "underscan vborder", 0, 128); |
Marius Gröger | 5bccf5e | 2010-09-21 21:30:59 +0200 | [diff] [blame] | 1424 | if (!rdev->mode_info.underscan_vborder_property) |
| 1425 | return -ENOMEM; |
Marius Gröger | 5bccf5e | 2010-09-21 21:30:59 +0200 | [diff] [blame] | 1426 | |
Alex Deucher | 8666c07 | 2013-09-03 14:58:44 -0400 | [diff] [blame] | 1427 | sz = ARRAY_SIZE(radeon_audio_enum_list); |
| 1428 | rdev->mode_info.audio_property = |
| 1429 | drm_property_create_enum(rdev->ddev, 0, |
| 1430 | "audio", |
| 1431 | radeon_audio_enum_list, sz); |
| 1432 | |
Alex Deucher | 6214bb7 | 2013-09-24 17:26:26 -0400 | [diff] [blame] | 1433 | sz = ARRAY_SIZE(radeon_dither_enum_list); |
| 1434 | rdev->mode_info.dither_property = |
| 1435 | drm_property_create_enum(rdev->ddev, 0, |
| 1436 | "dither", |
| 1437 | radeon_dither_enum_list, sz); |
| 1438 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1439 | return 0; |
| 1440 | } |
| 1441 | |
Alex Deucher | f46c012 | 2010-03-31 00:33:27 -0400 | [diff] [blame] | 1442 | void radeon_update_display_priority(struct radeon_device *rdev) |
| 1443 | { |
| 1444 | /* adjustment options for the display watermarks */ |
| 1445 | if ((radeon_disp_priority == 0) || (radeon_disp_priority > 2)) { |
| 1446 | /* set display priority to high for r3xx, rv515 chips |
| 1447 | * this avoids flickering due to underflow to the |
| 1448 | * display controllers during heavy acceleration. |
Alex Deucher | 4573744 | 2010-05-20 11:26:11 -0400 | [diff] [blame] | 1449 | * Don't force high on rs4xx igp chips as it seems to |
| 1450 | * affect the sound card. See kernel bug 15982. |
Alex Deucher | f46c012 | 2010-03-31 00:33:27 -0400 | [diff] [blame] | 1451 | */ |
Alex Deucher | 4573744 | 2010-05-20 11:26:11 -0400 | [diff] [blame] | 1452 | if ((ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV515)) && |
| 1453 | !(rdev->flags & RADEON_IS_IGP)) |
Alex Deucher | f46c012 | 2010-03-31 00:33:27 -0400 | [diff] [blame] | 1454 | rdev->disp_priority = 2; |
| 1455 | else |
| 1456 | rdev->disp_priority = 0; |
| 1457 | } else |
| 1458 | rdev->disp_priority = radeon_disp_priority; |
| 1459 | |
| 1460 | } |
| 1461 | |
Alex Deucher | 0783986 | 2012-05-14 16:52:29 +0200 | [diff] [blame] | 1462 | /* |
| 1463 | * Allocate hdmi structs and determine register offsets |
| 1464 | */ |
| 1465 | static void radeon_afmt_init(struct radeon_device *rdev) |
| 1466 | { |
| 1467 | int i; |
| 1468 | |
| 1469 | for (i = 0; i < RADEON_MAX_AFMT_BLOCKS; i++) |
| 1470 | rdev->mode_info.afmt[i] = NULL; |
| 1471 | |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 1472 | if (ASIC_IS_NODCE(rdev)) { |
| 1473 | /* nothing to do */ |
Alex Deucher | 0783986 | 2012-05-14 16:52:29 +0200 | [diff] [blame] | 1474 | } else if (ASIC_IS_DCE4(rdev)) { |
Rafał Miłecki | a4d39e6 | 2013-08-01 17:29:16 +0200 | [diff] [blame] | 1475 | static uint32_t eg_offsets[] = { |
| 1476 | EVERGREEN_CRTC0_REGISTER_OFFSET, |
| 1477 | EVERGREEN_CRTC1_REGISTER_OFFSET, |
| 1478 | EVERGREEN_CRTC2_REGISTER_OFFSET, |
| 1479 | EVERGREEN_CRTC3_REGISTER_OFFSET, |
| 1480 | EVERGREEN_CRTC4_REGISTER_OFFSET, |
| 1481 | EVERGREEN_CRTC5_REGISTER_OFFSET, |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 1482 | 0x13830 - 0x7030, |
Rafał Miłecki | a4d39e6 | 2013-08-01 17:29:16 +0200 | [diff] [blame] | 1483 | }; |
| 1484 | int num_afmt; |
| 1485 | |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 1486 | /* DCE8 has 7 audio blocks tied to DIG encoders */ |
| 1487 | /* DCE6 has 6 audio blocks tied to DIG encoders */ |
Alex Deucher | 0783986 | 2012-05-14 16:52:29 +0200 | [diff] [blame] | 1488 | /* DCE4/5 has 6 audio blocks tied to DIG encoders */ |
| 1489 | /* DCE4.1 has 2 audio blocks tied to DIG encoders */ |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 1490 | if (ASIC_IS_DCE8(rdev)) |
| 1491 | num_afmt = 7; |
| 1492 | else if (ASIC_IS_DCE6(rdev)) |
| 1493 | num_afmt = 6; |
| 1494 | else if (ASIC_IS_DCE5(rdev)) |
Rafał Miłecki | a4d39e6 | 2013-08-01 17:29:16 +0200 | [diff] [blame] | 1495 | num_afmt = 6; |
| 1496 | else if (ASIC_IS_DCE41(rdev)) |
| 1497 | num_afmt = 2; |
| 1498 | else /* DCE4 */ |
| 1499 | num_afmt = 6; |
| 1500 | |
| 1501 | BUG_ON(num_afmt > ARRAY_SIZE(eg_offsets)); |
| 1502 | for (i = 0; i < num_afmt; i++) { |
| 1503 | rdev->mode_info.afmt[i] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL); |
| 1504 | if (rdev->mode_info.afmt[i]) { |
| 1505 | rdev->mode_info.afmt[i]->offset = eg_offsets[i]; |
| 1506 | rdev->mode_info.afmt[i]->id = i; |
Alex Deucher | 0783986 | 2012-05-14 16:52:29 +0200 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | } else if (ASIC_IS_DCE3(rdev)) { |
| 1510 | /* DCE3.x has 2 audio blocks tied to DIG encoders */ |
| 1511 | rdev->mode_info.afmt[0] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL); |
| 1512 | if (rdev->mode_info.afmt[0]) { |
| 1513 | rdev->mode_info.afmt[0]->offset = DCE3_HDMI_OFFSET0; |
| 1514 | rdev->mode_info.afmt[0]->id = 0; |
| 1515 | } |
| 1516 | rdev->mode_info.afmt[1] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL); |
| 1517 | if (rdev->mode_info.afmt[1]) { |
| 1518 | rdev->mode_info.afmt[1]->offset = DCE3_HDMI_OFFSET1; |
| 1519 | rdev->mode_info.afmt[1]->id = 1; |
| 1520 | } |
| 1521 | } else if (ASIC_IS_DCE2(rdev)) { |
| 1522 | /* DCE2 has at least 1 routable audio block */ |
| 1523 | rdev->mode_info.afmt[0] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL); |
| 1524 | if (rdev->mode_info.afmt[0]) { |
| 1525 | rdev->mode_info.afmt[0]->offset = DCE2_HDMI_OFFSET0; |
| 1526 | rdev->mode_info.afmt[0]->id = 0; |
| 1527 | } |
| 1528 | /* r6xx has 2 routable audio blocks */ |
| 1529 | if (rdev->family >= CHIP_R600) { |
| 1530 | rdev->mode_info.afmt[1] = kzalloc(sizeof(struct radeon_afmt), GFP_KERNEL); |
| 1531 | if (rdev->mode_info.afmt[1]) { |
| 1532 | rdev->mode_info.afmt[1]->offset = DCE2_HDMI_OFFSET1; |
| 1533 | rdev->mode_info.afmt[1]->id = 1; |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | static void radeon_afmt_fini(struct radeon_device *rdev) |
| 1540 | { |
| 1541 | int i; |
| 1542 | |
| 1543 | for (i = 0; i < RADEON_MAX_AFMT_BLOCKS; i++) { |
| 1544 | kfree(rdev->mode_info.afmt[i]); |
| 1545 | rdev->mode_info.afmt[i] = NULL; |
| 1546 | } |
| 1547 | } |
| 1548 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1549 | int radeon_modeset_init(struct radeon_device *rdev) |
| 1550 | { |
Alex Deucher | 18917b6 | 2010-02-01 16:02:25 -0500 | [diff] [blame] | 1551 | int i; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1552 | int ret; |
| 1553 | |
| 1554 | drm_mode_config_init(rdev->ddev); |
| 1555 | rdev->mode_info.mode_config_initialized = true; |
| 1556 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 1557 | rdev->ddev->mode_config.funcs = &radeon_mode_funcs; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1558 | |
Alex Deucher | 881dd74 | 2011-01-06 21:19:14 -0500 | [diff] [blame] | 1559 | if (ASIC_IS_DCE5(rdev)) { |
| 1560 | rdev->ddev->mode_config.max_width = 16384; |
| 1561 | rdev->ddev->mode_config.max_height = 16384; |
| 1562 | } else if (ASIC_IS_AVIVO(rdev)) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1563 | rdev->ddev->mode_config.max_width = 8192; |
| 1564 | rdev->ddev->mode_config.max_height = 8192; |
| 1565 | } else { |
| 1566 | rdev->ddev->mode_config.max_width = 4096; |
| 1567 | rdev->ddev->mode_config.max_height = 4096; |
| 1568 | } |
| 1569 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 1570 | rdev->ddev->mode_config.preferred_depth = 24; |
| 1571 | rdev->ddev->mode_config.prefer_shadow = 1; |
| 1572 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1573 | rdev->ddev->mode_config.fb_base = rdev->mc.aper_base; |
| 1574 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1575 | ret = radeon_modeset_create_props(rdev); |
| 1576 | if (ret) { |
| 1577 | return ret; |
| 1578 | } |
Dave Airlie | dfee561 | 2009-10-02 09:19:09 +1000 | [diff] [blame] | 1579 | |
Alex Deucher | f376b94 | 2010-08-05 21:21:16 -0400 | [diff] [blame] | 1580 | /* init i2c buses */ |
| 1581 | radeon_i2c_init(rdev); |
| 1582 | |
Alex Deucher | 3c53788 | 2010-02-05 04:21:19 -0500 | [diff] [blame] | 1583 | /* check combios for a valid hardcoded EDID - Sun servers */ |
| 1584 | if (!rdev->is_atom_bios) { |
| 1585 | /* check for hardcoded EDID in BIOS */ |
| 1586 | radeon_combios_check_hardcoded_edid(rdev); |
| 1587 | } |
| 1588 | |
Dave Airlie | dfee561 | 2009-10-02 09:19:09 +1000 | [diff] [blame] | 1589 | /* allocate crtcs */ |
Alex Deucher | 18917b6 | 2010-02-01 16:02:25 -0500 | [diff] [blame] | 1590 | for (i = 0; i < rdev->num_crtc; i++) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1591 | radeon_crtc_init(rdev->ddev, i); |
| 1592 | } |
| 1593 | |
| 1594 | /* okay we should have all the bios connectors */ |
| 1595 | ret = radeon_setup_enc_conn(rdev->ddev); |
| 1596 | if (!ret) { |
| 1597 | return ret; |
| 1598 | } |
Alex Deucher | ac89af1 | 2011-05-22 13:20:36 -0400 | [diff] [blame] | 1599 | |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 1600 | /* init dig PHYs, disp eng pll */ |
| 1601 | if (rdev->is_atom_bios) { |
Alex Deucher | ac89af1 | 2011-05-22 13:20:36 -0400 | [diff] [blame] | 1602 | radeon_atom_encoder_init(rdev); |
Alex Deucher | f3f1f03 | 2012-03-20 17:18:04 -0400 | [diff] [blame] | 1603 | radeon_atom_disp_eng_pll_init(rdev); |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 1604 | } |
Alex Deucher | ac89af1 | 2011-05-22 13:20:36 -0400 | [diff] [blame] | 1605 | |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 1606 | /* initialize hpd */ |
| 1607 | radeon_hpd_init(rdev); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1608 | |
Alex Deucher | 0783986 | 2012-05-14 16:52:29 +0200 | [diff] [blame] | 1609 | /* setup afmt */ |
| 1610 | radeon_afmt_init(rdev); |
| 1611 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1612 | radeon_fbdev_init(rdev); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1613 | drm_kms_helper_poll_init(rdev->ddev); |
| 1614 | |
Alex Deucher | 6c7bcce | 2013-12-18 14:07:14 -0500 | [diff] [blame] | 1615 | if (rdev->pm.dpm_enabled) { |
| 1616 | /* do dpm late init */ |
| 1617 | ret = radeon_pm_late_init(rdev); |
| 1618 | if (ret) { |
| 1619 | rdev->pm.dpm_enabled = false; |
| 1620 | DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n"); |
| 1621 | } |
| 1622 | /* set the dpm state for PX since there won't be |
| 1623 | * a modeset to call this. |
| 1624 | */ |
| 1625 | radeon_pm_compute_clocks(rdev); |
| 1626 | } |
| 1627 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1628 | return 0; |
| 1629 | } |
| 1630 | |
| 1631 | void radeon_modeset_fini(struct radeon_device *rdev) |
| 1632 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1633 | radeon_fbdev_fini(rdev); |
Alex Deucher | 3c53788 | 2010-02-05 04:21:19 -0500 | [diff] [blame] | 1634 | kfree(rdev->mode_info.bios_hardcoded_edid); |
| 1635 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1636 | if (rdev->mode_info.mode_config_initialized) { |
Alex Deucher | 0783986 | 2012-05-14 16:52:29 +0200 | [diff] [blame] | 1637 | radeon_afmt_fini(rdev); |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1638 | drm_kms_helper_poll_fini(rdev->ddev); |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 1639 | radeon_hpd_fini(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1640 | drm_mode_config_cleanup(rdev->ddev); |
| 1641 | rdev->mode_info.mode_config_initialized = false; |
| 1642 | } |
Alex Deucher | f376b94 | 2010-08-05 21:21:16 -0400 | [diff] [blame] | 1643 | /* free i2c buses */ |
| 1644 | radeon_i2c_fini(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1645 | } |
| 1646 | |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 1647 | static bool is_hdtv_mode(const struct drm_display_mode *mode) |
Alex Deucher | 039ed2d | 2010-08-20 11:57:19 -0400 | [diff] [blame] | 1648 | { |
| 1649 | /* try and guess if this is a tv or a monitor */ |
| 1650 | if ((mode->vdisplay == 480 && mode->hdisplay == 720) || /* 480p */ |
| 1651 | (mode->vdisplay == 576) || /* 576p */ |
| 1652 | (mode->vdisplay == 720) || /* 720p */ |
| 1653 | (mode->vdisplay == 1080)) /* 1080p */ |
| 1654 | return true; |
| 1655 | else |
| 1656 | return false; |
| 1657 | } |
| 1658 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1659 | bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 1660 | const struct drm_display_mode *mode, |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1661 | struct drm_display_mode *adjusted_mode) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1662 | { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1663 | struct drm_device *dev = crtc->dev; |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1664 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1665 | struct drm_encoder *encoder; |
| 1666 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
| 1667 | struct radeon_encoder *radeon_encoder; |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1668 | struct drm_connector *connector; |
| 1669 | struct radeon_connector *radeon_connector; |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1670 | bool first = true; |
Alex Deucher | d65d65b | 2010-08-03 19:58:49 -0400 | [diff] [blame] | 1671 | u32 src_v = 1, dst_v = 1; |
| 1672 | u32 src_h = 1, dst_h = 1; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1673 | |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1674 | radeon_crtc->h_border = 0; |
| 1675 | radeon_crtc->v_border = 0; |
| 1676 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1677 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1678 | if (encoder->crtc != crtc) |
| 1679 | continue; |
Alex Deucher | d65d65b | 2010-08-03 19:58:49 -0400 | [diff] [blame] | 1680 | radeon_encoder = to_radeon_encoder(encoder); |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1681 | connector = radeon_get_connector_for_encoder(encoder); |
| 1682 | radeon_connector = to_radeon_connector(connector); |
| 1683 | |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1684 | if (first) { |
Alex Deucher | 80297e8 | 2009-11-12 14:55:14 -0500 | [diff] [blame] | 1685 | /* set scaling */ |
| 1686 | if (radeon_encoder->rmx_type == RMX_OFF) |
| 1687 | radeon_crtc->rmx_type = RMX_OFF; |
| 1688 | else if (mode->hdisplay < radeon_encoder->native_mode.hdisplay || |
| 1689 | mode->vdisplay < radeon_encoder->native_mode.vdisplay) |
| 1690 | radeon_crtc->rmx_type = radeon_encoder->rmx_type; |
| 1691 | else |
| 1692 | radeon_crtc->rmx_type = RMX_OFF; |
| 1693 | /* copy native mode */ |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1694 | memcpy(&radeon_crtc->native_mode, |
Alex Deucher | 80297e8 | 2009-11-12 14:55:14 -0500 | [diff] [blame] | 1695 | &radeon_encoder->native_mode, |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 1696 | sizeof(struct drm_display_mode)); |
Alex Deucher | ff32a59 | 2010-09-07 13:26:39 -0400 | [diff] [blame] | 1697 | src_v = crtc->mode.vdisplay; |
| 1698 | dst_v = radeon_crtc->native_mode.vdisplay; |
| 1699 | src_h = crtc->mode.hdisplay; |
| 1700 | dst_h = radeon_crtc->native_mode.hdisplay; |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1701 | |
| 1702 | /* fix up for overscan on hdmi */ |
| 1703 | if (ASIC_IS_AVIVO(rdev) && |
Alex Deucher | e6db0da | 2010-09-10 03:19:05 -0400 | [diff] [blame] | 1704 | (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) && |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1705 | ((radeon_encoder->underscan_type == UNDERSCAN_ON) || |
| 1706 | ((radeon_encoder->underscan_type == UNDERSCAN_AUTO) && |
Alex Deucher | 039ed2d | 2010-08-20 11:57:19 -0400 | [diff] [blame] | 1707 | drm_detect_hdmi_monitor(radeon_connector->edid) && |
| 1708 | is_hdtv_mode(mode)))) { |
Marius Gröger | 5bccf5e | 2010-09-21 21:30:59 +0200 | [diff] [blame] | 1709 | if (radeon_encoder->underscan_hborder != 0) |
| 1710 | radeon_crtc->h_border = radeon_encoder->underscan_hborder; |
| 1711 | else |
| 1712 | radeon_crtc->h_border = (mode->hdisplay >> 5) + 16; |
| 1713 | if (radeon_encoder->underscan_vborder != 0) |
| 1714 | radeon_crtc->v_border = radeon_encoder->underscan_vborder; |
| 1715 | else |
| 1716 | radeon_crtc->v_border = (mode->vdisplay >> 5) + 16; |
Alex Deucher | 5b1714d | 2010-08-03 19:59:20 -0400 | [diff] [blame] | 1717 | radeon_crtc->rmx_type = RMX_FULL; |
| 1718 | src_v = crtc->mode.vdisplay; |
| 1719 | dst_v = crtc->mode.vdisplay - (radeon_crtc->v_border * 2); |
| 1720 | src_h = crtc->mode.hdisplay; |
| 1721 | dst_h = crtc->mode.hdisplay - (radeon_crtc->h_border * 2); |
| 1722 | } |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1723 | first = false; |
| 1724 | } else { |
| 1725 | if (radeon_crtc->rmx_type != radeon_encoder->rmx_type) { |
| 1726 | /* WARNING: Right now this can't happen but |
| 1727 | * in the future we need to check that scaling |
Alex Deucher | d65d65b | 2010-08-03 19:58:49 -0400 | [diff] [blame] | 1728 | * are consistent across different encoder |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1729 | * (ie all encoder can work with the same |
| 1730 | * scaling). |
| 1731 | */ |
Alex Deucher | d65d65b | 2010-08-03 19:58:49 -0400 | [diff] [blame] | 1732 | DRM_ERROR("Scaling not consistent across encoder.\n"); |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1733 | return false; |
| 1734 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1735 | } |
| 1736 | } |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1737 | if (radeon_crtc->rmx_type != RMX_OFF) { |
| 1738 | fixed20_12 a, b; |
Alex Deucher | d65d65b | 2010-08-03 19:58:49 -0400 | [diff] [blame] | 1739 | a.full = dfixed_const(src_v); |
| 1740 | b.full = dfixed_const(dst_v); |
Ben Skeggs | 68adac5 | 2010-04-28 11:46:42 +1000 | [diff] [blame] | 1741 | radeon_crtc->vsc.full = dfixed_div(a, b); |
Alex Deucher | d65d65b | 2010-08-03 19:58:49 -0400 | [diff] [blame] | 1742 | a.full = dfixed_const(src_h); |
| 1743 | b.full = dfixed_const(dst_h); |
Ben Skeggs | 68adac5 | 2010-04-28 11:46:42 +1000 | [diff] [blame] | 1744 | radeon_crtc->hsc.full = dfixed_div(a, b); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1745 | } else { |
Ben Skeggs | 68adac5 | 2010-04-28 11:46:42 +1000 | [diff] [blame] | 1746 | radeon_crtc->vsc.full = dfixed_const(1); |
| 1747 | radeon_crtc->hsc.full = dfixed_const(1); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1748 | } |
Jerome Glisse | c93bb85 | 2009-07-13 21:04:08 +0200 | [diff] [blame] | 1749 | return true; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1750 | } |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1751 | |
| 1752 | /* |
Mario Kleiner | d47abc5 | 2013-10-30 05:13:07 +0100 | [diff] [blame] | 1753 | * Retrieve current video scanout position of crtc on a given gpu, and |
| 1754 | * an optional accurate timestamp of when query happened. |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1755 | * |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1756 | * \param dev Device to query. |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1757 | * \param crtc Crtc to query. |
Ville Syrjälä | abca9e45 | 2013-10-28 20:50:48 +0200 | [diff] [blame] | 1758 | * \param flags Flags from caller (DRM_CALLED_FROM_VBLIRQ or 0). |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1759 | * \param *vpos Location where vertical scanout position should be stored. |
| 1760 | * \param *hpos Location where horizontal scanout position should go. |
Mario Kleiner | d47abc5 | 2013-10-30 05:13:07 +0100 | [diff] [blame] | 1761 | * \param *stime Target location for timestamp taken immediately before |
| 1762 | * scanout position query. Can be NULL to skip timestamp. |
| 1763 | * \param *etime Target location for timestamp taken immediately after |
| 1764 | * scanout position query. Can be NULL to skip timestamp. |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1765 | * |
| 1766 | * Returns vpos as a positive number while in active scanout area. |
| 1767 | * Returns vpos as a negative number inside vblank, counting the number |
| 1768 | * of scanlines to go until end of vblank, e.g., -1 means "one scanline |
| 1769 | * until start of active scanout / end of vblank." |
| 1770 | * |
| 1771 | * \return Flags, or'ed together as follows: |
| 1772 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1773 | * DRM_SCANOUTPOS_VALID = Query successful. |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1774 | * DRM_SCANOUTPOS_INVBL = Inside vblank. |
| 1775 | * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1776 | * this flag means that returned position may be offset by a constant but |
| 1777 | * unknown small number of scanlines wrt. real scanout position. |
| 1778 | * |
| 1779 | */ |
Ville Syrjälä | abca9e45 | 2013-10-28 20:50:48 +0200 | [diff] [blame] | 1780 | int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, unsigned int flags, |
| 1781 | int *vpos, int *hpos, ktime_t *stime, ktime_t *etime) |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1782 | { |
| 1783 | u32 stat_crtc = 0, vbl = 0, position = 0; |
| 1784 | int vbl_start, vbl_end, vtotal, ret = 0; |
| 1785 | bool in_vbl = true; |
| 1786 | |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1787 | struct radeon_device *rdev = dev->dev_private; |
| 1788 | |
Mario Kleiner | d47abc5 | 2013-10-30 05:13:07 +0100 | [diff] [blame] | 1789 | /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ |
| 1790 | |
| 1791 | /* Get optional system timestamp before query. */ |
| 1792 | if (stime) |
| 1793 | *stime = ktime_get(); |
| 1794 | |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1795 | if (ASIC_IS_DCE4(rdev)) { |
| 1796 | if (crtc == 0) { |
| 1797 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 1798 | EVERGREEN_CRTC0_REGISTER_OFFSET); |
| 1799 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 1800 | EVERGREEN_CRTC0_REGISTER_OFFSET); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1801 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1802 | } |
| 1803 | if (crtc == 1) { |
| 1804 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 1805 | EVERGREEN_CRTC1_REGISTER_OFFSET); |
| 1806 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 1807 | EVERGREEN_CRTC1_REGISTER_OFFSET); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1808 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1809 | } |
| 1810 | if (crtc == 2) { |
| 1811 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 1812 | EVERGREEN_CRTC2_REGISTER_OFFSET); |
| 1813 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 1814 | EVERGREEN_CRTC2_REGISTER_OFFSET); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1815 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1816 | } |
| 1817 | if (crtc == 3) { |
| 1818 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 1819 | EVERGREEN_CRTC3_REGISTER_OFFSET); |
| 1820 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 1821 | EVERGREEN_CRTC3_REGISTER_OFFSET); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1822 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1823 | } |
| 1824 | if (crtc == 4) { |
| 1825 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 1826 | EVERGREEN_CRTC4_REGISTER_OFFSET); |
| 1827 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 1828 | EVERGREEN_CRTC4_REGISTER_OFFSET); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1829 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1830 | } |
| 1831 | if (crtc == 5) { |
| 1832 | vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END + |
| 1833 | EVERGREEN_CRTC5_REGISTER_OFFSET); |
| 1834 | position = RREG32(EVERGREEN_CRTC_STATUS_POSITION + |
| 1835 | EVERGREEN_CRTC5_REGISTER_OFFSET); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1836 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1837 | } |
| 1838 | } else if (ASIC_IS_AVIVO(rdev)) { |
| 1839 | if (crtc == 0) { |
| 1840 | vbl = RREG32(AVIVO_D1CRTC_V_BLANK_START_END); |
| 1841 | position = RREG32(AVIVO_D1CRTC_STATUS_POSITION); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1842 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1843 | } |
| 1844 | if (crtc == 1) { |
| 1845 | vbl = RREG32(AVIVO_D2CRTC_V_BLANK_START_END); |
| 1846 | position = RREG32(AVIVO_D2CRTC_STATUS_POSITION); |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1847 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1848 | } |
| 1849 | } else { |
| 1850 | /* Pre-AVIVO: Different encoding of scanout pos and vblank interval. */ |
| 1851 | if (crtc == 0) { |
| 1852 | /* Assume vbl_end == 0, get vbl_start from |
| 1853 | * upper 16 bits. |
| 1854 | */ |
| 1855 | vbl = (RREG32(RADEON_CRTC_V_TOTAL_DISP) & |
| 1856 | RADEON_CRTC_V_DISP) >> RADEON_CRTC_V_DISP_SHIFT; |
| 1857 | /* Only retrieve vpos from upper 16 bits, set hpos == 0. */ |
| 1858 | position = (RREG32(RADEON_CRTC_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL; |
| 1859 | stat_crtc = RREG32(RADEON_CRTC_STATUS); |
| 1860 | if (!(stat_crtc & 1)) |
| 1861 | in_vbl = false; |
| 1862 | |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1863 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1864 | } |
| 1865 | if (crtc == 1) { |
| 1866 | vbl = (RREG32(RADEON_CRTC2_V_TOTAL_DISP) & |
| 1867 | RADEON_CRTC_V_DISP) >> RADEON_CRTC_V_DISP_SHIFT; |
| 1868 | position = (RREG32(RADEON_CRTC2_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL; |
| 1869 | stat_crtc = RREG32(RADEON_CRTC2_STATUS); |
| 1870 | if (!(stat_crtc & 1)) |
| 1871 | in_vbl = false; |
| 1872 | |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1873 | ret |= DRM_SCANOUTPOS_VALID; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1874 | } |
| 1875 | } |
| 1876 | |
Mario Kleiner | d47abc5 | 2013-10-30 05:13:07 +0100 | [diff] [blame] | 1877 | /* Get optional system timestamp after query. */ |
| 1878 | if (etime) |
| 1879 | *etime = ktime_get(); |
| 1880 | |
| 1881 | /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ |
| 1882 | |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1883 | /* Decode into vertical and horizontal scanout position. */ |
| 1884 | *vpos = position & 0x1fff; |
| 1885 | *hpos = (position >> 16) & 0x1fff; |
| 1886 | |
| 1887 | /* Valid vblank area boundaries from gpu retrieved? */ |
| 1888 | if (vbl > 0) { |
| 1889 | /* Yes: Decode. */ |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1890 | ret |= DRM_SCANOUTPOS_ACCURATE; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1891 | vbl_start = vbl & 0x1fff; |
| 1892 | vbl_end = (vbl >> 16) & 0x1fff; |
| 1893 | } |
| 1894 | else { |
| 1895 | /* No: Fake something reasonable which gives at least ok results. */ |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1896 | vbl_start = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vdisplay; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1897 | vbl_end = 0; |
| 1898 | } |
| 1899 | |
| 1900 | /* Test scanout position against vblank region. */ |
| 1901 | if ((*vpos < vbl_start) && (*vpos >= vbl_end)) |
| 1902 | in_vbl = false; |
| 1903 | |
| 1904 | /* Check if inside vblank area and apply corrective offsets: |
| 1905 | * vpos will then be >=0 in video scanout area, but negative |
| 1906 | * within vblank area, counting down the number of lines until |
| 1907 | * start of scanout. |
| 1908 | */ |
| 1909 | |
| 1910 | /* Inside "upper part" of vblank area? Apply corrective offset if so: */ |
| 1911 | if (in_vbl && (*vpos >= vbl_start)) { |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1912 | vtotal = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vtotal; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1913 | *vpos = *vpos - vtotal; |
| 1914 | } |
| 1915 | |
| 1916 | /* Correct for shifted end of vbl at vbl_end. */ |
| 1917 | *vpos = *vpos - vbl_end; |
| 1918 | |
| 1919 | /* In vblank? */ |
| 1920 | if (in_vbl) |
Mario Kleiner | f5a8020 | 2010-10-23 04:42:17 +0200 | [diff] [blame] | 1921 | ret |= DRM_SCANOUTPOS_INVBL; |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1922 | |
Ville Syrjälä | 8072bfa | 2013-10-28 21:22:52 +0200 | [diff] [blame] | 1923 | /* Is vpos outside nominal vblank area, but less than |
| 1924 | * 1/100 of a frame height away from start of vblank? |
| 1925 | * If so, assume this isn't a massively delayed vblank |
| 1926 | * interrupt, but a vblank interrupt that fired a few |
| 1927 | * microseconds before true start of vblank. Compensate |
| 1928 | * by adding a full frame duration to the final timestamp. |
| 1929 | * Happens, e.g., on ATI R500, R600. |
| 1930 | * |
| 1931 | * We only do this if DRM_CALLED_FROM_VBLIRQ. |
| 1932 | */ |
| 1933 | if ((flags & DRM_CALLED_FROM_VBLIRQ) && !in_vbl) { |
| 1934 | vbl_start = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vdisplay; |
| 1935 | vtotal = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vtotal; |
| 1936 | |
| 1937 | if (vbl_start - *vpos < vtotal / 100) { |
| 1938 | *vpos -= vtotal; |
| 1939 | |
| 1940 | /* Signal this correction as "applied". */ |
| 1941 | ret |= 0x8; |
| 1942 | } |
| 1943 | } |
| 1944 | |
Mario Kleiner | 6383cf7 | 2010-10-05 19:57:36 -0400 | [diff] [blame] | 1945 | return ret; |
| 1946 | } |