Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: remove non-DC DCE 11 code

DC has been the default for ~8 years now and supports
many things that the non-DC code does not (audio, DP MST, etc.).
No DCE 11.x IPs ever supported analog encoders so that is not
an issue. Finally drop this code.

Acked-by: Timur Kristóf <timur.kristof@gmail.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

-3865
-1
drivers/gpu/drm/amd/amdgpu/Makefile
··· 138 138 # add DCE block 139 139 amdgpu-y += \ 140 140 dce_v10_0.o \ 141 - dce_v11_0.o \ 142 141 amdgpu_vkms.o 143 142 144 143 # add GFX block
-8
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
··· 14 14 #include "dce_v8_0.h" 15 15 #endif 16 16 #include "dce_v10_0.h" 17 - #include "dce_v11_0.h" 18 17 #include "ivsrcid/ivsrcid_vislands30.h" 19 18 #include "amdgpu_vkms.h" 20 19 #include "amdgpu_display.h" ··· 579 580 case CHIP_FIJI: 580 581 case CHIP_TONGA: 581 582 dce_v10_0_disable_dce(adev); 582 - break; 583 - case CHIP_CARRIZO: 584 - case CHIP_STONEY: 585 - case CHIP_POLARIS10: 586 - case CHIP_POLARIS11: 587 - case CHIP_VEGAM: 588 - dce_v11_0_disable_dce(adev); 589 583 break; 590 584 case CHIP_TOPAZ: 591 585 #ifdef CONFIG_DRM_AMDGPU_SI
-3817
drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
··· 1 - /* 2 - * Copyright 2014 Advanced Micro Devices, Inc. 3 - * 4 - * Permission is hereby granted, free of charge, to any person obtaining a 5 - * copy of this software and associated documentation files (the "Software"), 6 - * to deal in the Software without restriction, including without limitation 7 - * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 - * and/or sell copies of the Software, and to permit persons to whom the 9 - * Software is furnished to do so, subject to the following conditions: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 14 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 - * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 - * OTHER DEALINGS IN THE SOFTWARE. 21 - * 22 - */ 23 - 24 - #include <drm/drm_edid.h> 25 - #include <drm/drm_fourcc.h> 26 - #include <drm/drm_modeset_helper.h> 27 - #include <drm/drm_modeset_helper_vtables.h> 28 - #include <drm/drm_vblank.h> 29 - 30 - #include "amdgpu.h" 31 - #include "amdgpu_pm.h" 32 - #include "amdgpu_i2c.h" 33 - #include "vid.h" 34 - #include "atom.h" 35 - #include "amdgpu_atombios.h" 36 - #include "atombios_crtc.h" 37 - #include "atombios_encoders.h" 38 - #include "amdgpu_pll.h" 39 - #include "amdgpu_connectors.h" 40 - #include "amdgpu_display.h" 41 - #include "dce_v11_0.h" 42 - 43 - #include "dce/dce_11_0_d.h" 44 - #include "dce/dce_11_0_sh_mask.h" 45 - #include "dce/dce_11_0_enum.h" 46 - #include "oss/oss_3_0_d.h" 47 - #include "oss/oss_3_0_sh_mask.h" 48 - #include "gmc/gmc_8_1_d.h" 49 - #include "gmc/gmc_8_1_sh_mask.h" 50 - 51 - #include "ivsrcid/ivsrcid_vislands30.h" 52 - 53 - static void dce_v11_0_set_display_funcs(struct amdgpu_device *adev); 54 - static void dce_v11_0_set_irq_funcs(struct amdgpu_device *adev); 55 - static void dce_v11_0_hpd_int_ack(struct amdgpu_device *adev, int hpd); 56 - 57 - static const u32 crtc_offsets[] = 58 - { 59 - CRTC0_REGISTER_OFFSET, 60 - CRTC1_REGISTER_OFFSET, 61 - CRTC2_REGISTER_OFFSET, 62 - CRTC3_REGISTER_OFFSET, 63 - CRTC4_REGISTER_OFFSET, 64 - CRTC5_REGISTER_OFFSET, 65 - CRTC6_REGISTER_OFFSET 66 - }; 67 - 68 - static const u32 hpd_offsets[] = 69 - { 70 - HPD0_REGISTER_OFFSET, 71 - HPD1_REGISTER_OFFSET, 72 - HPD2_REGISTER_OFFSET, 73 - HPD3_REGISTER_OFFSET, 74 - HPD4_REGISTER_OFFSET, 75 - HPD5_REGISTER_OFFSET 76 - }; 77 - 78 - static const uint32_t dig_offsets[] = { 79 - DIG0_REGISTER_OFFSET, 80 - DIG1_REGISTER_OFFSET, 81 - DIG2_REGISTER_OFFSET, 82 - DIG3_REGISTER_OFFSET, 83 - DIG4_REGISTER_OFFSET, 84 - DIG5_REGISTER_OFFSET, 85 - DIG6_REGISTER_OFFSET, 86 - DIG7_REGISTER_OFFSET, 87 - DIG8_REGISTER_OFFSET 88 - }; 89 - 90 - static const struct { 91 - uint32_t reg; 92 - uint32_t vblank; 93 - uint32_t vline; 94 - uint32_t hpd; 95 - 96 - } interrupt_status_offsets[] = { { 97 - .reg = mmDISP_INTERRUPT_STATUS, 98 - .vblank = DISP_INTERRUPT_STATUS__LB_D1_VBLANK_INTERRUPT_MASK, 99 - .vline = DISP_INTERRUPT_STATUS__LB_D1_VLINE_INTERRUPT_MASK, 100 - .hpd = DISP_INTERRUPT_STATUS__DC_HPD1_INTERRUPT_MASK 101 - }, { 102 - .reg = mmDISP_INTERRUPT_STATUS_CONTINUE, 103 - .vblank = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VBLANK_INTERRUPT_MASK, 104 - .vline = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VLINE_INTERRUPT_MASK, 105 - .hpd = DISP_INTERRUPT_STATUS_CONTINUE__DC_HPD2_INTERRUPT_MASK 106 - }, { 107 - .reg = mmDISP_INTERRUPT_STATUS_CONTINUE2, 108 - .vblank = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VBLANK_INTERRUPT_MASK, 109 - .vline = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VLINE_INTERRUPT_MASK, 110 - .hpd = DISP_INTERRUPT_STATUS_CONTINUE2__DC_HPD3_INTERRUPT_MASK 111 - }, { 112 - .reg = mmDISP_INTERRUPT_STATUS_CONTINUE3, 113 - .vblank = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VBLANK_INTERRUPT_MASK, 114 - .vline = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VLINE_INTERRUPT_MASK, 115 - .hpd = DISP_INTERRUPT_STATUS_CONTINUE3__DC_HPD4_INTERRUPT_MASK 116 - }, { 117 - .reg = mmDISP_INTERRUPT_STATUS_CONTINUE4, 118 - .vblank = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VBLANK_INTERRUPT_MASK, 119 - .vline = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VLINE_INTERRUPT_MASK, 120 - .hpd = DISP_INTERRUPT_STATUS_CONTINUE4__DC_HPD5_INTERRUPT_MASK 121 - }, { 122 - .reg = mmDISP_INTERRUPT_STATUS_CONTINUE5, 123 - .vblank = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VBLANK_INTERRUPT_MASK, 124 - .vline = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VLINE_INTERRUPT_MASK, 125 - .hpd = DISP_INTERRUPT_STATUS_CONTINUE5__DC_HPD6_INTERRUPT_MASK 126 - } }; 127 - 128 - static const u32 cz_golden_settings_a11[] = 129 - { 130 - mmCRTC_DOUBLE_BUFFER_CONTROL, 0x00010101, 0x00010000, 131 - mmFBC_MISC, 0x1f311fff, 0x14300000, 132 - }; 133 - 134 - static const u32 cz_mgcg_cgcg_init[] = 135 - { 136 - mmXDMA_CLOCK_GATING_CNTL, 0xffffffff, 0x00000100, 137 - mmXDMA_MEM_POWER_CNTL, 0x00000101, 0x00000000, 138 - }; 139 - 140 - static const u32 stoney_golden_settings_a11[] = 141 - { 142 - mmCRTC_DOUBLE_BUFFER_CONTROL, 0x00010101, 0x00010000, 143 - mmFBC_MISC, 0x1f311fff, 0x14302000, 144 - }; 145 - 146 - static const u32 polaris11_golden_settings_a11[] = 147 - { 148 - mmDCI_CLK_CNTL, 0x00000080, 0x00000000, 149 - mmFBC_DEBUG_COMP, 0x000000f0, 0x00000070, 150 - mmFBC_DEBUG1, 0xffffffff, 0x00000008, 151 - mmFBC_MISC, 0x9f313fff, 0x14302008, 152 - mmHDMI_CONTROL, 0x313f031f, 0x00000011, 153 - }; 154 - 155 - static const u32 polaris10_golden_settings_a11[] = 156 - { 157 - mmDCI_CLK_CNTL, 0x00000080, 0x00000000, 158 - mmFBC_DEBUG_COMP, 0x000000f0, 0x00000070, 159 - mmFBC_MISC, 0x9f313fff, 0x14302008, 160 - mmHDMI_CONTROL, 0x313f031f, 0x00000011, 161 - }; 162 - 163 - static void dce_v11_0_init_golden_registers(struct amdgpu_device *adev) 164 - { 165 - switch (adev->asic_type) { 166 - case CHIP_CARRIZO: 167 - amdgpu_device_program_register_sequence(adev, 168 - cz_mgcg_cgcg_init, 169 - ARRAY_SIZE(cz_mgcg_cgcg_init)); 170 - amdgpu_device_program_register_sequence(adev, 171 - cz_golden_settings_a11, 172 - ARRAY_SIZE(cz_golden_settings_a11)); 173 - break; 174 - case CHIP_STONEY: 175 - amdgpu_device_program_register_sequence(adev, 176 - stoney_golden_settings_a11, 177 - ARRAY_SIZE(stoney_golden_settings_a11)); 178 - break; 179 - case CHIP_POLARIS11: 180 - case CHIP_POLARIS12: 181 - amdgpu_device_program_register_sequence(adev, 182 - polaris11_golden_settings_a11, 183 - ARRAY_SIZE(polaris11_golden_settings_a11)); 184 - break; 185 - case CHIP_POLARIS10: 186 - case CHIP_VEGAM: 187 - amdgpu_device_program_register_sequence(adev, 188 - polaris10_golden_settings_a11, 189 - ARRAY_SIZE(polaris10_golden_settings_a11)); 190 - break; 191 - default: 192 - break; 193 - } 194 - } 195 - 196 - static u32 dce_v11_0_audio_endpt_rreg(struct amdgpu_device *adev, 197 - u32 block_offset, u32 reg) 198 - { 199 - unsigned long flags; 200 - u32 r; 201 - 202 - spin_lock_irqsave(&adev->audio_endpt_idx_lock, flags); 203 - WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX + block_offset, reg); 204 - r = RREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA + block_offset); 205 - spin_unlock_irqrestore(&adev->audio_endpt_idx_lock, flags); 206 - 207 - return r; 208 - } 209 - 210 - static void dce_v11_0_audio_endpt_wreg(struct amdgpu_device *adev, 211 - u32 block_offset, u32 reg, u32 v) 212 - { 213 - unsigned long flags; 214 - 215 - spin_lock_irqsave(&adev->audio_endpt_idx_lock, flags); 216 - WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX + block_offset, reg); 217 - WREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA + block_offset, v); 218 - spin_unlock_irqrestore(&adev->audio_endpt_idx_lock, flags); 219 - } 220 - 221 - static u32 dce_v11_0_vblank_get_counter(struct amdgpu_device *adev, int crtc) 222 - { 223 - if (crtc < 0 || crtc >= adev->mode_info.num_crtc) 224 - return 0; 225 - else 226 - return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]); 227 - } 228 - 229 - static void dce_v11_0_pageflip_interrupt_init(struct amdgpu_device *adev) 230 - { 231 - unsigned i; 232 - 233 - /* Enable pflip interrupts */ 234 - for (i = 0; i < adev->mode_info.num_crtc; i++) 235 - amdgpu_irq_get(adev, &adev->pageflip_irq, i); 236 - } 237 - 238 - static void dce_v11_0_pageflip_interrupt_fini(struct amdgpu_device *adev) 239 - { 240 - unsigned i; 241 - 242 - /* Disable pflip interrupts */ 243 - for (i = 0; i < adev->mode_info.num_crtc; i++) 244 - amdgpu_irq_put(adev, &adev->pageflip_irq, i); 245 - } 246 - 247 - /** 248 - * dce_v11_0_page_flip - pageflip callback. 249 - * 250 - * @adev: amdgpu_device pointer 251 - * @crtc_id: crtc to cleanup pageflip on 252 - * @crtc_base: new address of the crtc (GPU MC address) 253 - * @async: asynchronous flip 254 - * 255 - * Triggers the actual pageflip by updating the primary 256 - * surface base address. 257 - */ 258 - static void dce_v11_0_page_flip(struct amdgpu_device *adev, 259 - int crtc_id, u64 crtc_base, bool async) 260 - { 261 - struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id]; 262 - struct drm_framebuffer *fb = amdgpu_crtc->base.primary->fb; 263 - u32 tmp; 264 - 265 - /* flip immediate for async, default is vsync */ 266 - tmp = RREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset); 267 - tmp = REG_SET_FIELD(tmp, GRPH_FLIP_CONTROL, 268 - GRPH_SURFACE_UPDATE_IMMEDIATE_EN, async ? 1 : 0); 269 - WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, tmp); 270 - /* update pitch */ 271 - WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, 272 - fb->pitches[0] / fb->format->cpp[0]); 273 - /* update the scanout addresses */ 274 - WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, 275 - upper_32_bits(crtc_base)); 276 - /* writing to the low address triggers the update */ 277 - WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, 278 - lower_32_bits(crtc_base)); 279 - /* post the write */ 280 - RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset); 281 - } 282 - 283 - static int dce_v11_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc, 284 - u32 *vbl, u32 *position) 285 - { 286 - if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc)) 287 - return -EINVAL; 288 - 289 - *vbl = RREG32(mmCRTC_V_BLANK_START_END + crtc_offsets[crtc]); 290 - *position = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]); 291 - 292 - return 0; 293 - } 294 - 295 - /** 296 - * dce_v11_0_hpd_sense - hpd sense callback. 297 - * 298 - * @adev: amdgpu_device pointer 299 - * @hpd: hpd (hotplug detect) pin 300 - * 301 - * Checks if a digital monitor is connected (evergreen+). 302 - * Returns true if connected, false if not connected. 303 - */ 304 - static bool dce_v11_0_hpd_sense(struct amdgpu_device *adev, 305 - enum amdgpu_hpd_id hpd) 306 - { 307 - bool connected = false; 308 - 309 - if (hpd >= adev->mode_info.num_hpd) 310 - return connected; 311 - 312 - if (RREG32(mmDC_HPD_INT_STATUS + hpd_offsets[hpd]) & 313 - DC_HPD_INT_STATUS__DC_HPD_SENSE_MASK) 314 - connected = true; 315 - 316 - return connected; 317 - } 318 - 319 - /** 320 - * dce_v11_0_hpd_set_polarity - hpd set polarity callback. 321 - * 322 - * @adev: amdgpu_device pointer 323 - * @hpd: hpd (hotplug detect) pin 324 - * 325 - * Set the polarity of the hpd pin (evergreen+). 326 - */ 327 - static void dce_v11_0_hpd_set_polarity(struct amdgpu_device *adev, 328 - enum amdgpu_hpd_id hpd) 329 - { 330 - u32 tmp; 331 - bool connected = dce_v11_0_hpd_sense(adev, hpd); 332 - 333 - if (hpd >= adev->mode_info.num_hpd) 334 - return; 335 - 336 - tmp = RREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[hpd]); 337 - if (connected) 338 - tmp = REG_SET_FIELD(tmp, DC_HPD_INT_CONTROL, DC_HPD_INT_POLARITY, 0); 339 - else 340 - tmp = REG_SET_FIELD(tmp, DC_HPD_INT_CONTROL, DC_HPD_INT_POLARITY, 1); 341 - WREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[hpd], tmp); 342 - } 343 - 344 - /** 345 - * dce_v11_0_hpd_init - hpd setup callback. 346 - * 347 - * @adev: amdgpu_device pointer 348 - * 349 - * Setup the hpd pins used by the card (evergreen+). 350 - * Enable the pin, set the polarity, and enable the hpd interrupts. 351 - */ 352 - static void dce_v11_0_hpd_init(struct amdgpu_device *adev) 353 - { 354 - struct drm_device *dev = adev_to_drm(adev); 355 - struct drm_connector *connector; 356 - struct drm_connector_list_iter iter; 357 - u32 tmp; 358 - 359 - drm_connector_list_iter_begin(dev, &iter); 360 - drm_for_each_connector_iter(connector, &iter) { 361 - struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector); 362 - 363 - if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd) 364 - continue; 365 - 366 - if (connector->connector_type == DRM_MODE_CONNECTOR_eDP || 367 - connector->connector_type == DRM_MODE_CONNECTOR_LVDS) { 368 - /* don't try to enable hpd on eDP or LVDS avoid breaking the 369 - * aux dp channel on imac and help (but not completely fix) 370 - * https://bugzilla.redhat.com/show_bug.cgi?id=726143 371 - * also avoid interrupt storms during dpms. 372 - */ 373 - tmp = RREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]); 374 - tmp = REG_SET_FIELD(tmp, DC_HPD_INT_CONTROL, DC_HPD_INT_EN, 0); 375 - WREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp); 376 - continue; 377 - } 378 - 379 - tmp = RREG32(mmDC_HPD_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]); 380 - tmp = REG_SET_FIELD(tmp, DC_HPD_CONTROL, DC_HPD_EN, 1); 381 - WREG32(mmDC_HPD_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp); 382 - 383 - tmp = RREG32(mmDC_HPD_TOGGLE_FILT_CNTL + hpd_offsets[amdgpu_connector->hpd.hpd]); 384 - tmp = REG_SET_FIELD(tmp, DC_HPD_TOGGLE_FILT_CNTL, 385 - DC_HPD_CONNECT_INT_DELAY, 386 - AMDGPU_HPD_CONNECT_INT_DELAY_IN_MS); 387 - tmp = REG_SET_FIELD(tmp, DC_HPD_TOGGLE_FILT_CNTL, 388 - DC_HPD_DISCONNECT_INT_DELAY, 389 - AMDGPU_HPD_DISCONNECT_INT_DELAY_IN_MS); 390 - WREG32(mmDC_HPD_TOGGLE_FILT_CNTL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp); 391 - 392 - dce_v11_0_hpd_int_ack(adev, amdgpu_connector->hpd.hpd); 393 - dce_v11_0_hpd_set_polarity(adev, amdgpu_connector->hpd.hpd); 394 - amdgpu_irq_get(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd); 395 - } 396 - drm_connector_list_iter_end(&iter); 397 - } 398 - 399 - /** 400 - * dce_v11_0_hpd_fini - hpd tear down callback. 401 - * 402 - * @adev: amdgpu_device pointer 403 - * 404 - * Tear down the hpd pins used by the card (evergreen+). 405 - * Disable the hpd interrupts. 406 - */ 407 - static void dce_v11_0_hpd_fini(struct amdgpu_device *adev) 408 - { 409 - struct drm_device *dev = adev_to_drm(adev); 410 - struct drm_connector *connector; 411 - struct drm_connector_list_iter iter; 412 - u32 tmp; 413 - 414 - drm_connector_list_iter_begin(dev, &iter); 415 - drm_for_each_connector_iter(connector, &iter) { 416 - struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector); 417 - 418 - if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd) 419 - continue; 420 - 421 - tmp = RREG32(mmDC_HPD_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]); 422 - tmp = REG_SET_FIELD(tmp, DC_HPD_CONTROL, DC_HPD_EN, 0); 423 - WREG32(mmDC_HPD_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp); 424 - 425 - amdgpu_irq_put(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd); 426 - } 427 - drm_connector_list_iter_end(&iter); 428 - } 429 - 430 - static u32 dce_v11_0_hpd_get_gpio_reg(struct amdgpu_device *adev) 431 - { 432 - return mmDC_GPIO_HPD_A; 433 - } 434 - 435 - static bool dce_v11_0_is_display_hung(struct amdgpu_device *adev) 436 - { 437 - u32 crtc_hung = 0; 438 - u32 crtc_status[6]; 439 - u32 i, j, tmp; 440 - 441 - for (i = 0; i < adev->mode_info.num_crtc; i++) { 442 - tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]); 443 - if (REG_GET_FIELD(tmp, CRTC_CONTROL, CRTC_MASTER_EN)) { 444 - crtc_status[i] = RREG32(mmCRTC_STATUS_HV_COUNT + crtc_offsets[i]); 445 - crtc_hung |= (1 << i); 446 - } 447 - } 448 - 449 - for (j = 0; j < 10; j++) { 450 - for (i = 0; i < adev->mode_info.num_crtc; i++) { 451 - if (crtc_hung & (1 << i)) { 452 - tmp = RREG32(mmCRTC_STATUS_HV_COUNT + crtc_offsets[i]); 453 - if (tmp != crtc_status[i]) 454 - crtc_hung &= ~(1 << i); 455 - } 456 - } 457 - if (crtc_hung == 0) 458 - return false; 459 - udelay(100); 460 - } 461 - 462 - return true; 463 - } 464 - 465 - static void dce_v11_0_set_vga_render_state(struct amdgpu_device *adev, 466 - bool render) 467 - { 468 - u32 tmp; 469 - 470 - /* Lockout access through VGA aperture*/ 471 - tmp = RREG32(mmVGA_HDP_CONTROL); 472 - if (render) 473 - tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 0); 474 - else 475 - tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 1); 476 - WREG32(mmVGA_HDP_CONTROL, tmp); 477 - 478 - /* disable VGA render */ 479 - tmp = RREG32(mmVGA_RENDER_CONTROL); 480 - if (render) 481 - tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 1); 482 - else 483 - tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0); 484 - WREG32(mmVGA_RENDER_CONTROL, tmp); 485 - } 486 - 487 - static int dce_v11_0_get_num_crtc (struct amdgpu_device *adev) 488 - { 489 - int num_crtc = 0; 490 - 491 - switch (adev->asic_type) { 492 - case CHIP_CARRIZO: 493 - num_crtc = 3; 494 - break; 495 - case CHIP_STONEY: 496 - num_crtc = 2; 497 - break; 498 - case CHIP_POLARIS10: 499 - case CHIP_VEGAM: 500 - num_crtc = 6; 501 - break; 502 - case CHIP_POLARIS11: 503 - case CHIP_POLARIS12: 504 - num_crtc = 5; 505 - break; 506 - default: 507 - num_crtc = 0; 508 - } 509 - return num_crtc; 510 - } 511 - 512 - void dce_v11_0_disable_dce(struct amdgpu_device *adev) 513 - { 514 - /*Disable VGA render and enabled crtc, if has DCE engine*/ 515 - if (amdgpu_atombios_has_dce_engine_info(adev)) { 516 - u32 tmp; 517 - int crtc_enabled, i; 518 - 519 - dce_v11_0_set_vga_render_state(adev, false); 520 - 521 - /*Disable crtc*/ 522 - for (i = 0; i < dce_v11_0_get_num_crtc(adev); i++) { 523 - crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]), 524 - CRTC_CONTROL, CRTC_MASTER_EN); 525 - if (crtc_enabled) { 526 - WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1); 527 - tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]); 528 - tmp = REG_SET_FIELD(tmp, CRTC_CONTROL, CRTC_MASTER_EN, 0); 529 - WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp); 530 - WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0); 531 - } 532 - } 533 - } 534 - } 535 - 536 - static void dce_v11_0_program_fmt(struct drm_encoder *encoder) 537 - { 538 - struct drm_device *dev = encoder->dev; 539 - struct amdgpu_device *adev = drm_to_adev(dev); 540 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 541 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc); 542 - struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder); 543 - int bpc = 0; 544 - u32 tmp = 0; 545 - enum amdgpu_connector_dither dither = AMDGPU_FMT_DITHER_DISABLE; 546 - 547 - if (connector) { 548 - struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector); 549 - bpc = amdgpu_connector_get_monitor_bpc(connector); 550 - dither = amdgpu_connector->dither; 551 - } 552 - 553 - /* LVDS/eDP FMT is set up by atom */ 554 - if (amdgpu_encoder->devices & ATOM_DEVICE_LCD_SUPPORT) 555 - return; 556 - 557 - /* not needed for analog */ 558 - if ((amdgpu_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) || 559 - (amdgpu_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2)) 560 - return; 561 - 562 - if (bpc == 0) 563 - return; 564 - 565 - switch (bpc) { 566 - case 6: 567 - if (dither == AMDGPU_FMT_DITHER_ENABLE) { 568 - /* XXX sort out optimal dither settings */ 569 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_FRAME_RANDOM_ENABLE, 1); 570 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_HIGHPASS_RANDOM_ENABLE, 1); 571 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_SPATIAL_DITHER_EN, 1); 572 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_SPATIAL_DITHER_DEPTH, 0); 573 - } else { 574 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_TRUNCATE_EN, 1); 575 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_TRUNCATE_DEPTH, 0); 576 - } 577 - break; 578 - case 8: 579 - if (dither == AMDGPU_FMT_DITHER_ENABLE) { 580 - /* XXX sort out optimal dither settings */ 581 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_FRAME_RANDOM_ENABLE, 1); 582 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_HIGHPASS_RANDOM_ENABLE, 1); 583 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_RGB_RANDOM_ENABLE, 1); 584 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_SPATIAL_DITHER_EN, 1); 585 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_SPATIAL_DITHER_DEPTH, 1); 586 - } else { 587 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_TRUNCATE_EN, 1); 588 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_TRUNCATE_DEPTH, 1); 589 - } 590 - break; 591 - case 10: 592 - if (dither == AMDGPU_FMT_DITHER_ENABLE) { 593 - /* XXX sort out optimal dither settings */ 594 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_FRAME_RANDOM_ENABLE, 1); 595 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_HIGHPASS_RANDOM_ENABLE, 1); 596 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_RGB_RANDOM_ENABLE, 1); 597 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_SPATIAL_DITHER_EN, 1); 598 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_SPATIAL_DITHER_DEPTH, 2); 599 - } else { 600 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_TRUNCATE_EN, 1); 601 - tmp = REG_SET_FIELD(tmp, FMT_BIT_DEPTH_CONTROL, FMT_TRUNCATE_DEPTH, 2); 602 - } 603 - break; 604 - default: 605 - /* not needed */ 606 - break; 607 - } 608 - 609 - WREG32(mmFMT_BIT_DEPTH_CONTROL + amdgpu_crtc->crtc_offset, tmp); 610 - } 611 - 612 - 613 - /* display watermark setup */ 614 - /** 615 - * dce_v11_0_line_buffer_adjust - Set up the line buffer 616 - * 617 - * @adev: amdgpu_device pointer 618 - * @amdgpu_crtc: the selected display controller 619 - * @mode: the current display mode on the selected display 620 - * controller 621 - * 622 - * Setup up the line buffer allocation for 623 - * the selected display controller (CIK). 624 - * Returns the line buffer size in pixels. 625 - */ 626 - static u32 dce_v11_0_line_buffer_adjust(struct amdgpu_device *adev, 627 - struct amdgpu_crtc *amdgpu_crtc, 628 - struct drm_display_mode *mode) 629 - { 630 - u32 tmp, buffer_alloc, i, mem_cfg; 631 - u32 pipe_offset = amdgpu_crtc->crtc_id; 632 - /* 633 - * Line Buffer Setup 634 - * There are 6 line buffers, one for each display controllers. 635 - * There are 3 partitions per LB. Select the number of partitions 636 - * to enable based on the display width. For display widths larger 637 - * than 4096, you need use to use 2 display controllers and combine 638 - * them using the stereo blender. 639 - */ 640 - if (amdgpu_crtc->base.enabled && mode) { 641 - if (mode->crtc_hdisplay < 1920) { 642 - mem_cfg = 1; 643 - buffer_alloc = 2; 644 - } else if (mode->crtc_hdisplay < 2560) { 645 - mem_cfg = 2; 646 - buffer_alloc = 2; 647 - } else if (mode->crtc_hdisplay < 4096) { 648 - mem_cfg = 0; 649 - buffer_alloc = (adev->flags & AMD_IS_APU) ? 2 : 4; 650 - } else { 651 - DRM_DEBUG_KMS("Mode too big for LB!\n"); 652 - mem_cfg = 0; 653 - buffer_alloc = (adev->flags & AMD_IS_APU) ? 2 : 4; 654 - } 655 - } else { 656 - mem_cfg = 1; 657 - buffer_alloc = 0; 658 - } 659 - 660 - tmp = RREG32(mmLB_MEMORY_CTRL + amdgpu_crtc->crtc_offset); 661 - tmp = REG_SET_FIELD(tmp, LB_MEMORY_CTRL, LB_MEMORY_CONFIG, mem_cfg); 662 - WREG32(mmLB_MEMORY_CTRL + amdgpu_crtc->crtc_offset, tmp); 663 - 664 - tmp = RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset); 665 - tmp = REG_SET_FIELD(tmp, PIPE0_DMIF_BUFFER_CONTROL, DMIF_BUFFERS_ALLOCATED, buffer_alloc); 666 - WREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset, tmp); 667 - 668 - for (i = 0; i < adev->usec_timeout; i++) { 669 - tmp = RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset); 670 - if (REG_GET_FIELD(tmp, PIPE0_DMIF_BUFFER_CONTROL, DMIF_BUFFERS_ALLOCATION_COMPLETED)) 671 - break; 672 - udelay(1); 673 - } 674 - 675 - if (amdgpu_crtc->base.enabled && mode) { 676 - switch (mem_cfg) { 677 - case 0: 678 - default: 679 - return 4096 * 2; 680 - case 1: 681 - return 1920 * 2; 682 - case 2: 683 - return 2560 * 2; 684 - } 685 - } 686 - 687 - /* controller not enabled, so no lb used */ 688 - return 0; 689 - } 690 - 691 - /** 692 - * cik_get_number_of_dram_channels - get the number of dram channels 693 - * 694 - * @adev: amdgpu_device pointer 695 - * 696 - * Look up the number of video ram channels (CIK). 697 - * Used for display watermark bandwidth calculations 698 - * Returns the number of dram channels 699 - */ 700 - static u32 cik_get_number_of_dram_channels(struct amdgpu_device *adev) 701 - { 702 - u32 tmp = RREG32(mmMC_SHARED_CHMAP); 703 - 704 - switch (REG_GET_FIELD(tmp, MC_SHARED_CHMAP, NOOFCHAN)) { 705 - case 0: 706 - default: 707 - return 1; 708 - case 1: 709 - return 2; 710 - case 2: 711 - return 4; 712 - case 3: 713 - return 8; 714 - case 4: 715 - return 3; 716 - case 5: 717 - return 6; 718 - case 6: 719 - return 10; 720 - case 7: 721 - return 12; 722 - case 8: 723 - return 16; 724 - } 725 - } 726 - 727 - struct dce10_wm_params { 728 - u32 dram_channels; /* number of dram channels */ 729 - u32 yclk; /* bandwidth per dram data pin in kHz */ 730 - u32 sclk; /* engine clock in kHz */ 731 - u32 disp_clk; /* display clock in kHz */ 732 - u32 src_width; /* viewport width */ 733 - u32 active_time; /* active display time in ns */ 734 - u32 blank_time; /* blank time in ns */ 735 - bool interlaced; /* mode is interlaced */ 736 - fixed20_12 vsc; /* vertical scale ratio */ 737 - u32 num_heads; /* number of active crtcs */ 738 - u32 bytes_per_pixel; /* bytes per pixel display + overlay */ 739 - u32 lb_size; /* line buffer allocated to pipe */ 740 - u32 vtaps; /* vertical scaler taps */ 741 - }; 742 - 743 - /** 744 - * dce_v11_0_dram_bandwidth - get the dram bandwidth 745 - * 746 - * @wm: watermark calculation data 747 - * 748 - * Calculate the raw dram bandwidth (CIK). 749 - * Used for display watermark bandwidth calculations 750 - * Returns the dram bandwidth in MBytes/s 751 - */ 752 - static u32 dce_v11_0_dram_bandwidth(struct dce10_wm_params *wm) 753 - { 754 - /* Calculate raw DRAM Bandwidth */ 755 - fixed20_12 dram_efficiency; /* 0.7 */ 756 - fixed20_12 yclk, dram_channels, bandwidth; 757 - fixed20_12 a; 758 - 759 - a.full = dfixed_const(1000); 760 - yclk.full = dfixed_const(wm->yclk); 761 - yclk.full = dfixed_div(yclk, a); 762 - dram_channels.full = dfixed_const(wm->dram_channels * 4); 763 - a.full = dfixed_const(10); 764 - dram_efficiency.full = dfixed_const(7); 765 - dram_efficiency.full = dfixed_div(dram_efficiency, a); 766 - bandwidth.full = dfixed_mul(dram_channels, yclk); 767 - bandwidth.full = dfixed_mul(bandwidth, dram_efficiency); 768 - 769 - return dfixed_trunc(bandwidth); 770 - } 771 - 772 - /** 773 - * dce_v11_0_dram_bandwidth_for_display - get the dram bandwidth for display 774 - * 775 - * @wm: watermark calculation data 776 - * 777 - * Calculate the dram bandwidth used for display (CIK). 778 - * Used for display watermark bandwidth calculations 779 - * Returns the dram bandwidth for display in MBytes/s 780 - */ 781 - static u32 dce_v11_0_dram_bandwidth_for_display(struct dce10_wm_params *wm) 782 - { 783 - /* Calculate DRAM Bandwidth and the part allocated to display. */ 784 - fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */ 785 - fixed20_12 yclk, dram_channels, bandwidth; 786 - fixed20_12 a; 787 - 788 - a.full = dfixed_const(1000); 789 - yclk.full = dfixed_const(wm->yclk); 790 - yclk.full = dfixed_div(yclk, a); 791 - dram_channels.full = dfixed_const(wm->dram_channels * 4); 792 - a.full = dfixed_const(10); 793 - disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */ 794 - disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a); 795 - bandwidth.full = dfixed_mul(dram_channels, yclk); 796 - bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation); 797 - 798 - return dfixed_trunc(bandwidth); 799 - } 800 - 801 - /** 802 - * dce_v11_0_data_return_bandwidth - get the data return bandwidth 803 - * 804 - * @wm: watermark calculation data 805 - * 806 - * Calculate the data return bandwidth used for display (CIK). 807 - * Used for display watermark bandwidth calculations 808 - * Returns the data return bandwidth in MBytes/s 809 - */ 810 - static u32 dce_v11_0_data_return_bandwidth(struct dce10_wm_params *wm) 811 - { 812 - /* Calculate the display Data return Bandwidth */ 813 - fixed20_12 return_efficiency; /* 0.8 */ 814 - fixed20_12 sclk, bandwidth; 815 - fixed20_12 a; 816 - 817 - a.full = dfixed_const(1000); 818 - sclk.full = dfixed_const(wm->sclk); 819 - sclk.full = dfixed_div(sclk, a); 820 - a.full = dfixed_const(10); 821 - return_efficiency.full = dfixed_const(8); 822 - return_efficiency.full = dfixed_div(return_efficiency, a); 823 - a.full = dfixed_const(32); 824 - bandwidth.full = dfixed_mul(a, sclk); 825 - bandwidth.full = dfixed_mul(bandwidth, return_efficiency); 826 - 827 - return dfixed_trunc(bandwidth); 828 - } 829 - 830 - /** 831 - * dce_v11_0_dmif_request_bandwidth - get the dmif bandwidth 832 - * 833 - * @wm: watermark calculation data 834 - * 835 - * Calculate the dmif bandwidth used for display (CIK). 836 - * Used for display watermark bandwidth calculations 837 - * Returns the dmif bandwidth in MBytes/s 838 - */ 839 - static u32 dce_v11_0_dmif_request_bandwidth(struct dce10_wm_params *wm) 840 - { 841 - /* Calculate the DMIF Request Bandwidth */ 842 - fixed20_12 disp_clk_request_efficiency; /* 0.8 */ 843 - fixed20_12 disp_clk, bandwidth; 844 - fixed20_12 a, b; 845 - 846 - a.full = dfixed_const(1000); 847 - disp_clk.full = dfixed_const(wm->disp_clk); 848 - disp_clk.full = dfixed_div(disp_clk, a); 849 - a.full = dfixed_const(32); 850 - b.full = dfixed_mul(a, disp_clk); 851 - 852 - a.full = dfixed_const(10); 853 - disp_clk_request_efficiency.full = dfixed_const(8); 854 - disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a); 855 - 856 - bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency); 857 - 858 - return dfixed_trunc(bandwidth); 859 - } 860 - 861 - /** 862 - * dce_v11_0_available_bandwidth - get the min available bandwidth 863 - * 864 - * @wm: watermark calculation data 865 - * 866 - * Calculate the min available bandwidth used for display (CIK). 867 - * Used for display watermark bandwidth calculations 868 - * Returns the min available bandwidth in MBytes/s 869 - */ 870 - static u32 dce_v11_0_available_bandwidth(struct dce10_wm_params *wm) 871 - { 872 - /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */ 873 - u32 dram_bandwidth = dce_v11_0_dram_bandwidth(wm); 874 - u32 data_return_bandwidth = dce_v11_0_data_return_bandwidth(wm); 875 - u32 dmif_req_bandwidth = dce_v11_0_dmif_request_bandwidth(wm); 876 - 877 - return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth)); 878 - } 879 - 880 - /** 881 - * dce_v11_0_average_bandwidth - get the average available bandwidth 882 - * 883 - * @wm: watermark calculation data 884 - * 885 - * Calculate the average available bandwidth used for display (CIK). 886 - * Used for display watermark bandwidth calculations 887 - * Returns the average available bandwidth in MBytes/s 888 - */ 889 - static u32 dce_v11_0_average_bandwidth(struct dce10_wm_params *wm) 890 - { 891 - /* Calculate the display mode Average Bandwidth 892 - * DisplayMode should contain the source and destination dimensions, 893 - * timing, etc. 894 - */ 895 - fixed20_12 bpp; 896 - fixed20_12 line_time; 897 - fixed20_12 src_width; 898 - fixed20_12 bandwidth; 899 - fixed20_12 a; 900 - 901 - a.full = dfixed_const(1000); 902 - line_time.full = dfixed_const(wm->active_time + wm->blank_time); 903 - line_time.full = dfixed_div(line_time, a); 904 - bpp.full = dfixed_const(wm->bytes_per_pixel); 905 - src_width.full = dfixed_const(wm->src_width); 906 - bandwidth.full = dfixed_mul(src_width, bpp); 907 - bandwidth.full = dfixed_mul(bandwidth, wm->vsc); 908 - bandwidth.full = dfixed_div(bandwidth, line_time); 909 - 910 - return dfixed_trunc(bandwidth); 911 - } 912 - 913 - /** 914 - * dce_v11_0_latency_watermark - get the latency watermark 915 - * 916 - * @wm: watermark calculation data 917 - * 918 - * Calculate the latency watermark (CIK). 919 - * Used for display watermark bandwidth calculations 920 - * Returns the latency watermark in ns 921 - */ 922 - static u32 dce_v11_0_latency_watermark(struct dce10_wm_params *wm) 923 - { 924 - /* First calculate the latency in ns */ 925 - u32 mc_latency = 2000; /* 2000 ns. */ 926 - u32 available_bandwidth = dce_v11_0_available_bandwidth(wm); 927 - u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth; 928 - u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth; 929 - u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */ 930 - u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) + 931 - (wm->num_heads * cursor_line_pair_return_time); 932 - u32 latency = mc_latency + other_heads_data_return_time + dc_latency; 933 - u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time; 934 - u32 tmp, dmif_size = 12288; 935 - fixed20_12 a, b, c; 936 - 937 - if (wm->num_heads == 0) 938 - return 0; 939 - 940 - a.full = dfixed_const(2); 941 - b.full = dfixed_const(1); 942 - if ((wm->vsc.full > a.full) || 943 - ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) || 944 - (wm->vtaps >= 5) || 945 - ((wm->vsc.full >= a.full) && wm->interlaced)) 946 - max_src_lines_per_dst_line = 4; 947 - else 948 - max_src_lines_per_dst_line = 2; 949 - 950 - a.full = dfixed_const(available_bandwidth); 951 - b.full = dfixed_const(wm->num_heads); 952 - a.full = dfixed_div(a, b); 953 - tmp = div_u64((u64) dmif_size * (u64) wm->disp_clk, mc_latency + 512); 954 - tmp = min(dfixed_trunc(a), tmp); 955 - 956 - lb_fill_bw = min(tmp, wm->disp_clk * wm->bytes_per_pixel / 1000); 957 - 958 - a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel); 959 - b.full = dfixed_const(1000); 960 - c.full = dfixed_const(lb_fill_bw); 961 - b.full = dfixed_div(c, b); 962 - a.full = dfixed_div(a, b); 963 - line_fill_time = dfixed_trunc(a); 964 - 965 - if (line_fill_time < wm->active_time) 966 - return latency; 967 - else 968 - return latency + (line_fill_time - wm->active_time); 969 - 970 - } 971 - 972 - /** 973 - * dce_v11_0_average_bandwidth_vs_dram_bandwidth_for_display - check 974 - * average and available dram bandwidth 975 - * 976 - * @wm: watermark calculation data 977 - * 978 - * Check if the display average bandwidth fits in the display 979 - * dram bandwidth (CIK). 980 - * Used for display watermark bandwidth calculations 981 - * Returns true if the display fits, false if not. 982 - */ 983 - static bool dce_v11_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce10_wm_params *wm) 984 - { 985 - if (dce_v11_0_average_bandwidth(wm) <= 986 - (dce_v11_0_dram_bandwidth_for_display(wm) / wm->num_heads)) 987 - return true; 988 - else 989 - return false; 990 - } 991 - 992 - /** 993 - * dce_v11_0_average_bandwidth_vs_available_bandwidth - check 994 - * average and available bandwidth 995 - * 996 - * @wm: watermark calculation data 997 - * 998 - * Check if the display average bandwidth fits in the display 999 - * available bandwidth (CIK). 1000 - * Used for display watermark bandwidth calculations 1001 - * Returns true if the display fits, false if not. 1002 - */ 1003 - static bool dce_v11_0_average_bandwidth_vs_available_bandwidth(struct dce10_wm_params *wm) 1004 - { 1005 - if (dce_v11_0_average_bandwidth(wm) <= 1006 - (dce_v11_0_available_bandwidth(wm) / wm->num_heads)) 1007 - return true; 1008 - else 1009 - return false; 1010 - } 1011 - 1012 - /** 1013 - * dce_v11_0_check_latency_hiding - check latency hiding 1014 - * 1015 - * @wm: watermark calculation data 1016 - * 1017 - * Check latency hiding (CIK). 1018 - * Used for display watermark bandwidth calculations 1019 - * Returns true if the display fits, false if not. 1020 - */ 1021 - static bool dce_v11_0_check_latency_hiding(struct dce10_wm_params *wm) 1022 - { 1023 - u32 lb_partitions = wm->lb_size / wm->src_width; 1024 - u32 line_time = wm->active_time + wm->blank_time; 1025 - u32 latency_tolerant_lines; 1026 - u32 latency_hiding; 1027 - fixed20_12 a; 1028 - 1029 - a.full = dfixed_const(1); 1030 - if (wm->vsc.full > a.full) 1031 - latency_tolerant_lines = 1; 1032 - else { 1033 - if (lb_partitions <= (wm->vtaps + 1)) 1034 - latency_tolerant_lines = 1; 1035 - else 1036 - latency_tolerant_lines = 2; 1037 - } 1038 - 1039 - latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time); 1040 - 1041 - if (dce_v11_0_latency_watermark(wm) <= latency_hiding) 1042 - return true; 1043 - else 1044 - return false; 1045 - } 1046 - 1047 - /** 1048 - * dce_v11_0_program_watermarks - program display watermarks 1049 - * 1050 - * @adev: amdgpu_device pointer 1051 - * @amdgpu_crtc: the selected display controller 1052 - * @lb_size: line buffer size 1053 - * @num_heads: number of display controllers in use 1054 - * 1055 - * Calculate and program the display watermarks for the 1056 - * selected display controller (CIK). 1057 - */ 1058 - static void dce_v11_0_program_watermarks(struct amdgpu_device *adev, 1059 - struct amdgpu_crtc *amdgpu_crtc, 1060 - u32 lb_size, u32 num_heads) 1061 - { 1062 - struct drm_display_mode *mode = &amdgpu_crtc->base.mode; 1063 - struct dce10_wm_params wm_low, wm_high; 1064 - u32 active_time; 1065 - u32 line_time = 0; 1066 - u32 latency_watermark_a = 0, latency_watermark_b = 0; 1067 - u32 tmp, wm_mask, lb_vblank_lead_lines = 0; 1068 - 1069 - if (amdgpu_crtc->base.enabled && num_heads && mode) { 1070 - active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000, 1071 - (u32)mode->clock); 1072 - line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000, 1073 - (u32)mode->clock); 1074 - line_time = min_t(u32, line_time, 65535); 1075 - 1076 - /* watermark for high clocks */ 1077 - if (adev->pm.dpm_enabled) { 1078 - wm_high.yclk = 1079 - amdgpu_dpm_get_mclk(adev, false) * 10; 1080 - wm_high.sclk = 1081 - amdgpu_dpm_get_sclk(adev, false) * 10; 1082 - } else { 1083 - wm_high.yclk = adev->pm.current_mclk * 10; 1084 - wm_high.sclk = adev->pm.current_sclk * 10; 1085 - } 1086 - 1087 - wm_high.disp_clk = mode->clock; 1088 - wm_high.src_width = mode->crtc_hdisplay; 1089 - wm_high.active_time = active_time; 1090 - wm_high.blank_time = line_time - wm_high.active_time; 1091 - wm_high.interlaced = false; 1092 - if (mode->flags & DRM_MODE_FLAG_INTERLACE) 1093 - wm_high.interlaced = true; 1094 - wm_high.vsc = amdgpu_crtc->vsc; 1095 - wm_high.vtaps = 1; 1096 - if (amdgpu_crtc->rmx_type != RMX_OFF) 1097 - wm_high.vtaps = 2; 1098 - wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */ 1099 - wm_high.lb_size = lb_size; 1100 - wm_high.dram_channels = cik_get_number_of_dram_channels(adev); 1101 - wm_high.num_heads = num_heads; 1102 - 1103 - /* set for high clocks */ 1104 - latency_watermark_a = min_t(u32, dce_v11_0_latency_watermark(&wm_high), 65535); 1105 - 1106 - /* possibly force display priority to high */ 1107 - /* should really do this at mode validation time... */ 1108 - if (!dce_v11_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) || 1109 - !dce_v11_0_average_bandwidth_vs_available_bandwidth(&wm_high) || 1110 - !dce_v11_0_check_latency_hiding(&wm_high) || 1111 - (adev->mode_info.disp_priority == 2)) { 1112 - DRM_DEBUG_KMS("force priority to high\n"); 1113 - } 1114 - 1115 - /* watermark for low clocks */ 1116 - if (adev->pm.dpm_enabled) { 1117 - wm_low.yclk = 1118 - amdgpu_dpm_get_mclk(adev, true) * 10; 1119 - wm_low.sclk = 1120 - amdgpu_dpm_get_sclk(adev, true) * 10; 1121 - } else { 1122 - wm_low.yclk = adev->pm.current_mclk * 10; 1123 - wm_low.sclk = adev->pm.current_sclk * 10; 1124 - } 1125 - 1126 - wm_low.disp_clk = mode->clock; 1127 - wm_low.src_width = mode->crtc_hdisplay; 1128 - wm_low.active_time = active_time; 1129 - wm_low.blank_time = line_time - wm_low.active_time; 1130 - wm_low.interlaced = false; 1131 - if (mode->flags & DRM_MODE_FLAG_INTERLACE) 1132 - wm_low.interlaced = true; 1133 - wm_low.vsc = amdgpu_crtc->vsc; 1134 - wm_low.vtaps = 1; 1135 - if (amdgpu_crtc->rmx_type != RMX_OFF) 1136 - wm_low.vtaps = 2; 1137 - wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */ 1138 - wm_low.lb_size = lb_size; 1139 - wm_low.dram_channels = cik_get_number_of_dram_channels(adev); 1140 - wm_low.num_heads = num_heads; 1141 - 1142 - /* set for low clocks */ 1143 - latency_watermark_b = min_t(u32, dce_v11_0_latency_watermark(&wm_low), 65535); 1144 - 1145 - /* possibly force display priority to high */ 1146 - /* should really do this at mode validation time... */ 1147 - if (!dce_v11_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) || 1148 - !dce_v11_0_average_bandwidth_vs_available_bandwidth(&wm_low) || 1149 - !dce_v11_0_check_latency_hiding(&wm_low) || 1150 - (adev->mode_info.disp_priority == 2)) { 1151 - DRM_DEBUG_KMS("force priority to high\n"); 1152 - } 1153 - lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay); 1154 - } 1155 - 1156 - /* select wm A */ 1157 - wm_mask = RREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset); 1158 - tmp = REG_SET_FIELD(wm_mask, DPG_WATERMARK_MASK_CONTROL, URGENCY_WATERMARK_MASK, 1); 1159 - WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, tmp); 1160 - tmp = RREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset); 1161 - tmp = REG_SET_FIELD(tmp, DPG_PIPE_URGENCY_CONTROL, URGENCY_LOW_WATERMARK, latency_watermark_a); 1162 - tmp = REG_SET_FIELD(tmp, DPG_PIPE_URGENCY_CONTROL, URGENCY_HIGH_WATERMARK, line_time); 1163 - WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset, tmp); 1164 - /* select wm B */ 1165 - tmp = REG_SET_FIELD(wm_mask, DPG_WATERMARK_MASK_CONTROL, URGENCY_WATERMARK_MASK, 2); 1166 - WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, tmp); 1167 - tmp = RREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset); 1168 - tmp = REG_SET_FIELD(tmp, DPG_PIPE_URGENCY_CONTROL, URGENCY_LOW_WATERMARK, latency_watermark_b); 1169 - tmp = REG_SET_FIELD(tmp, DPG_PIPE_URGENCY_CONTROL, URGENCY_HIGH_WATERMARK, line_time); 1170 - WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset, tmp); 1171 - /* restore original selection */ 1172 - WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, wm_mask); 1173 - 1174 - /* save values for DPM */ 1175 - amdgpu_crtc->line_time = line_time; 1176 - 1177 - /* Save number of lines the linebuffer leads before the scanout */ 1178 - amdgpu_crtc->lb_vblank_lead_lines = lb_vblank_lead_lines; 1179 - } 1180 - 1181 - /** 1182 - * dce_v11_0_bandwidth_update - program display watermarks 1183 - * 1184 - * @adev: amdgpu_device pointer 1185 - * 1186 - * Calculate and program the display watermarks and line 1187 - * buffer allocation (CIK). 1188 - */ 1189 - static void dce_v11_0_bandwidth_update(struct amdgpu_device *adev) 1190 - { 1191 - struct drm_display_mode *mode = NULL; 1192 - u32 num_heads = 0, lb_size; 1193 - int i; 1194 - 1195 - amdgpu_display_update_priority(adev); 1196 - 1197 - for (i = 0; i < adev->mode_info.num_crtc; i++) { 1198 - if (adev->mode_info.crtcs[i]->base.enabled) 1199 - num_heads++; 1200 - } 1201 - for (i = 0; i < adev->mode_info.num_crtc; i++) { 1202 - mode = &adev->mode_info.crtcs[i]->base.mode; 1203 - lb_size = dce_v11_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i], mode); 1204 - dce_v11_0_program_watermarks(adev, adev->mode_info.crtcs[i], 1205 - lb_size, num_heads); 1206 - } 1207 - } 1208 - 1209 - static void dce_v11_0_audio_get_connected_pins(struct amdgpu_device *adev) 1210 - { 1211 - int i; 1212 - u32 offset, tmp; 1213 - 1214 - for (i = 0; i < adev->mode_info.audio.num_pins; i++) { 1215 - offset = adev->mode_info.audio.pin[i].offset; 1216 - tmp = RREG32_AUDIO_ENDPT(offset, 1217 - ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT); 1218 - if (((tmp & 1219 - AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY_MASK) >> 1220 - AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY__SHIFT) == 1) 1221 - adev->mode_info.audio.pin[i].connected = false; 1222 - else 1223 - adev->mode_info.audio.pin[i].connected = true; 1224 - } 1225 - } 1226 - 1227 - static struct amdgpu_audio_pin *dce_v11_0_audio_get_pin(struct amdgpu_device *adev) 1228 - { 1229 - int i; 1230 - 1231 - dce_v11_0_audio_get_connected_pins(adev); 1232 - 1233 - for (i = 0; i < adev->mode_info.audio.num_pins; i++) { 1234 - if (adev->mode_info.audio.pin[i].connected) 1235 - return &adev->mode_info.audio.pin[i]; 1236 - } 1237 - DRM_ERROR("No connected audio pins found!\n"); 1238 - return NULL; 1239 - } 1240 - 1241 - static void dce_v11_0_afmt_audio_select_pin(struct drm_encoder *encoder) 1242 - { 1243 - struct amdgpu_device *adev = drm_to_adev(encoder->dev); 1244 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1245 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1246 - u32 tmp; 1247 - 1248 - if (!dig || !dig->afmt || !dig->afmt->pin) 1249 - return; 1250 - 1251 - tmp = RREG32(mmAFMT_AUDIO_SRC_CONTROL + dig->afmt->offset); 1252 - tmp = REG_SET_FIELD(tmp, AFMT_AUDIO_SRC_CONTROL, AFMT_AUDIO_SRC_SELECT, dig->afmt->pin->id); 1253 - WREG32(mmAFMT_AUDIO_SRC_CONTROL + dig->afmt->offset, tmp); 1254 - } 1255 - 1256 - static void dce_v11_0_audio_write_latency_fields(struct drm_encoder *encoder, 1257 - struct drm_display_mode *mode) 1258 - { 1259 - struct drm_device *dev = encoder->dev; 1260 - struct amdgpu_device *adev = drm_to_adev(dev); 1261 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1262 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1263 - struct drm_connector *connector; 1264 - struct drm_connector_list_iter iter; 1265 - struct amdgpu_connector *amdgpu_connector = NULL; 1266 - u32 tmp; 1267 - int interlace = 0; 1268 - 1269 - if (!dig || !dig->afmt || !dig->afmt->pin) 1270 - return; 1271 - 1272 - drm_connector_list_iter_begin(dev, &iter); 1273 - drm_for_each_connector_iter(connector, &iter) { 1274 - if (connector->encoder == encoder) { 1275 - amdgpu_connector = to_amdgpu_connector(connector); 1276 - break; 1277 - } 1278 - } 1279 - drm_connector_list_iter_end(&iter); 1280 - 1281 - if (!amdgpu_connector) { 1282 - DRM_ERROR("Couldn't find encoder's connector\n"); 1283 - return; 1284 - } 1285 - 1286 - if (mode->flags & DRM_MODE_FLAG_INTERLACE) 1287 - interlace = 1; 1288 - if (connector->latency_present[interlace]) { 1289 - tmp = REG_SET_FIELD(0, AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, 1290 - VIDEO_LIPSYNC, connector->video_latency[interlace]); 1291 - tmp = REG_SET_FIELD(0, AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, 1292 - AUDIO_LIPSYNC, connector->audio_latency[interlace]); 1293 - } else { 1294 - tmp = REG_SET_FIELD(0, AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, 1295 - VIDEO_LIPSYNC, 0); 1296 - tmp = REG_SET_FIELD(0, AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, 1297 - AUDIO_LIPSYNC, 0); 1298 - } 1299 - WREG32_AUDIO_ENDPT(dig->afmt->pin->offset, 1300 - ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, tmp); 1301 - } 1302 - 1303 - static void dce_v11_0_audio_write_speaker_allocation(struct drm_encoder *encoder) 1304 - { 1305 - struct drm_device *dev = encoder->dev; 1306 - struct amdgpu_device *adev = drm_to_adev(dev); 1307 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1308 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1309 - struct drm_connector *connector; 1310 - struct drm_connector_list_iter iter; 1311 - struct amdgpu_connector *amdgpu_connector = NULL; 1312 - u32 tmp; 1313 - u8 *sadb = NULL; 1314 - int sad_count; 1315 - 1316 - if (!dig || !dig->afmt || !dig->afmt->pin) 1317 - return; 1318 - 1319 - drm_connector_list_iter_begin(dev, &iter); 1320 - drm_for_each_connector_iter(connector, &iter) { 1321 - if (connector->encoder == encoder) { 1322 - amdgpu_connector = to_amdgpu_connector(connector); 1323 - break; 1324 - } 1325 - } 1326 - drm_connector_list_iter_end(&iter); 1327 - 1328 - if (!amdgpu_connector) { 1329 - DRM_ERROR("Couldn't find encoder's connector\n"); 1330 - return; 1331 - } 1332 - 1333 - sad_count = drm_edid_to_speaker_allocation(amdgpu_connector->edid, &sadb); 1334 - if (sad_count < 0) { 1335 - DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count); 1336 - sad_count = 0; 1337 - } 1338 - 1339 - /* program the speaker allocation */ 1340 - tmp = RREG32_AUDIO_ENDPT(dig->afmt->pin->offset, 1341 - ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER); 1342 - tmp = REG_SET_FIELD(tmp, AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, 1343 - DP_CONNECTION, 0); 1344 - /* set HDMI mode */ 1345 - tmp = REG_SET_FIELD(tmp, AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, 1346 - HDMI_CONNECTION, 1); 1347 - if (sad_count) 1348 - tmp = REG_SET_FIELD(tmp, AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, 1349 - SPEAKER_ALLOCATION, sadb[0]); 1350 - else 1351 - tmp = REG_SET_FIELD(tmp, AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, 1352 - SPEAKER_ALLOCATION, 5); /* stereo */ 1353 - WREG32_AUDIO_ENDPT(dig->afmt->pin->offset, 1354 - ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp); 1355 - 1356 - kfree(sadb); 1357 - } 1358 - 1359 - static void dce_v11_0_audio_write_sad_regs(struct drm_encoder *encoder) 1360 - { 1361 - struct drm_device *dev = encoder->dev; 1362 - struct amdgpu_device *adev = drm_to_adev(dev); 1363 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1364 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1365 - struct drm_connector *connector; 1366 - struct drm_connector_list_iter iter; 1367 - struct amdgpu_connector *amdgpu_connector = NULL; 1368 - struct cea_sad *sads; 1369 - int i, sad_count; 1370 - 1371 - static const u16 eld_reg_to_type[][2] = { 1372 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM }, 1373 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 }, 1374 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 }, 1375 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 }, 1376 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 }, 1377 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC }, 1378 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS }, 1379 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC }, 1380 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 }, 1381 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD }, 1382 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP }, 1383 - { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO }, 1384 - }; 1385 - 1386 - if (!dig || !dig->afmt || !dig->afmt->pin) 1387 - return; 1388 - 1389 - drm_connector_list_iter_begin(dev, &iter); 1390 - drm_for_each_connector_iter(connector, &iter) { 1391 - if (connector->encoder == encoder) { 1392 - amdgpu_connector = to_amdgpu_connector(connector); 1393 - break; 1394 - } 1395 - } 1396 - drm_connector_list_iter_end(&iter); 1397 - 1398 - if (!amdgpu_connector) { 1399 - DRM_ERROR("Couldn't find encoder's connector\n"); 1400 - return; 1401 - } 1402 - 1403 - sad_count = drm_edid_to_sad(amdgpu_connector->edid, &sads); 1404 - if (sad_count < 0) 1405 - DRM_ERROR("Couldn't read SADs: %d\n", sad_count); 1406 - if (sad_count <= 0) 1407 - return; 1408 - BUG_ON(!sads); 1409 - 1410 - for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) { 1411 - u32 tmp = 0; 1412 - u8 stereo_freqs = 0; 1413 - int max_channels = -1; 1414 - int j; 1415 - 1416 - for (j = 0; j < sad_count; j++) { 1417 - struct cea_sad *sad = &sads[j]; 1418 - 1419 - if (sad->format == eld_reg_to_type[i][1]) { 1420 - if (sad->channels > max_channels) { 1421 - tmp = REG_SET_FIELD(tmp, AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, 1422 - MAX_CHANNELS, sad->channels); 1423 - tmp = REG_SET_FIELD(tmp, AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, 1424 - DESCRIPTOR_BYTE_2, sad->byte2); 1425 - tmp = REG_SET_FIELD(tmp, AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, 1426 - SUPPORTED_FREQUENCIES, sad->freq); 1427 - max_channels = sad->channels; 1428 - } 1429 - 1430 - if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM) 1431 - stereo_freqs |= sad->freq; 1432 - else 1433 - break; 1434 - } 1435 - } 1436 - 1437 - tmp = REG_SET_FIELD(tmp, AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, 1438 - SUPPORTED_FREQUENCIES_STEREO, stereo_freqs); 1439 - WREG32_AUDIO_ENDPT(dig->afmt->pin->offset, eld_reg_to_type[i][0], tmp); 1440 - } 1441 - 1442 - kfree(sads); 1443 - } 1444 - 1445 - static void dce_v11_0_audio_enable(struct amdgpu_device *adev, 1446 - struct amdgpu_audio_pin *pin, 1447 - bool enable) 1448 - { 1449 - if (!pin) 1450 - return; 1451 - 1452 - WREG32_AUDIO_ENDPT(pin->offset, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL, 1453 - enable ? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK : 0); 1454 - } 1455 - 1456 - static const u32 pin_offsets[] = 1457 - { 1458 - AUD0_REGISTER_OFFSET, 1459 - AUD1_REGISTER_OFFSET, 1460 - AUD2_REGISTER_OFFSET, 1461 - AUD3_REGISTER_OFFSET, 1462 - AUD4_REGISTER_OFFSET, 1463 - AUD5_REGISTER_OFFSET, 1464 - AUD6_REGISTER_OFFSET, 1465 - AUD7_REGISTER_OFFSET, 1466 - }; 1467 - 1468 - static int dce_v11_0_audio_init(struct amdgpu_device *adev) 1469 - { 1470 - int i; 1471 - 1472 - if (!amdgpu_audio) 1473 - return 0; 1474 - 1475 - adev->mode_info.audio.enabled = true; 1476 - 1477 - switch (adev->asic_type) { 1478 - case CHIP_CARRIZO: 1479 - case CHIP_STONEY: 1480 - adev->mode_info.audio.num_pins = 7; 1481 - break; 1482 - case CHIP_POLARIS10: 1483 - case CHIP_VEGAM: 1484 - adev->mode_info.audio.num_pins = 8; 1485 - break; 1486 - case CHIP_POLARIS11: 1487 - case CHIP_POLARIS12: 1488 - adev->mode_info.audio.num_pins = 6; 1489 - break; 1490 - default: 1491 - return -EINVAL; 1492 - } 1493 - 1494 - for (i = 0; i < adev->mode_info.audio.num_pins; i++) { 1495 - adev->mode_info.audio.pin[i].channels = -1; 1496 - adev->mode_info.audio.pin[i].rate = -1; 1497 - adev->mode_info.audio.pin[i].bits_per_sample = -1; 1498 - adev->mode_info.audio.pin[i].status_bits = 0; 1499 - adev->mode_info.audio.pin[i].category_code = 0; 1500 - adev->mode_info.audio.pin[i].connected = false; 1501 - adev->mode_info.audio.pin[i].offset = pin_offsets[i]; 1502 - adev->mode_info.audio.pin[i].id = i; 1503 - /* disable audio. it will be set up later */ 1504 - /* XXX remove once we switch to ip funcs */ 1505 - dce_v11_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); 1506 - } 1507 - 1508 - return 0; 1509 - } 1510 - 1511 - static void dce_v11_0_audio_fini(struct amdgpu_device *adev) 1512 - { 1513 - if (!amdgpu_audio) 1514 - return; 1515 - 1516 - if (!adev->mode_info.audio.enabled) 1517 - return; 1518 - 1519 - adev->mode_info.audio.enabled = false; 1520 - } 1521 - 1522 - /* 1523 - * update the N and CTS parameters for a given pixel clock rate 1524 - */ 1525 - static void dce_v11_0_afmt_update_ACR(struct drm_encoder *encoder, uint32_t clock) 1526 - { 1527 - struct drm_device *dev = encoder->dev; 1528 - struct amdgpu_device *adev = drm_to_adev(dev); 1529 - struct amdgpu_afmt_acr acr = amdgpu_afmt_acr(clock); 1530 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1531 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1532 - u32 tmp; 1533 - 1534 - tmp = RREG32(mmHDMI_ACR_32_0 + dig->afmt->offset); 1535 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_32_0, HDMI_ACR_CTS_32, acr.cts_32khz); 1536 - WREG32(mmHDMI_ACR_32_0 + dig->afmt->offset, tmp); 1537 - tmp = RREG32(mmHDMI_ACR_32_1 + dig->afmt->offset); 1538 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_32_1, HDMI_ACR_N_32, acr.n_32khz); 1539 - WREG32(mmHDMI_ACR_32_1 + dig->afmt->offset, tmp); 1540 - 1541 - tmp = RREG32(mmHDMI_ACR_44_0 + dig->afmt->offset); 1542 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_44_0, HDMI_ACR_CTS_44, acr.cts_44_1khz); 1543 - WREG32(mmHDMI_ACR_44_0 + dig->afmt->offset, tmp); 1544 - tmp = RREG32(mmHDMI_ACR_44_1 + dig->afmt->offset); 1545 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_44_1, HDMI_ACR_N_44, acr.n_44_1khz); 1546 - WREG32(mmHDMI_ACR_44_1 + dig->afmt->offset, tmp); 1547 - 1548 - tmp = RREG32(mmHDMI_ACR_48_0 + dig->afmt->offset); 1549 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_48_0, HDMI_ACR_CTS_48, acr.cts_48khz); 1550 - WREG32(mmHDMI_ACR_48_0 + dig->afmt->offset, tmp); 1551 - tmp = RREG32(mmHDMI_ACR_48_1 + dig->afmt->offset); 1552 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_48_1, HDMI_ACR_N_48, acr.n_48khz); 1553 - WREG32(mmHDMI_ACR_48_1 + dig->afmt->offset, tmp); 1554 - 1555 - } 1556 - 1557 - /* 1558 - * build a HDMI Video Info Frame 1559 - */ 1560 - static void dce_v11_0_afmt_update_avi_infoframe(struct drm_encoder *encoder, 1561 - void *buffer, size_t size) 1562 - { 1563 - struct drm_device *dev = encoder->dev; 1564 - struct amdgpu_device *adev = drm_to_adev(dev); 1565 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1566 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1567 - uint8_t *frame = buffer + 3; 1568 - uint8_t *header = buffer; 1569 - 1570 - WREG32(mmAFMT_AVI_INFO0 + dig->afmt->offset, 1571 - frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24)); 1572 - WREG32(mmAFMT_AVI_INFO1 + dig->afmt->offset, 1573 - frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24)); 1574 - WREG32(mmAFMT_AVI_INFO2 + dig->afmt->offset, 1575 - frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); 1576 - WREG32(mmAFMT_AVI_INFO3 + dig->afmt->offset, 1577 - frame[0xC] | (frame[0xD] << 8) | (header[1] << 24)); 1578 - } 1579 - 1580 - static void dce_v11_0_audio_set_dto(struct drm_encoder *encoder, u32 clock) 1581 - { 1582 - struct drm_device *dev = encoder->dev; 1583 - struct amdgpu_device *adev = drm_to_adev(dev); 1584 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1585 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1586 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc); 1587 - u32 dto_phase = 24 * 1000; 1588 - u32 dto_modulo = clock; 1589 - u32 tmp; 1590 - 1591 - if (!dig || !dig->afmt) 1592 - return; 1593 - 1594 - /* XXX two dtos; generally use dto0 for hdmi */ 1595 - /* Express [24MHz / target pixel clock] as an exact rational 1596 - * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE 1597 - * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator 1598 - */ 1599 - tmp = RREG32(mmDCCG_AUDIO_DTO_SOURCE); 1600 - tmp = REG_SET_FIELD(tmp, DCCG_AUDIO_DTO_SOURCE, DCCG_AUDIO_DTO0_SOURCE_SEL, 1601 - amdgpu_crtc->crtc_id); 1602 - WREG32(mmDCCG_AUDIO_DTO_SOURCE, tmp); 1603 - WREG32(mmDCCG_AUDIO_DTO0_PHASE, dto_phase); 1604 - WREG32(mmDCCG_AUDIO_DTO0_MODULE, dto_modulo); 1605 - } 1606 - 1607 - /* 1608 - * update the info frames with the data from the current display mode 1609 - */ 1610 - static void dce_v11_0_afmt_setmode(struct drm_encoder *encoder, 1611 - struct drm_display_mode *mode) 1612 - { 1613 - struct drm_device *dev = encoder->dev; 1614 - struct amdgpu_device *adev = drm_to_adev(dev); 1615 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1616 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1617 - struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder); 1618 - u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; 1619 - struct hdmi_avi_infoframe frame; 1620 - ssize_t err; 1621 - u32 tmp; 1622 - int bpc = 8; 1623 - 1624 - if (!dig || !dig->afmt) 1625 - return; 1626 - 1627 - /* Silent, r600_hdmi_enable will raise WARN for us */ 1628 - if (!dig->afmt->enabled) 1629 - return; 1630 - 1631 - /* hdmi deep color mode general control packets setup, if bpc > 8 */ 1632 - if (encoder->crtc) { 1633 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc); 1634 - bpc = amdgpu_crtc->bpc; 1635 - } 1636 - 1637 - /* disable audio prior to setting up hw */ 1638 - dig->afmt->pin = dce_v11_0_audio_get_pin(adev); 1639 - dce_v11_0_audio_enable(adev, dig->afmt->pin, false); 1640 - 1641 - dce_v11_0_audio_set_dto(encoder, mode->clock); 1642 - 1643 - tmp = RREG32(mmHDMI_VBI_PACKET_CONTROL + dig->afmt->offset); 1644 - tmp = REG_SET_FIELD(tmp, HDMI_VBI_PACKET_CONTROL, HDMI_NULL_SEND, 1); 1645 - WREG32(mmHDMI_VBI_PACKET_CONTROL + dig->afmt->offset, tmp); /* send null packets when required */ 1646 - 1647 - WREG32(mmAFMT_AUDIO_CRC_CONTROL + dig->afmt->offset, 0x1000); 1648 - 1649 - tmp = RREG32(mmHDMI_CONTROL + dig->afmt->offset); 1650 - switch (bpc) { 1651 - case 0: 1652 - case 6: 1653 - case 8: 1654 - case 16: 1655 - default: 1656 - tmp = REG_SET_FIELD(tmp, HDMI_CONTROL, HDMI_DEEP_COLOR_ENABLE, 0); 1657 - tmp = REG_SET_FIELD(tmp, HDMI_CONTROL, HDMI_DEEP_COLOR_DEPTH, 0); 1658 - DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n", 1659 - connector->name, bpc); 1660 - break; 1661 - case 10: 1662 - tmp = REG_SET_FIELD(tmp, HDMI_CONTROL, HDMI_DEEP_COLOR_ENABLE, 1); 1663 - tmp = REG_SET_FIELD(tmp, HDMI_CONTROL, HDMI_DEEP_COLOR_DEPTH, 1); 1664 - DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n", 1665 - connector->name); 1666 - break; 1667 - case 12: 1668 - tmp = REG_SET_FIELD(tmp, HDMI_CONTROL, HDMI_DEEP_COLOR_ENABLE, 1); 1669 - tmp = REG_SET_FIELD(tmp, HDMI_CONTROL, HDMI_DEEP_COLOR_DEPTH, 2); 1670 - DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n", 1671 - connector->name); 1672 - break; 1673 - } 1674 - WREG32(mmHDMI_CONTROL + dig->afmt->offset, tmp); 1675 - 1676 - tmp = RREG32(mmHDMI_VBI_PACKET_CONTROL + dig->afmt->offset); 1677 - tmp = REG_SET_FIELD(tmp, HDMI_VBI_PACKET_CONTROL, HDMI_NULL_SEND, 1); /* send null packets when required */ 1678 - tmp = REG_SET_FIELD(tmp, HDMI_VBI_PACKET_CONTROL, HDMI_GC_SEND, 1); /* send general control packets */ 1679 - tmp = REG_SET_FIELD(tmp, HDMI_VBI_PACKET_CONTROL, HDMI_GC_CONT, 1); /* send general control packets every frame */ 1680 - WREG32(mmHDMI_VBI_PACKET_CONTROL + dig->afmt->offset, tmp); 1681 - 1682 - tmp = RREG32(mmHDMI_INFOFRAME_CONTROL0 + dig->afmt->offset); 1683 - /* enable audio info frames (frames won't be set until audio is enabled) */ 1684 - tmp = REG_SET_FIELD(tmp, HDMI_INFOFRAME_CONTROL0, HDMI_AUDIO_INFO_SEND, 1); 1685 - /* required for audio info values to be updated */ 1686 - tmp = REG_SET_FIELD(tmp, HDMI_INFOFRAME_CONTROL0, HDMI_AUDIO_INFO_CONT, 1); 1687 - WREG32(mmHDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, tmp); 1688 - 1689 - tmp = RREG32(mmAFMT_INFOFRAME_CONTROL0 + dig->afmt->offset); 1690 - /* required for audio info values to be updated */ 1691 - tmp = REG_SET_FIELD(tmp, AFMT_INFOFRAME_CONTROL0, AFMT_AUDIO_INFO_UPDATE, 1); 1692 - WREG32(mmAFMT_INFOFRAME_CONTROL0 + dig->afmt->offset, tmp); 1693 - 1694 - tmp = RREG32(mmHDMI_INFOFRAME_CONTROL1 + dig->afmt->offset); 1695 - /* anything other than 0 */ 1696 - tmp = REG_SET_FIELD(tmp, HDMI_INFOFRAME_CONTROL1, HDMI_AUDIO_INFO_LINE, 2); 1697 - WREG32(mmHDMI_INFOFRAME_CONTROL1 + dig->afmt->offset, tmp); 1698 - 1699 - WREG32(mmHDMI_GC + dig->afmt->offset, 0); /* unset HDMI_GC_AVMUTE */ 1700 - 1701 - tmp = RREG32(mmHDMI_AUDIO_PACKET_CONTROL + dig->afmt->offset); 1702 - /* set the default audio delay */ 1703 - tmp = REG_SET_FIELD(tmp, HDMI_AUDIO_PACKET_CONTROL, HDMI_AUDIO_DELAY_EN, 1); 1704 - /* should be suffient for all audio modes and small enough for all hblanks */ 1705 - tmp = REG_SET_FIELD(tmp, HDMI_AUDIO_PACKET_CONTROL, HDMI_AUDIO_PACKETS_PER_LINE, 3); 1706 - WREG32(mmHDMI_AUDIO_PACKET_CONTROL + dig->afmt->offset, tmp); 1707 - 1708 - tmp = RREG32(mmAFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset); 1709 - /* allow 60958 channel status fields to be updated */ 1710 - tmp = REG_SET_FIELD(tmp, AFMT_AUDIO_PACKET_CONTROL, AFMT_60958_CS_UPDATE, 1); 1711 - WREG32(mmAFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, tmp); 1712 - 1713 - tmp = RREG32(mmHDMI_ACR_PACKET_CONTROL + dig->afmt->offset); 1714 - if (bpc > 8) 1715 - /* clear SW CTS value */ 1716 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_PACKET_CONTROL, HDMI_ACR_SOURCE, 0); 1717 - else 1718 - /* select SW CTS value */ 1719 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_PACKET_CONTROL, HDMI_ACR_SOURCE, 1); 1720 - /* allow hw to sent ACR packets when required */ 1721 - tmp = REG_SET_FIELD(tmp, HDMI_ACR_PACKET_CONTROL, HDMI_ACR_AUTO_SEND, 1); 1722 - WREG32(mmHDMI_ACR_PACKET_CONTROL + dig->afmt->offset, tmp); 1723 - 1724 - dce_v11_0_afmt_update_ACR(encoder, mode->clock); 1725 - 1726 - tmp = RREG32(mmAFMT_60958_0 + dig->afmt->offset); 1727 - tmp = REG_SET_FIELD(tmp, AFMT_60958_0, AFMT_60958_CS_CHANNEL_NUMBER_L, 1); 1728 - WREG32(mmAFMT_60958_0 + dig->afmt->offset, tmp); 1729 - 1730 - tmp = RREG32(mmAFMT_60958_1 + dig->afmt->offset); 1731 - tmp = REG_SET_FIELD(tmp, AFMT_60958_1, AFMT_60958_CS_CHANNEL_NUMBER_R, 2); 1732 - WREG32(mmAFMT_60958_1 + dig->afmt->offset, tmp); 1733 - 1734 - tmp = RREG32(mmAFMT_60958_2 + dig->afmt->offset); 1735 - tmp = REG_SET_FIELD(tmp, AFMT_60958_2, AFMT_60958_CS_CHANNEL_NUMBER_2, 3); 1736 - tmp = REG_SET_FIELD(tmp, AFMT_60958_2, AFMT_60958_CS_CHANNEL_NUMBER_3, 4); 1737 - tmp = REG_SET_FIELD(tmp, AFMT_60958_2, AFMT_60958_CS_CHANNEL_NUMBER_4, 5); 1738 - tmp = REG_SET_FIELD(tmp, AFMT_60958_2, AFMT_60958_CS_CHANNEL_NUMBER_5, 6); 1739 - tmp = REG_SET_FIELD(tmp, AFMT_60958_2, AFMT_60958_CS_CHANNEL_NUMBER_6, 7); 1740 - tmp = REG_SET_FIELD(tmp, AFMT_60958_2, AFMT_60958_CS_CHANNEL_NUMBER_7, 8); 1741 - WREG32(mmAFMT_60958_2 + dig->afmt->offset, tmp); 1742 - 1743 - dce_v11_0_audio_write_speaker_allocation(encoder); 1744 - 1745 - WREG32(mmAFMT_AUDIO_PACKET_CONTROL2 + dig->afmt->offset, 1746 - (0xff << AFMT_AUDIO_PACKET_CONTROL2__AFMT_AUDIO_CHANNEL_ENABLE__SHIFT)); 1747 - 1748 - dce_v11_0_afmt_audio_select_pin(encoder); 1749 - dce_v11_0_audio_write_sad_regs(encoder); 1750 - dce_v11_0_audio_write_latency_fields(encoder, mode); 1751 - 1752 - err = drm_hdmi_avi_infoframe_from_display_mode(&frame, connector, mode); 1753 - if (err < 0) { 1754 - DRM_ERROR("failed to setup AVI infoframe: %zd\n", err); 1755 - return; 1756 - } 1757 - 1758 - err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); 1759 - if (err < 0) { 1760 - DRM_ERROR("failed to pack AVI infoframe: %zd\n", err); 1761 - return; 1762 - } 1763 - 1764 - dce_v11_0_afmt_update_avi_infoframe(encoder, buffer, sizeof(buffer)); 1765 - 1766 - tmp = RREG32(mmHDMI_INFOFRAME_CONTROL0 + dig->afmt->offset); 1767 - /* enable AVI info frames */ 1768 - tmp = REG_SET_FIELD(tmp, HDMI_INFOFRAME_CONTROL0, HDMI_AVI_INFO_SEND, 1); 1769 - /* required for audio info values to be updated */ 1770 - tmp = REG_SET_FIELD(tmp, HDMI_INFOFRAME_CONTROL0, HDMI_AVI_INFO_CONT, 1); 1771 - WREG32(mmHDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, tmp); 1772 - 1773 - tmp = RREG32(mmHDMI_INFOFRAME_CONTROL1 + dig->afmt->offset); 1774 - tmp = REG_SET_FIELD(tmp, HDMI_INFOFRAME_CONTROL1, HDMI_AVI_INFO_LINE, 2); 1775 - WREG32(mmHDMI_INFOFRAME_CONTROL1 + dig->afmt->offset, tmp); 1776 - 1777 - tmp = RREG32(mmAFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset); 1778 - /* send audio packets */ 1779 - tmp = REG_SET_FIELD(tmp, AFMT_AUDIO_PACKET_CONTROL, AFMT_AUDIO_SAMPLE_SEND, 1); 1780 - WREG32(mmAFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, tmp); 1781 - 1782 - WREG32(mmAFMT_RAMP_CONTROL0 + dig->afmt->offset, 0x00FFFFFF); 1783 - WREG32(mmAFMT_RAMP_CONTROL1 + dig->afmt->offset, 0x007FFFFF); 1784 - WREG32(mmAFMT_RAMP_CONTROL2 + dig->afmt->offset, 0x00000001); 1785 - WREG32(mmAFMT_RAMP_CONTROL3 + dig->afmt->offset, 0x00000001); 1786 - 1787 - /* enable audio after to setting up hw */ 1788 - dce_v11_0_audio_enable(adev, dig->afmt->pin, true); 1789 - } 1790 - 1791 - static void dce_v11_0_afmt_enable(struct drm_encoder *encoder, bool enable) 1792 - { 1793 - struct drm_device *dev = encoder->dev; 1794 - struct amdgpu_device *adev = drm_to_adev(dev); 1795 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 1796 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 1797 - 1798 - if (!dig || !dig->afmt) 1799 - return; 1800 - 1801 - /* Silent, r600_hdmi_enable will raise WARN for us */ 1802 - if (enable && dig->afmt->enabled) 1803 - return; 1804 - if (!enable && !dig->afmt->enabled) 1805 - return; 1806 - 1807 - if (!enable && dig->afmt->pin) { 1808 - dce_v11_0_audio_enable(adev, dig->afmt->pin, false); 1809 - dig->afmt->pin = NULL; 1810 - } 1811 - 1812 - dig->afmt->enabled = enable; 1813 - 1814 - DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n", 1815 - enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id); 1816 - } 1817 - 1818 - static int dce_v11_0_afmt_init(struct amdgpu_device *adev) 1819 - { 1820 - int i; 1821 - 1822 - for (i = 0; i < adev->mode_info.num_dig; i++) 1823 - adev->mode_info.afmt[i] = NULL; 1824 - 1825 - /* DCE11 has audio blocks tied to DIG encoders */ 1826 - for (i = 0; i < adev->mode_info.num_dig; i++) { 1827 - adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL); 1828 - if (adev->mode_info.afmt[i]) { 1829 - adev->mode_info.afmt[i]->offset = dig_offsets[i]; 1830 - adev->mode_info.afmt[i]->id = i; 1831 - } else { 1832 - int j; 1833 - for (j = 0; j < i; j++) { 1834 - kfree(adev->mode_info.afmt[j]); 1835 - adev->mode_info.afmt[j] = NULL; 1836 - } 1837 - return -ENOMEM; 1838 - } 1839 - } 1840 - return 0; 1841 - } 1842 - 1843 - static void dce_v11_0_afmt_fini(struct amdgpu_device *adev) 1844 - { 1845 - int i; 1846 - 1847 - for (i = 0; i < adev->mode_info.num_dig; i++) { 1848 - kfree(adev->mode_info.afmt[i]); 1849 - adev->mode_info.afmt[i] = NULL; 1850 - } 1851 - } 1852 - 1853 - static const u32 vga_control_regs[6] = 1854 - { 1855 - mmD1VGA_CONTROL, 1856 - mmD2VGA_CONTROL, 1857 - mmD3VGA_CONTROL, 1858 - mmD4VGA_CONTROL, 1859 - mmD5VGA_CONTROL, 1860 - mmD6VGA_CONTROL, 1861 - }; 1862 - 1863 - static void dce_v11_0_vga_enable(struct drm_crtc *crtc, bool enable) 1864 - { 1865 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 1866 - struct drm_device *dev = crtc->dev; 1867 - struct amdgpu_device *adev = drm_to_adev(dev); 1868 - u32 vga_control; 1869 - 1870 - vga_control = RREG32(vga_control_regs[amdgpu_crtc->crtc_id]) & ~1; 1871 - if (enable) 1872 - WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control | 1); 1873 - else 1874 - WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control); 1875 - } 1876 - 1877 - static void dce_v11_0_grph_enable(struct drm_crtc *crtc, bool enable) 1878 - { 1879 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 1880 - struct drm_device *dev = crtc->dev; 1881 - struct amdgpu_device *adev = drm_to_adev(dev); 1882 - 1883 - if (enable) 1884 - WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 1); 1885 - else 1886 - WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0); 1887 - } 1888 - 1889 - static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc, 1890 - struct drm_framebuffer *fb, 1891 - int x, int y, int atomic) 1892 - { 1893 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 1894 - struct drm_device *dev = crtc->dev; 1895 - struct amdgpu_device *adev = drm_to_adev(dev); 1896 - struct drm_framebuffer *target_fb; 1897 - struct drm_gem_object *obj; 1898 - struct amdgpu_bo *abo; 1899 - uint64_t fb_location, tiling_flags; 1900 - uint32_t fb_format, fb_pitch_pixels; 1901 - u32 fb_swap = REG_SET_FIELD(0, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, ENDIAN_NONE); 1902 - u32 pipe_config; 1903 - u32 tmp, viewport_w, viewport_h; 1904 - int r; 1905 - bool bypass_lut = false; 1906 - 1907 - /* no fb bound */ 1908 - if (!atomic && !crtc->primary->fb) { 1909 - DRM_DEBUG_KMS("No FB bound\n"); 1910 - return 0; 1911 - } 1912 - 1913 - if (atomic) 1914 - target_fb = fb; 1915 - else 1916 - target_fb = crtc->primary->fb; 1917 - 1918 - /* If atomic, assume fb object is pinned & idle & fenced and 1919 - * just update base pointers 1920 - */ 1921 - obj = target_fb->obj[0]; 1922 - abo = gem_to_amdgpu_bo(obj); 1923 - r = amdgpu_bo_reserve(abo, false); 1924 - if (unlikely(r != 0)) 1925 - return r; 1926 - 1927 - if (!atomic) { 1928 - abo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; 1929 - r = amdgpu_bo_pin(abo, AMDGPU_GEM_DOMAIN_VRAM); 1930 - if (unlikely(r != 0)) { 1931 - amdgpu_bo_unreserve(abo); 1932 - return -EINVAL; 1933 - } 1934 - } 1935 - fb_location = amdgpu_bo_gpu_offset(abo); 1936 - 1937 - amdgpu_bo_get_tiling_flags(abo, &tiling_flags); 1938 - amdgpu_bo_unreserve(abo); 1939 - 1940 - pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG); 1941 - 1942 - switch (target_fb->format->format) { 1943 - case DRM_FORMAT_C8: 1944 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 0); 1945 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 0); 1946 - break; 1947 - case DRM_FORMAT_XRGB4444: 1948 - case DRM_FORMAT_ARGB4444: 1949 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 1); 1950 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 2); 1951 - #ifdef __BIG_ENDIAN 1952 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, 1953 - ENDIAN_8IN16); 1954 - #endif 1955 - break; 1956 - case DRM_FORMAT_XRGB1555: 1957 - case DRM_FORMAT_ARGB1555: 1958 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 1); 1959 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 0); 1960 - #ifdef __BIG_ENDIAN 1961 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, 1962 - ENDIAN_8IN16); 1963 - #endif 1964 - break; 1965 - case DRM_FORMAT_BGRX5551: 1966 - case DRM_FORMAT_BGRA5551: 1967 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 1); 1968 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 5); 1969 - #ifdef __BIG_ENDIAN 1970 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, 1971 - ENDIAN_8IN16); 1972 - #endif 1973 - break; 1974 - case DRM_FORMAT_RGB565: 1975 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 1); 1976 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 1); 1977 - #ifdef __BIG_ENDIAN 1978 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, 1979 - ENDIAN_8IN16); 1980 - #endif 1981 - break; 1982 - case DRM_FORMAT_XRGB8888: 1983 - case DRM_FORMAT_ARGB8888: 1984 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 2); 1985 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 0); 1986 - #ifdef __BIG_ENDIAN 1987 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, 1988 - ENDIAN_8IN32); 1989 - #endif 1990 - break; 1991 - case DRM_FORMAT_XRGB2101010: 1992 - case DRM_FORMAT_ARGB2101010: 1993 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 2); 1994 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 1); 1995 - #ifdef __BIG_ENDIAN 1996 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, 1997 - ENDIAN_8IN32); 1998 - #endif 1999 - /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */ 2000 - bypass_lut = true; 2001 - break; 2002 - case DRM_FORMAT_BGRX1010102: 2003 - case DRM_FORMAT_BGRA1010102: 2004 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 2); 2005 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 4); 2006 - #ifdef __BIG_ENDIAN 2007 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, 2008 - ENDIAN_8IN32); 2009 - #endif 2010 - /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */ 2011 - bypass_lut = true; 2012 - break; 2013 - case DRM_FORMAT_XBGR8888: 2014 - case DRM_FORMAT_ABGR8888: 2015 - fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 2); 2016 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_FORMAT, 0); 2017 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_RED_CROSSBAR, 2); 2018 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_BLUE_CROSSBAR, 2); 2019 - #ifdef __BIG_ENDIAN 2020 - fb_swap = REG_SET_FIELD(fb_swap, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, 2021 - ENDIAN_8IN32); 2022 - #endif 2023 - break; 2024 - default: 2025 - DRM_ERROR("Unsupported screen format %p4cc\n", 2026 - &target_fb->format->format); 2027 - return -EINVAL; 2028 - } 2029 - 2030 - if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) { 2031 - unsigned bankw, bankh, mtaspect, tile_split, num_banks; 2032 - 2033 - bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH); 2034 - bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT); 2035 - mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT); 2036 - tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT); 2037 - num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS); 2038 - 2039 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_NUM_BANKS, num_banks); 2040 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE, 2041 - ARRAY_2D_TILED_THIN1); 2042 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_TILE_SPLIT, 2043 - tile_split); 2044 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_BANK_WIDTH, bankw); 2045 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_BANK_HEIGHT, bankh); 2046 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_MACRO_TILE_ASPECT, 2047 - mtaspect); 2048 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_MICRO_TILE_MODE, 2049 - ADDR_SURF_MICRO_TILING_DISPLAY); 2050 - } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) { 2051 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE, 2052 - ARRAY_1D_TILED_THIN1); 2053 - } 2054 - 2055 - fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_PIPE_CONFIG, 2056 - pipe_config); 2057 - 2058 - dce_v11_0_vga_enable(crtc, false); 2059 - 2060 - /* Make sure surface address is updated at vertical blank rather than 2061 - * horizontal blank 2062 - */ 2063 - tmp = RREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset); 2064 - tmp = REG_SET_FIELD(tmp, GRPH_FLIP_CONTROL, 2065 - GRPH_SURFACE_UPDATE_H_RETRACE_EN, 0); 2066 - WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2067 - 2068 - WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, 2069 - upper_32_bits(fb_location)); 2070 - WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, 2071 - upper_32_bits(fb_location)); 2072 - WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, 2073 - (u32)fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK); 2074 - WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, 2075 - (u32) fb_location & GRPH_SECONDARY_SURFACE_ADDRESS__GRPH_SECONDARY_SURFACE_ADDRESS_MASK); 2076 - WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format); 2077 - WREG32(mmGRPH_SWAP_CNTL + amdgpu_crtc->crtc_offset, fb_swap); 2078 - 2079 - /* 2080 - * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT 2081 - * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to 2082 - * retain the full precision throughout the pipeline. 2083 - */ 2084 - tmp = RREG32(mmGRPH_LUT_10BIT_BYPASS + amdgpu_crtc->crtc_offset); 2085 - if (bypass_lut) 2086 - tmp = REG_SET_FIELD(tmp, GRPH_LUT_10BIT_BYPASS, GRPH_LUT_10BIT_BYPASS_EN, 1); 2087 - else 2088 - tmp = REG_SET_FIELD(tmp, GRPH_LUT_10BIT_BYPASS, GRPH_LUT_10BIT_BYPASS_EN, 0); 2089 - WREG32(mmGRPH_LUT_10BIT_BYPASS + amdgpu_crtc->crtc_offset, tmp); 2090 - 2091 - if (bypass_lut) 2092 - DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n"); 2093 - 2094 - WREG32(mmGRPH_SURFACE_OFFSET_X + amdgpu_crtc->crtc_offset, 0); 2095 - WREG32(mmGRPH_SURFACE_OFFSET_Y + amdgpu_crtc->crtc_offset, 0); 2096 - WREG32(mmGRPH_X_START + amdgpu_crtc->crtc_offset, 0); 2097 - WREG32(mmGRPH_Y_START + amdgpu_crtc->crtc_offset, 0); 2098 - WREG32(mmGRPH_X_END + amdgpu_crtc->crtc_offset, target_fb->width); 2099 - WREG32(mmGRPH_Y_END + amdgpu_crtc->crtc_offset, target_fb->height); 2100 - 2101 - fb_pitch_pixels = target_fb->pitches[0] / target_fb->format->cpp[0]; 2102 - WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, fb_pitch_pixels); 2103 - 2104 - dce_v11_0_grph_enable(crtc, true); 2105 - 2106 - WREG32(mmLB_DESKTOP_HEIGHT + amdgpu_crtc->crtc_offset, 2107 - target_fb->height); 2108 - 2109 - x &= ~3; 2110 - y &= ~1; 2111 - WREG32(mmVIEWPORT_START + amdgpu_crtc->crtc_offset, 2112 - (x << 16) | y); 2113 - viewport_w = crtc->mode.hdisplay; 2114 - viewport_h = (crtc->mode.vdisplay + 1) & ~1; 2115 - WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset, 2116 - (viewport_w << 16) | viewport_h); 2117 - 2118 - /* set pageflip to happen anywhere in vblank interval */ 2119 - WREG32(mmCRTC_MASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0); 2120 - 2121 - if (!atomic && fb && fb != crtc->primary->fb) { 2122 - abo = gem_to_amdgpu_bo(fb->obj[0]); 2123 - r = amdgpu_bo_reserve(abo, true); 2124 - if (unlikely(r != 0)) 2125 - return r; 2126 - amdgpu_bo_unpin(abo); 2127 - amdgpu_bo_unreserve(abo); 2128 - } 2129 - 2130 - /* Bytes per pixel may have changed */ 2131 - dce_v11_0_bandwidth_update(adev); 2132 - 2133 - return 0; 2134 - } 2135 - 2136 - static void dce_v11_0_set_interleave(struct drm_crtc *crtc, 2137 - struct drm_display_mode *mode) 2138 - { 2139 - struct drm_device *dev = crtc->dev; 2140 - struct amdgpu_device *adev = drm_to_adev(dev); 2141 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2142 - u32 tmp; 2143 - 2144 - tmp = RREG32(mmLB_DATA_FORMAT + amdgpu_crtc->crtc_offset); 2145 - if (mode->flags & DRM_MODE_FLAG_INTERLACE) 2146 - tmp = REG_SET_FIELD(tmp, LB_DATA_FORMAT, INTERLEAVE_EN, 1); 2147 - else 2148 - tmp = REG_SET_FIELD(tmp, LB_DATA_FORMAT, INTERLEAVE_EN, 0); 2149 - WREG32(mmLB_DATA_FORMAT + amdgpu_crtc->crtc_offset, tmp); 2150 - } 2151 - 2152 - static void dce_v11_0_crtc_load_lut(struct drm_crtc *crtc) 2153 - { 2154 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2155 - struct drm_device *dev = crtc->dev; 2156 - struct amdgpu_device *adev = drm_to_adev(dev); 2157 - u16 *r, *g, *b; 2158 - int i; 2159 - u32 tmp; 2160 - 2161 - DRM_DEBUG_KMS("%d\n", amdgpu_crtc->crtc_id); 2162 - 2163 - tmp = RREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset); 2164 - tmp = REG_SET_FIELD(tmp, INPUT_CSC_CONTROL, INPUT_CSC_GRPH_MODE, 0); 2165 - WREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2166 - 2167 - tmp = RREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset); 2168 - tmp = REG_SET_FIELD(tmp, PRESCALE_GRPH_CONTROL, GRPH_PRESCALE_BYPASS, 1); 2169 - WREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2170 - 2171 - tmp = RREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset); 2172 - tmp = REG_SET_FIELD(tmp, INPUT_GAMMA_CONTROL, GRPH_INPUT_GAMMA_MODE, 0); 2173 - WREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2174 - 2175 - WREG32(mmDC_LUT_CONTROL + amdgpu_crtc->crtc_offset, 0); 2176 - 2177 - WREG32(mmDC_LUT_BLACK_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0); 2178 - WREG32(mmDC_LUT_BLACK_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0); 2179 - WREG32(mmDC_LUT_BLACK_OFFSET_RED + amdgpu_crtc->crtc_offset, 0); 2180 - 2181 - WREG32(mmDC_LUT_WHITE_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0xffff); 2182 - WREG32(mmDC_LUT_WHITE_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0xffff); 2183 - WREG32(mmDC_LUT_WHITE_OFFSET_RED + amdgpu_crtc->crtc_offset, 0xffff); 2184 - 2185 - WREG32(mmDC_LUT_RW_MODE + amdgpu_crtc->crtc_offset, 0); 2186 - WREG32(mmDC_LUT_WRITE_EN_MASK + amdgpu_crtc->crtc_offset, 0x00000007); 2187 - 2188 - WREG32(mmDC_LUT_RW_INDEX + amdgpu_crtc->crtc_offset, 0); 2189 - r = crtc->gamma_store; 2190 - g = r + crtc->gamma_size; 2191 - b = g + crtc->gamma_size; 2192 - for (i = 0; i < 256; i++) { 2193 - WREG32(mmDC_LUT_30_COLOR + amdgpu_crtc->crtc_offset, 2194 - ((*r++ & 0xffc0) << 14) | 2195 - ((*g++ & 0xffc0) << 4) | 2196 - (*b++ >> 6)); 2197 - } 2198 - 2199 - tmp = RREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset); 2200 - tmp = REG_SET_FIELD(tmp, DEGAMMA_CONTROL, GRPH_DEGAMMA_MODE, 0); 2201 - tmp = REG_SET_FIELD(tmp, DEGAMMA_CONTROL, CURSOR_DEGAMMA_MODE, 0); 2202 - tmp = REG_SET_FIELD(tmp, DEGAMMA_CONTROL, CURSOR2_DEGAMMA_MODE, 0); 2203 - WREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2204 - 2205 - tmp = RREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset); 2206 - tmp = REG_SET_FIELD(tmp, GAMUT_REMAP_CONTROL, GRPH_GAMUT_REMAP_MODE, 0); 2207 - WREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2208 - 2209 - tmp = RREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset); 2210 - tmp = REG_SET_FIELD(tmp, REGAMMA_CONTROL, GRPH_REGAMMA_MODE, 0); 2211 - WREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2212 - 2213 - tmp = RREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset); 2214 - tmp = REG_SET_FIELD(tmp, OUTPUT_CSC_CONTROL, OUTPUT_CSC_GRPH_MODE, 0); 2215 - WREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2216 - 2217 - /* XXX match this to the depth of the crtc fmt block, move to modeset? */ 2218 - WREG32(mmDENORM_CONTROL + amdgpu_crtc->crtc_offset, 0); 2219 - /* XXX this only needs to be programmed once per crtc at startup, 2220 - * not sure where the best place for it is 2221 - */ 2222 - tmp = RREG32(mmALPHA_CONTROL + amdgpu_crtc->crtc_offset); 2223 - tmp = REG_SET_FIELD(tmp, ALPHA_CONTROL, CURSOR_ALPHA_BLND_ENA, 1); 2224 - WREG32(mmALPHA_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2225 - } 2226 - 2227 - static int dce_v11_0_pick_dig_encoder(struct drm_encoder *encoder) 2228 - { 2229 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 2230 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 2231 - 2232 - switch (amdgpu_encoder->encoder_id) { 2233 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 2234 - if (dig->linkb) 2235 - return 1; 2236 - else 2237 - return 0; 2238 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 2239 - if (dig->linkb) 2240 - return 3; 2241 - else 2242 - return 2; 2243 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 2244 - if (dig->linkb) 2245 - return 5; 2246 - else 2247 - return 4; 2248 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 2249 - return 6; 2250 - default: 2251 - DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id); 2252 - return 0; 2253 - } 2254 - } 2255 - 2256 - /** 2257 - * dce_v11_0_pick_pll - Allocate a PPLL for use by the crtc. 2258 - * 2259 - * @crtc: drm crtc 2260 - * 2261 - * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors 2262 - * a single PPLL can be used for all DP crtcs/encoders. For non-DP 2263 - * monitors a dedicated PPLL must be used. If a particular board has 2264 - * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming 2265 - * as there is no need to program the PLL itself. If we are not able to 2266 - * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to 2267 - * avoid messing up an existing monitor. 2268 - * 2269 - * Asic specific PLL information 2270 - * 2271 - * DCE 10.x 2272 - * Tonga 2273 - * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) 2274 - * CI 2275 - * - PPLL0, PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC 2276 - * 2277 - */ 2278 - static u32 dce_v11_0_pick_pll(struct drm_crtc *crtc) 2279 - { 2280 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2281 - struct drm_device *dev = crtc->dev; 2282 - struct amdgpu_device *adev = drm_to_adev(dev); 2283 - u32 pll_in_use; 2284 - int pll; 2285 - 2286 - if ((adev->asic_type == CHIP_POLARIS10) || 2287 - (adev->asic_type == CHIP_POLARIS11) || 2288 - (adev->asic_type == CHIP_POLARIS12) || 2289 - (adev->asic_type == CHIP_VEGAM)) { 2290 - struct amdgpu_encoder *amdgpu_encoder = 2291 - to_amdgpu_encoder(amdgpu_crtc->encoder); 2292 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 2293 - 2294 - if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) 2295 - return ATOM_DP_DTO; 2296 - 2297 - switch (amdgpu_encoder->encoder_id) { 2298 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 2299 - if (dig->linkb) 2300 - return ATOM_COMBOPHY_PLL1; 2301 - else 2302 - return ATOM_COMBOPHY_PLL0; 2303 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 2304 - if (dig->linkb) 2305 - return ATOM_COMBOPHY_PLL3; 2306 - else 2307 - return ATOM_COMBOPHY_PLL2; 2308 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 2309 - if (dig->linkb) 2310 - return ATOM_COMBOPHY_PLL5; 2311 - else 2312 - return ATOM_COMBOPHY_PLL4; 2313 - default: 2314 - DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id); 2315 - return ATOM_PPLL_INVALID; 2316 - } 2317 - } 2318 - 2319 - if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) { 2320 - if (adev->clock.dp_extclk) 2321 - /* skip PPLL programming if using ext clock */ 2322 - return ATOM_PPLL_INVALID; 2323 - else { 2324 - /* use the same PPLL for all DP monitors */ 2325 - pll = amdgpu_pll_get_shared_dp_ppll(crtc); 2326 - if (pll != ATOM_PPLL_INVALID) 2327 - return pll; 2328 - } 2329 - } else { 2330 - /* use the same PPLL for all monitors with the same clock */ 2331 - pll = amdgpu_pll_get_shared_nondp_ppll(crtc); 2332 - if (pll != ATOM_PPLL_INVALID) 2333 - return pll; 2334 - } 2335 - 2336 - /* XXX need to determine what plls are available on each DCE11 part */ 2337 - pll_in_use = amdgpu_pll_get_use_mask(crtc); 2338 - if (adev->flags & AMD_IS_APU) { 2339 - if (!(pll_in_use & (1 << ATOM_PPLL1))) 2340 - return ATOM_PPLL1; 2341 - if (!(pll_in_use & (1 << ATOM_PPLL0))) 2342 - return ATOM_PPLL0; 2343 - DRM_ERROR("unable to allocate a PPLL\n"); 2344 - return ATOM_PPLL_INVALID; 2345 - } else { 2346 - if (!(pll_in_use & (1 << ATOM_PPLL2))) 2347 - return ATOM_PPLL2; 2348 - if (!(pll_in_use & (1 << ATOM_PPLL1))) 2349 - return ATOM_PPLL1; 2350 - if (!(pll_in_use & (1 << ATOM_PPLL0))) 2351 - return ATOM_PPLL0; 2352 - DRM_ERROR("unable to allocate a PPLL\n"); 2353 - return ATOM_PPLL_INVALID; 2354 - } 2355 - return ATOM_PPLL_INVALID; 2356 - } 2357 - 2358 - static void dce_v11_0_lock_cursor(struct drm_crtc *crtc, bool lock) 2359 - { 2360 - struct amdgpu_device *adev = drm_to_adev(crtc->dev); 2361 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2362 - uint32_t cur_lock; 2363 - 2364 - cur_lock = RREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset); 2365 - if (lock) 2366 - cur_lock = REG_SET_FIELD(cur_lock, CUR_UPDATE, CURSOR_UPDATE_LOCK, 1); 2367 - else 2368 - cur_lock = REG_SET_FIELD(cur_lock, CUR_UPDATE, CURSOR_UPDATE_LOCK, 0); 2369 - WREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset, cur_lock); 2370 - } 2371 - 2372 - static void dce_v11_0_hide_cursor(struct drm_crtc *crtc) 2373 - { 2374 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2375 - struct amdgpu_device *adev = drm_to_adev(crtc->dev); 2376 - u32 tmp; 2377 - 2378 - tmp = RREG32(mmCUR_CONTROL + amdgpu_crtc->crtc_offset); 2379 - tmp = REG_SET_FIELD(tmp, CUR_CONTROL, CURSOR_EN, 0); 2380 - WREG32(mmCUR_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2381 - } 2382 - 2383 - static void dce_v11_0_show_cursor(struct drm_crtc *crtc) 2384 - { 2385 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2386 - struct amdgpu_device *adev = drm_to_adev(crtc->dev); 2387 - u32 tmp; 2388 - 2389 - WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset, 2390 - upper_32_bits(amdgpu_crtc->cursor_addr)); 2391 - WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset, 2392 - lower_32_bits(amdgpu_crtc->cursor_addr)); 2393 - 2394 - tmp = RREG32(mmCUR_CONTROL + amdgpu_crtc->crtc_offset); 2395 - tmp = REG_SET_FIELD(tmp, CUR_CONTROL, CURSOR_EN, 1); 2396 - tmp = REG_SET_FIELD(tmp, CUR_CONTROL, CURSOR_MODE, 2); 2397 - WREG32(mmCUR_CONTROL + amdgpu_crtc->crtc_offset, tmp); 2398 - } 2399 - 2400 - static int dce_v11_0_cursor_move_locked(struct drm_crtc *crtc, 2401 - int x, int y) 2402 - { 2403 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2404 - struct amdgpu_device *adev = drm_to_adev(crtc->dev); 2405 - int xorigin = 0, yorigin = 0; 2406 - 2407 - amdgpu_crtc->cursor_x = x; 2408 - amdgpu_crtc->cursor_y = y; 2409 - 2410 - /* avivo cursor are offset into the total surface */ 2411 - x += crtc->x; 2412 - y += crtc->y; 2413 - DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y); 2414 - 2415 - if (x < 0) { 2416 - xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1); 2417 - x = 0; 2418 - } 2419 - if (y < 0) { 2420 - yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1); 2421 - y = 0; 2422 - } 2423 - 2424 - WREG32(mmCUR_POSITION + amdgpu_crtc->crtc_offset, (x << 16) | y); 2425 - WREG32(mmCUR_HOT_SPOT + amdgpu_crtc->crtc_offset, (xorigin << 16) | yorigin); 2426 - WREG32(mmCUR_SIZE + amdgpu_crtc->crtc_offset, 2427 - ((amdgpu_crtc->cursor_width - 1) << 16) | (amdgpu_crtc->cursor_height - 1)); 2428 - 2429 - return 0; 2430 - } 2431 - 2432 - static int dce_v11_0_crtc_cursor_move(struct drm_crtc *crtc, 2433 - int x, int y) 2434 - { 2435 - int ret; 2436 - 2437 - dce_v11_0_lock_cursor(crtc, true); 2438 - ret = dce_v11_0_cursor_move_locked(crtc, x, y); 2439 - dce_v11_0_lock_cursor(crtc, false); 2440 - 2441 - return ret; 2442 - } 2443 - 2444 - static int dce_v11_0_crtc_cursor_set2(struct drm_crtc *crtc, 2445 - struct drm_file *file_priv, 2446 - uint32_t handle, 2447 - uint32_t width, 2448 - uint32_t height, 2449 - int32_t hot_x, 2450 - int32_t hot_y) 2451 - { 2452 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2453 - struct drm_gem_object *obj; 2454 - struct amdgpu_bo *aobj; 2455 - int ret; 2456 - 2457 - if (!handle) { 2458 - /* turn off cursor */ 2459 - dce_v11_0_hide_cursor(crtc); 2460 - obj = NULL; 2461 - goto unpin; 2462 - } 2463 - 2464 - if ((width > amdgpu_crtc->max_cursor_width) || 2465 - (height > amdgpu_crtc->max_cursor_height)) { 2466 - DRM_ERROR("bad cursor width or height %d x %d\n", width, height); 2467 - return -EINVAL; 2468 - } 2469 - 2470 - obj = drm_gem_object_lookup(file_priv, handle); 2471 - if (!obj) { 2472 - DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, amdgpu_crtc->crtc_id); 2473 - return -ENOENT; 2474 - } 2475 - 2476 - aobj = gem_to_amdgpu_bo(obj); 2477 - ret = amdgpu_bo_reserve(aobj, false); 2478 - if (ret != 0) { 2479 - drm_gem_object_put(obj); 2480 - return ret; 2481 - } 2482 - 2483 - aobj->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; 2484 - ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM); 2485 - amdgpu_bo_unreserve(aobj); 2486 - if (ret) { 2487 - DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret); 2488 - drm_gem_object_put(obj); 2489 - return ret; 2490 - } 2491 - amdgpu_crtc->cursor_addr = amdgpu_bo_gpu_offset(aobj); 2492 - 2493 - dce_v11_0_lock_cursor(crtc, true); 2494 - 2495 - if (width != amdgpu_crtc->cursor_width || 2496 - height != amdgpu_crtc->cursor_height || 2497 - hot_x != amdgpu_crtc->cursor_hot_x || 2498 - hot_y != amdgpu_crtc->cursor_hot_y) { 2499 - int x, y; 2500 - 2501 - x = amdgpu_crtc->cursor_x + amdgpu_crtc->cursor_hot_x - hot_x; 2502 - y = amdgpu_crtc->cursor_y + amdgpu_crtc->cursor_hot_y - hot_y; 2503 - 2504 - dce_v11_0_cursor_move_locked(crtc, x, y); 2505 - 2506 - amdgpu_crtc->cursor_width = width; 2507 - amdgpu_crtc->cursor_height = height; 2508 - amdgpu_crtc->cursor_hot_x = hot_x; 2509 - amdgpu_crtc->cursor_hot_y = hot_y; 2510 - } 2511 - 2512 - dce_v11_0_show_cursor(crtc); 2513 - dce_v11_0_lock_cursor(crtc, false); 2514 - 2515 - unpin: 2516 - if (amdgpu_crtc->cursor_bo) { 2517 - struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo); 2518 - ret = amdgpu_bo_reserve(aobj, true); 2519 - if (likely(ret == 0)) { 2520 - amdgpu_bo_unpin(aobj); 2521 - amdgpu_bo_unreserve(aobj); 2522 - } 2523 - drm_gem_object_put(amdgpu_crtc->cursor_bo); 2524 - } 2525 - 2526 - amdgpu_crtc->cursor_bo = obj; 2527 - return 0; 2528 - } 2529 - 2530 - static void dce_v11_0_cursor_reset(struct drm_crtc *crtc) 2531 - { 2532 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2533 - 2534 - if (amdgpu_crtc->cursor_bo) { 2535 - dce_v11_0_lock_cursor(crtc, true); 2536 - 2537 - dce_v11_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x, 2538 - amdgpu_crtc->cursor_y); 2539 - 2540 - dce_v11_0_show_cursor(crtc); 2541 - 2542 - dce_v11_0_lock_cursor(crtc, false); 2543 - } 2544 - } 2545 - 2546 - static int dce_v11_0_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, 2547 - u16 *blue, uint32_t size, 2548 - struct drm_modeset_acquire_ctx *ctx) 2549 - { 2550 - dce_v11_0_crtc_load_lut(crtc); 2551 - 2552 - return 0; 2553 - } 2554 - 2555 - static void dce_v11_0_crtc_destroy(struct drm_crtc *crtc) 2556 - { 2557 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2558 - 2559 - drm_crtc_cleanup(crtc); 2560 - kfree(amdgpu_crtc); 2561 - } 2562 - 2563 - static const struct drm_crtc_funcs dce_v11_0_crtc_funcs = { 2564 - .cursor_set2 = dce_v11_0_crtc_cursor_set2, 2565 - .cursor_move = dce_v11_0_crtc_cursor_move, 2566 - .gamma_set = dce_v11_0_crtc_gamma_set, 2567 - .set_config = amdgpu_display_crtc_set_config, 2568 - .destroy = dce_v11_0_crtc_destroy, 2569 - .page_flip_target = amdgpu_display_crtc_page_flip_target, 2570 - .get_vblank_counter = amdgpu_get_vblank_counter_kms, 2571 - .enable_vblank = amdgpu_enable_vblank_kms, 2572 - .disable_vblank = amdgpu_disable_vblank_kms, 2573 - .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp, 2574 - }; 2575 - 2576 - static void dce_v11_0_crtc_dpms(struct drm_crtc *crtc, int mode) 2577 - { 2578 - struct drm_device *dev = crtc->dev; 2579 - struct amdgpu_device *adev = drm_to_adev(dev); 2580 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2581 - unsigned type; 2582 - 2583 - switch (mode) { 2584 - case DRM_MODE_DPMS_ON: 2585 - amdgpu_crtc->enabled = true; 2586 - amdgpu_atombios_crtc_enable(crtc, ATOM_ENABLE); 2587 - dce_v11_0_vga_enable(crtc, true); 2588 - amdgpu_atombios_crtc_blank(crtc, ATOM_DISABLE); 2589 - dce_v11_0_vga_enable(crtc, false); 2590 - /* Make sure VBLANK and PFLIP interrupts are still enabled */ 2591 - type = amdgpu_display_crtc_idx_to_irq_type(adev, 2592 - amdgpu_crtc->crtc_id); 2593 - amdgpu_irq_update(adev, &adev->crtc_irq, type); 2594 - amdgpu_irq_update(adev, &adev->pageflip_irq, type); 2595 - drm_crtc_vblank_on(crtc); 2596 - dce_v11_0_crtc_load_lut(crtc); 2597 - break; 2598 - case DRM_MODE_DPMS_STANDBY: 2599 - case DRM_MODE_DPMS_SUSPEND: 2600 - case DRM_MODE_DPMS_OFF: 2601 - drm_crtc_vblank_off(crtc); 2602 - if (amdgpu_crtc->enabled) { 2603 - dce_v11_0_vga_enable(crtc, true); 2604 - amdgpu_atombios_crtc_blank(crtc, ATOM_ENABLE); 2605 - dce_v11_0_vga_enable(crtc, false); 2606 - } 2607 - amdgpu_atombios_crtc_enable(crtc, ATOM_DISABLE); 2608 - amdgpu_crtc->enabled = false; 2609 - break; 2610 - } 2611 - /* adjust pm to dpms */ 2612 - amdgpu_dpm_compute_clocks(adev); 2613 - } 2614 - 2615 - static void dce_v11_0_crtc_prepare(struct drm_crtc *crtc) 2616 - { 2617 - /* disable crtc pair power gating before programming */ 2618 - amdgpu_atombios_crtc_powergate(crtc, ATOM_DISABLE); 2619 - amdgpu_atombios_crtc_lock(crtc, ATOM_ENABLE); 2620 - dce_v11_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 2621 - } 2622 - 2623 - static void dce_v11_0_crtc_commit(struct drm_crtc *crtc) 2624 - { 2625 - dce_v11_0_crtc_dpms(crtc, DRM_MODE_DPMS_ON); 2626 - amdgpu_atombios_crtc_lock(crtc, ATOM_DISABLE); 2627 - } 2628 - 2629 - static void dce_v11_0_crtc_disable(struct drm_crtc *crtc) 2630 - { 2631 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2632 - struct drm_device *dev = crtc->dev; 2633 - struct amdgpu_device *adev = drm_to_adev(dev); 2634 - struct amdgpu_atom_ss ss; 2635 - int i; 2636 - 2637 - dce_v11_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 2638 - if (crtc->primary->fb) { 2639 - int r; 2640 - struct amdgpu_bo *abo; 2641 - 2642 - abo = gem_to_amdgpu_bo(crtc->primary->fb->obj[0]); 2643 - r = amdgpu_bo_reserve(abo, true); 2644 - if (unlikely(r)) 2645 - DRM_ERROR("failed to reserve abo before unpin\n"); 2646 - else { 2647 - amdgpu_bo_unpin(abo); 2648 - amdgpu_bo_unreserve(abo); 2649 - } 2650 - } 2651 - /* disable the GRPH */ 2652 - dce_v11_0_grph_enable(crtc, false); 2653 - 2654 - amdgpu_atombios_crtc_powergate(crtc, ATOM_ENABLE); 2655 - 2656 - for (i = 0; i < adev->mode_info.num_crtc; i++) { 2657 - if (adev->mode_info.crtcs[i] && 2658 - adev->mode_info.crtcs[i]->enabled && 2659 - i != amdgpu_crtc->crtc_id && 2660 - amdgpu_crtc->pll_id == adev->mode_info.crtcs[i]->pll_id) { 2661 - /* one other crtc is using this pll don't turn 2662 - * off the pll 2663 - */ 2664 - goto done; 2665 - } 2666 - } 2667 - 2668 - switch (amdgpu_crtc->pll_id) { 2669 - case ATOM_PPLL0: 2670 - case ATOM_PPLL1: 2671 - case ATOM_PPLL2: 2672 - /* disable the ppll */ 2673 - amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id, 2674 - 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); 2675 - break; 2676 - case ATOM_COMBOPHY_PLL0: 2677 - case ATOM_COMBOPHY_PLL1: 2678 - case ATOM_COMBOPHY_PLL2: 2679 - case ATOM_COMBOPHY_PLL3: 2680 - case ATOM_COMBOPHY_PLL4: 2681 - case ATOM_COMBOPHY_PLL5: 2682 - /* disable the ppll */ 2683 - amdgpu_atombios_crtc_program_pll(crtc, ATOM_CRTC_INVALID, amdgpu_crtc->pll_id, 2684 - 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); 2685 - break; 2686 - default: 2687 - break; 2688 - } 2689 - done: 2690 - amdgpu_crtc->pll_id = ATOM_PPLL_INVALID; 2691 - amdgpu_crtc->adjusted_clock = 0; 2692 - amdgpu_crtc->encoder = NULL; 2693 - amdgpu_crtc->connector = NULL; 2694 - } 2695 - 2696 - static int dce_v11_0_crtc_mode_set(struct drm_crtc *crtc, 2697 - struct drm_display_mode *mode, 2698 - struct drm_display_mode *adjusted_mode, 2699 - int x, int y, struct drm_framebuffer *old_fb) 2700 - { 2701 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2702 - struct drm_device *dev = crtc->dev; 2703 - struct amdgpu_device *adev = drm_to_adev(dev); 2704 - 2705 - if (!amdgpu_crtc->adjusted_clock) 2706 - return -EINVAL; 2707 - 2708 - if ((adev->asic_type == CHIP_POLARIS10) || 2709 - (adev->asic_type == CHIP_POLARIS11) || 2710 - (adev->asic_type == CHIP_POLARIS12) || 2711 - (adev->asic_type == CHIP_VEGAM)) { 2712 - struct amdgpu_encoder *amdgpu_encoder = 2713 - to_amdgpu_encoder(amdgpu_crtc->encoder); 2714 - int encoder_mode = 2715 - amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder); 2716 - 2717 - /* SetPixelClock calculates the plls and ss values now */ 2718 - amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, 2719 - amdgpu_crtc->pll_id, 2720 - encoder_mode, amdgpu_encoder->encoder_id, 2721 - adjusted_mode->clock, 0, 0, 0, 0, 2722 - amdgpu_crtc->bpc, amdgpu_crtc->ss_enabled, &amdgpu_crtc->ss); 2723 - } else { 2724 - amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode); 2725 - } 2726 - amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode); 2727 - dce_v11_0_crtc_do_set_base(crtc, old_fb, x, y, 0); 2728 - amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode); 2729 - amdgpu_atombios_crtc_scaler_setup(crtc); 2730 - dce_v11_0_cursor_reset(crtc); 2731 - /* update the hw version fpr dpm */ 2732 - amdgpu_crtc->hw_mode = *adjusted_mode; 2733 - 2734 - return 0; 2735 - } 2736 - 2737 - static bool dce_v11_0_crtc_mode_fixup(struct drm_crtc *crtc, 2738 - const struct drm_display_mode *mode, 2739 - struct drm_display_mode *adjusted_mode) 2740 - { 2741 - struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 2742 - struct drm_device *dev = crtc->dev; 2743 - struct drm_encoder *encoder; 2744 - 2745 - /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */ 2746 - list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 2747 - if (encoder->crtc == crtc) { 2748 - amdgpu_crtc->encoder = encoder; 2749 - amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder); 2750 - break; 2751 - } 2752 - } 2753 - if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) { 2754 - amdgpu_crtc->encoder = NULL; 2755 - amdgpu_crtc->connector = NULL; 2756 - return false; 2757 - } 2758 - if (!amdgpu_display_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) 2759 - return false; 2760 - if (amdgpu_atombios_crtc_prepare_pll(crtc, adjusted_mode)) 2761 - return false; 2762 - /* pick pll */ 2763 - amdgpu_crtc->pll_id = dce_v11_0_pick_pll(crtc); 2764 - /* if we can't get a PPLL for a non-DP encoder, fail */ 2765 - if ((amdgpu_crtc->pll_id == ATOM_PPLL_INVALID) && 2766 - !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) 2767 - return false; 2768 - 2769 - return true; 2770 - } 2771 - 2772 - static int dce_v11_0_crtc_set_base(struct drm_crtc *crtc, int x, int y, 2773 - struct drm_framebuffer *old_fb) 2774 - { 2775 - return dce_v11_0_crtc_do_set_base(crtc, old_fb, x, y, 0); 2776 - } 2777 - 2778 - static int dce_v11_0_crtc_set_base_atomic(struct drm_crtc *crtc, 2779 - struct drm_framebuffer *fb, 2780 - int x, int y, enum mode_set_atomic state) 2781 - { 2782 - return dce_v11_0_crtc_do_set_base(crtc, fb, x, y, 1); 2783 - } 2784 - 2785 - static const struct drm_crtc_helper_funcs dce_v11_0_crtc_helper_funcs = { 2786 - .dpms = dce_v11_0_crtc_dpms, 2787 - .mode_fixup = dce_v11_0_crtc_mode_fixup, 2788 - .mode_set = dce_v11_0_crtc_mode_set, 2789 - .mode_set_base = dce_v11_0_crtc_set_base, 2790 - .mode_set_base_atomic = dce_v11_0_crtc_set_base_atomic, 2791 - .prepare = dce_v11_0_crtc_prepare, 2792 - .commit = dce_v11_0_crtc_commit, 2793 - .disable = dce_v11_0_crtc_disable, 2794 - .get_scanout_position = amdgpu_crtc_get_scanout_position, 2795 - }; 2796 - 2797 - static void dce_v11_0_panic_flush(struct drm_plane *plane) 2798 - { 2799 - struct drm_framebuffer *fb; 2800 - struct amdgpu_crtc *amdgpu_crtc; 2801 - struct amdgpu_device *adev; 2802 - uint32_t fb_format; 2803 - 2804 - if (!plane->fb) 2805 - return; 2806 - 2807 - fb = plane->fb; 2808 - amdgpu_crtc = to_amdgpu_crtc(plane->crtc); 2809 - adev = drm_to_adev(fb->dev); 2810 - 2811 - /* Disable DC tiling */ 2812 - fb_format = RREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset); 2813 - fb_format &= ~GRPH_CONTROL__GRPH_ARRAY_MODE_MASK; 2814 - WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format); 2815 - 2816 - } 2817 - 2818 - static const struct drm_plane_helper_funcs dce_v11_0_drm_primary_plane_helper_funcs = { 2819 - .get_scanout_buffer = amdgpu_display_get_scanout_buffer, 2820 - .panic_flush = dce_v11_0_panic_flush, 2821 - }; 2822 - 2823 - static int dce_v11_0_crtc_init(struct amdgpu_device *adev, int index) 2824 - { 2825 - struct amdgpu_crtc *amdgpu_crtc; 2826 - 2827 - amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) + 2828 - (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); 2829 - if (amdgpu_crtc == NULL) 2830 - return -ENOMEM; 2831 - 2832 - drm_crtc_init(adev_to_drm(adev), &amdgpu_crtc->base, &dce_v11_0_crtc_funcs); 2833 - 2834 - drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256); 2835 - amdgpu_crtc->crtc_id = index; 2836 - adev->mode_info.crtcs[index] = amdgpu_crtc; 2837 - 2838 - amdgpu_crtc->max_cursor_width = 128; 2839 - amdgpu_crtc->max_cursor_height = 128; 2840 - adev_to_drm(adev)->mode_config.cursor_width = amdgpu_crtc->max_cursor_width; 2841 - adev_to_drm(adev)->mode_config.cursor_height = amdgpu_crtc->max_cursor_height; 2842 - 2843 - switch (amdgpu_crtc->crtc_id) { 2844 - case 0: 2845 - default: 2846 - amdgpu_crtc->crtc_offset = CRTC0_REGISTER_OFFSET; 2847 - break; 2848 - case 1: 2849 - amdgpu_crtc->crtc_offset = CRTC1_REGISTER_OFFSET; 2850 - break; 2851 - case 2: 2852 - amdgpu_crtc->crtc_offset = CRTC2_REGISTER_OFFSET; 2853 - break; 2854 - case 3: 2855 - amdgpu_crtc->crtc_offset = CRTC3_REGISTER_OFFSET; 2856 - break; 2857 - case 4: 2858 - amdgpu_crtc->crtc_offset = CRTC4_REGISTER_OFFSET; 2859 - break; 2860 - case 5: 2861 - amdgpu_crtc->crtc_offset = CRTC5_REGISTER_OFFSET; 2862 - break; 2863 - } 2864 - 2865 - amdgpu_crtc->pll_id = ATOM_PPLL_INVALID; 2866 - amdgpu_crtc->adjusted_clock = 0; 2867 - amdgpu_crtc->encoder = NULL; 2868 - amdgpu_crtc->connector = NULL; 2869 - drm_crtc_helper_add(&amdgpu_crtc->base, &dce_v11_0_crtc_helper_funcs); 2870 - drm_plane_helper_add(amdgpu_crtc->base.primary, &dce_v11_0_drm_primary_plane_helper_funcs); 2871 - 2872 - return 0; 2873 - } 2874 - 2875 - static int dce_v11_0_early_init(struct amdgpu_ip_block *ip_block) 2876 - { 2877 - struct amdgpu_device *adev = ip_block->adev; 2878 - 2879 - adev->audio_endpt_rreg = &dce_v11_0_audio_endpt_rreg; 2880 - adev->audio_endpt_wreg = &dce_v11_0_audio_endpt_wreg; 2881 - 2882 - dce_v11_0_set_display_funcs(adev); 2883 - 2884 - adev->mode_info.num_crtc = dce_v11_0_get_num_crtc(adev); 2885 - 2886 - switch (adev->asic_type) { 2887 - case CHIP_CARRIZO: 2888 - adev->mode_info.num_hpd = 6; 2889 - adev->mode_info.num_dig = 9; 2890 - break; 2891 - case CHIP_STONEY: 2892 - adev->mode_info.num_hpd = 6; 2893 - adev->mode_info.num_dig = 9; 2894 - break; 2895 - case CHIP_POLARIS10: 2896 - case CHIP_VEGAM: 2897 - adev->mode_info.num_hpd = 6; 2898 - adev->mode_info.num_dig = 6; 2899 - break; 2900 - case CHIP_POLARIS11: 2901 - case CHIP_POLARIS12: 2902 - adev->mode_info.num_hpd = 5; 2903 - adev->mode_info.num_dig = 5; 2904 - break; 2905 - default: 2906 - /* FIXME: not supported yet */ 2907 - return -EINVAL; 2908 - } 2909 - 2910 - dce_v11_0_set_irq_funcs(adev); 2911 - 2912 - return 0; 2913 - } 2914 - 2915 - static int dce_v11_0_sw_init(struct amdgpu_ip_block *ip_block) 2916 - { 2917 - int r, i; 2918 - struct amdgpu_device *adev = ip_block->adev; 2919 - 2920 - for (i = 0; i < adev->mode_info.num_crtc; i++) { 2921 - r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, i + 1, &adev->crtc_irq); 2922 - if (r) 2923 - return r; 2924 - } 2925 - 2926 - for (i = VISLANDS30_IV_SRCID_D1_GRPH_PFLIP; i < 20; i += 2) { 2927 - r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, i, &adev->pageflip_irq); 2928 - if (r) 2929 - return r; 2930 - } 2931 - 2932 - /* HPD hotplug */ 2933 - r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_HOTPLUG_DETECT_A, &adev->hpd_irq); 2934 - if (r) 2935 - return r; 2936 - 2937 - adev_to_drm(adev)->mode_config.funcs = &amdgpu_mode_funcs; 2938 - 2939 - adev_to_drm(adev)->mode_config.async_page_flip = true; 2940 - 2941 - adev_to_drm(adev)->mode_config.max_width = 16384; 2942 - adev_to_drm(adev)->mode_config.max_height = 16384; 2943 - 2944 - adev_to_drm(adev)->mode_config.preferred_depth = 24; 2945 - adev_to_drm(adev)->mode_config.prefer_shadow = 1; 2946 - 2947 - adev_to_drm(adev)->mode_config.fb_modifiers_not_supported = true; 2948 - 2949 - r = amdgpu_display_modeset_create_props(adev); 2950 - if (r) 2951 - return r; 2952 - 2953 - adev_to_drm(adev)->mode_config.max_width = 16384; 2954 - adev_to_drm(adev)->mode_config.max_height = 16384; 2955 - 2956 - 2957 - /* allocate crtcs */ 2958 - for (i = 0; i < adev->mode_info.num_crtc; i++) { 2959 - r = dce_v11_0_crtc_init(adev, i); 2960 - if (r) 2961 - return r; 2962 - } 2963 - 2964 - if (amdgpu_atombios_get_connector_info_from_object_table(adev)) 2965 - amdgpu_display_print_display_setup(adev_to_drm(adev)); 2966 - else 2967 - return -EINVAL; 2968 - 2969 - /* setup afmt */ 2970 - r = dce_v11_0_afmt_init(adev); 2971 - if (r) 2972 - return r; 2973 - 2974 - r = dce_v11_0_audio_init(adev); 2975 - if (r) 2976 - return r; 2977 - 2978 - /* Disable vblank IRQs aggressively for power-saving */ 2979 - /* XXX: can this be enabled for DC? */ 2980 - adev_to_drm(adev)->vblank_disable_immediate = true; 2981 - 2982 - r = drm_vblank_init(adev_to_drm(adev), adev->mode_info.num_crtc); 2983 - if (r) 2984 - return r; 2985 - 2986 - INIT_DELAYED_WORK(&adev->hotplug_work, 2987 - amdgpu_display_hotplug_work_func); 2988 - 2989 - drm_kms_helper_poll_init(adev_to_drm(adev)); 2990 - 2991 - adev->mode_info.mode_config_initialized = true; 2992 - return 0; 2993 - } 2994 - 2995 - static int dce_v11_0_sw_fini(struct amdgpu_ip_block *ip_block) 2996 - { 2997 - struct amdgpu_device *adev = ip_block->adev; 2998 - 2999 - drm_edid_free(adev->mode_info.bios_hardcoded_edid); 3000 - 3001 - drm_kms_helper_poll_fini(adev_to_drm(adev)); 3002 - 3003 - dce_v11_0_audio_fini(adev); 3004 - 3005 - dce_v11_0_afmt_fini(adev); 3006 - 3007 - drm_mode_config_cleanup(adev_to_drm(adev)); 3008 - adev->mode_info.mode_config_initialized = false; 3009 - 3010 - return 0; 3011 - } 3012 - 3013 - static int dce_v11_0_hw_init(struct amdgpu_ip_block *ip_block) 3014 - { 3015 - int i; 3016 - struct amdgpu_device *adev = ip_block->adev; 3017 - 3018 - dce_v11_0_init_golden_registers(adev); 3019 - 3020 - /* disable vga render */ 3021 - dce_v11_0_set_vga_render_state(adev, false); 3022 - /* init dig PHYs, disp eng pll */ 3023 - amdgpu_atombios_crtc_powergate_init(adev); 3024 - amdgpu_atombios_encoder_init_dig(adev); 3025 - if ((adev->asic_type == CHIP_POLARIS10) || 3026 - (adev->asic_type == CHIP_POLARIS11) || 3027 - (adev->asic_type == CHIP_POLARIS12) || 3028 - (adev->asic_type == CHIP_VEGAM)) { 3029 - amdgpu_atombios_crtc_set_dce_clock(adev, adev->clock.default_dispclk, 3030 - DCE_CLOCK_TYPE_DISPCLK, ATOM_GCK_DFS); 3031 - amdgpu_atombios_crtc_set_dce_clock(adev, 0, 3032 - DCE_CLOCK_TYPE_DPREFCLK, ATOM_GCK_DFS); 3033 - } else { 3034 - amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk); 3035 - } 3036 - 3037 - /* initialize hpd */ 3038 - dce_v11_0_hpd_init(adev); 3039 - 3040 - for (i = 0; i < adev->mode_info.audio.num_pins; i++) { 3041 - dce_v11_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); 3042 - } 3043 - 3044 - dce_v11_0_pageflip_interrupt_init(adev); 3045 - 3046 - return 0; 3047 - } 3048 - 3049 - static int dce_v11_0_hw_fini(struct amdgpu_ip_block *ip_block) 3050 - { 3051 - int i; 3052 - struct amdgpu_device *adev = ip_block->adev; 3053 - 3054 - dce_v11_0_hpd_fini(adev); 3055 - 3056 - for (i = 0; i < adev->mode_info.audio.num_pins; i++) { 3057 - dce_v11_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false); 3058 - } 3059 - 3060 - dce_v11_0_pageflip_interrupt_fini(adev); 3061 - 3062 - flush_delayed_work(&adev->hotplug_work); 3063 - 3064 - return 0; 3065 - } 3066 - 3067 - static int dce_v11_0_suspend(struct amdgpu_ip_block *ip_block) 3068 - { 3069 - struct amdgpu_device *adev = ip_block->adev; 3070 - int r; 3071 - 3072 - r = amdgpu_display_suspend_helper(adev); 3073 - if (r) 3074 - return r; 3075 - 3076 - adev->mode_info.bl_level = 3077 - amdgpu_atombios_encoder_get_backlight_level_from_reg(adev); 3078 - 3079 - return dce_v11_0_hw_fini(ip_block); 3080 - } 3081 - 3082 - static int dce_v11_0_resume(struct amdgpu_ip_block *ip_block) 3083 - { 3084 - struct amdgpu_device *adev = ip_block->adev; 3085 - int ret; 3086 - 3087 - amdgpu_atombios_encoder_set_backlight_level_to_reg(adev, 3088 - adev->mode_info.bl_level); 3089 - 3090 - ret = dce_v11_0_hw_init(ip_block); 3091 - 3092 - /* turn on the BL */ 3093 - if (adev->mode_info.bl_encoder) { 3094 - u8 bl_level = amdgpu_display_backlight_get_level(adev, 3095 - adev->mode_info.bl_encoder); 3096 - amdgpu_display_backlight_set_level(adev, adev->mode_info.bl_encoder, 3097 - bl_level); 3098 - } 3099 - if (ret) 3100 - return ret; 3101 - 3102 - return amdgpu_display_resume_helper(adev); 3103 - } 3104 - 3105 - static bool dce_v11_0_is_idle(struct amdgpu_ip_block *ip_block) 3106 - { 3107 - return true; 3108 - } 3109 - 3110 - static int dce_v11_0_soft_reset(struct amdgpu_ip_block *ip_block) 3111 - { 3112 - u32 srbm_soft_reset = 0, tmp; 3113 - struct amdgpu_device *adev = ip_block->adev; 3114 - 3115 - if (dce_v11_0_is_display_hung(adev)) 3116 - srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK; 3117 - 3118 - if (srbm_soft_reset) { 3119 - tmp = RREG32(mmSRBM_SOFT_RESET); 3120 - tmp |= srbm_soft_reset; 3121 - dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp); 3122 - WREG32(mmSRBM_SOFT_RESET, tmp); 3123 - tmp = RREG32(mmSRBM_SOFT_RESET); 3124 - 3125 - udelay(50); 3126 - 3127 - tmp &= ~srbm_soft_reset; 3128 - WREG32(mmSRBM_SOFT_RESET, tmp); 3129 - tmp = RREG32(mmSRBM_SOFT_RESET); 3130 - 3131 - /* Wait a little for things to settle down */ 3132 - udelay(50); 3133 - } 3134 - return 0; 3135 - } 3136 - 3137 - static void dce_v11_0_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev, 3138 - int crtc, 3139 - enum amdgpu_interrupt_state state) 3140 - { 3141 - u32 lb_interrupt_mask; 3142 - 3143 - if (crtc >= adev->mode_info.num_crtc) { 3144 - DRM_DEBUG("invalid crtc %d\n", crtc); 3145 - return; 3146 - } 3147 - 3148 - switch (state) { 3149 - case AMDGPU_IRQ_STATE_DISABLE: 3150 - lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + crtc_offsets[crtc]); 3151 - lb_interrupt_mask = REG_SET_FIELD(lb_interrupt_mask, LB_INTERRUPT_MASK, 3152 - VBLANK_INTERRUPT_MASK, 0); 3153 - WREG32(mmLB_INTERRUPT_MASK + crtc_offsets[crtc], lb_interrupt_mask); 3154 - break; 3155 - case AMDGPU_IRQ_STATE_ENABLE: 3156 - lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + crtc_offsets[crtc]); 3157 - lb_interrupt_mask = REG_SET_FIELD(lb_interrupt_mask, LB_INTERRUPT_MASK, 3158 - VBLANK_INTERRUPT_MASK, 1); 3159 - WREG32(mmLB_INTERRUPT_MASK + crtc_offsets[crtc], lb_interrupt_mask); 3160 - break; 3161 - default: 3162 - break; 3163 - } 3164 - } 3165 - 3166 - static void dce_v11_0_set_crtc_vline_interrupt_state(struct amdgpu_device *adev, 3167 - int crtc, 3168 - enum amdgpu_interrupt_state state) 3169 - { 3170 - u32 lb_interrupt_mask; 3171 - 3172 - if (crtc >= adev->mode_info.num_crtc) { 3173 - DRM_DEBUG("invalid crtc %d\n", crtc); 3174 - return; 3175 - } 3176 - 3177 - switch (state) { 3178 - case AMDGPU_IRQ_STATE_DISABLE: 3179 - lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + crtc_offsets[crtc]); 3180 - lb_interrupt_mask = REG_SET_FIELD(lb_interrupt_mask, LB_INTERRUPT_MASK, 3181 - VLINE_INTERRUPT_MASK, 0); 3182 - WREG32(mmLB_INTERRUPT_MASK + crtc_offsets[crtc], lb_interrupt_mask); 3183 - break; 3184 - case AMDGPU_IRQ_STATE_ENABLE: 3185 - lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + crtc_offsets[crtc]); 3186 - lb_interrupt_mask = REG_SET_FIELD(lb_interrupt_mask, LB_INTERRUPT_MASK, 3187 - VLINE_INTERRUPT_MASK, 1); 3188 - WREG32(mmLB_INTERRUPT_MASK + crtc_offsets[crtc], lb_interrupt_mask); 3189 - break; 3190 - default: 3191 - break; 3192 - } 3193 - } 3194 - 3195 - static int dce_v11_0_set_hpd_irq_state(struct amdgpu_device *adev, 3196 - struct amdgpu_irq_src *source, 3197 - unsigned hpd, 3198 - enum amdgpu_interrupt_state state) 3199 - { 3200 - u32 tmp; 3201 - 3202 - if (hpd >= adev->mode_info.num_hpd) { 3203 - DRM_DEBUG("invalid hpd %d\n", hpd); 3204 - return 0; 3205 - } 3206 - 3207 - switch (state) { 3208 - case AMDGPU_IRQ_STATE_DISABLE: 3209 - tmp = RREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[hpd]); 3210 - tmp = REG_SET_FIELD(tmp, DC_HPD_INT_CONTROL, DC_HPD_INT_EN, 0); 3211 - WREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[hpd], tmp); 3212 - break; 3213 - case AMDGPU_IRQ_STATE_ENABLE: 3214 - tmp = RREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[hpd]); 3215 - tmp = REG_SET_FIELD(tmp, DC_HPD_INT_CONTROL, DC_HPD_INT_EN, 1); 3216 - WREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[hpd], tmp); 3217 - break; 3218 - default: 3219 - break; 3220 - } 3221 - 3222 - return 0; 3223 - } 3224 - 3225 - static int dce_v11_0_set_crtc_irq_state(struct amdgpu_device *adev, 3226 - struct amdgpu_irq_src *source, 3227 - unsigned type, 3228 - enum amdgpu_interrupt_state state) 3229 - { 3230 - switch (type) { 3231 - case AMDGPU_CRTC_IRQ_VBLANK1: 3232 - dce_v11_0_set_crtc_vblank_interrupt_state(adev, 0, state); 3233 - break; 3234 - case AMDGPU_CRTC_IRQ_VBLANK2: 3235 - dce_v11_0_set_crtc_vblank_interrupt_state(adev, 1, state); 3236 - break; 3237 - case AMDGPU_CRTC_IRQ_VBLANK3: 3238 - dce_v11_0_set_crtc_vblank_interrupt_state(adev, 2, state); 3239 - break; 3240 - case AMDGPU_CRTC_IRQ_VBLANK4: 3241 - dce_v11_0_set_crtc_vblank_interrupt_state(adev, 3, state); 3242 - break; 3243 - case AMDGPU_CRTC_IRQ_VBLANK5: 3244 - dce_v11_0_set_crtc_vblank_interrupt_state(adev, 4, state); 3245 - break; 3246 - case AMDGPU_CRTC_IRQ_VBLANK6: 3247 - dce_v11_0_set_crtc_vblank_interrupt_state(adev, 5, state); 3248 - break; 3249 - case AMDGPU_CRTC_IRQ_VLINE1: 3250 - dce_v11_0_set_crtc_vline_interrupt_state(adev, 0, state); 3251 - break; 3252 - case AMDGPU_CRTC_IRQ_VLINE2: 3253 - dce_v11_0_set_crtc_vline_interrupt_state(adev, 1, state); 3254 - break; 3255 - case AMDGPU_CRTC_IRQ_VLINE3: 3256 - dce_v11_0_set_crtc_vline_interrupt_state(adev, 2, state); 3257 - break; 3258 - case AMDGPU_CRTC_IRQ_VLINE4: 3259 - dce_v11_0_set_crtc_vline_interrupt_state(adev, 3, state); 3260 - break; 3261 - case AMDGPU_CRTC_IRQ_VLINE5: 3262 - dce_v11_0_set_crtc_vline_interrupt_state(adev, 4, state); 3263 - break; 3264 - case AMDGPU_CRTC_IRQ_VLINE6: 3265 - dce_v11_0_set_crtc_vline_interrupt_state(adev, 5, state); 3266 - break; 3267 - default: 3268 - break; 3269 - } 3270 - return 0; 3271 - } 3272 - 3273 - static int dce_v11_0_set_pageflip_irq_state(struct amdgpu_device *adev, 3274 - struct amdgpu_irq_src *src, 3275 - unsigned type, 3276 - enum amdgpu_interrupt_state state) 3277 - { 3278 - u32 reg; 3279 - 3280 - if (type >= adev->mode_info.num_crtc) { 3281 - DRM_ERROR("invalid pageflip crtc %d\n", type); 3282 - return -EINVAL; 3283 - } 3284 - 3285 - reg = RREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type]); 3286 - if (state == AMDGPU_IRQ_STATE_DISABLE) 3287 - WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type], 3288 - reg & ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK); 3289 - else 3290 - WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type], 3291 - reg | GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK); 3292 - 3293 - return 0; 3294 - } 3295 - 3296 - static int dce_v11_0_pageflip_irq(struct amdgpu_device *adev, 3297 - struct amdgpu_irq_src *source, 3298 - struct amdgpu_iv_entry *entry) 3299 - { 3300 - unsigned long flags; 3301 - unsigned crtc_id; 3302 - struct amdgpu_crtc *amdgpu_crtc; 3303 - struct amdgpu_flip_work *works; 3304 - 3305 - crtc_id = (entry->src_id - 8) >> 1; 3306 - amdgpu_crtc = adev->mode_info.crtcs[crtc_id]; 3307 - 3308 - if (crtc_id >= adev->mode_info.num_crtc) { 3309 - DRM_ERROR("invalid pageflip crtc %d\n", crtc_id); 3310 - return -EINVAL; 3311 - } 3312 - 3313 - if (RREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id]) & 3314 - GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK) 3315 - WREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id], 3316 - GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK); 3317 - 3318 - /* IRQ could occur when in initial stage */ 3319 - if(amdgpu_crtc == NULL) 3320 - return 0; 3321 - 3322 - spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags); 3323 - works = amdgpu_crtc->pflip_works; 3324 - if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){ 3325 - DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != " 3326 - "AMDGPU_FLIP_SUBMITTED(%d)\n", 3327 - amdgpu_crtc->pflip_status, 3328 - AMDGPU_FLIP_SUBMITTED); 3329 - spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags); 3330 - return 0; 3331 - } 3332 - 3333 - /* page flip completed. clean up */ 3334 - amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE; 3335 - amdgpu_crtc->pflip_works = NULL; 3336 - 3337 - /* wakeup usersapce */ 3338 - if(works->event) 3339 - drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event); 3340 - 3341 - spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags); 3342 - 3343 - drm_crtc_vblank_put(&amdgpu_crtc->base); 3344 - schedule_work(&works->unpin_work); 3345 - 3346 - return 0; 3347 - } 3348 - 3349 - static void dce_v11_0_hpd_int_ack(struct amdgpu_device *adev, 3350 - int hpd) 3351 - { 3352 - u32 tmp; 3353 - 3354 - if (hpd >= adev->mode_info.num_hpd) { 3355 - DRM_DEBUG("invalid hpd %d\n", hpd); 3356 - return; 3357 - } 3358 - 3359 - tmp = RREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[hpd]); 3360 - tmp = REG_SET_FIELD(tmp, DC_HPD_INT_CONTROL, DC_HPD_INT_ACK, 1); 3361 - WREG32(mmDC_HPD_INT_CONTROL + hpd_offsets[hpd], tmp); 3362 - } 3363 - 3364 - static void dce_v11_0_crtc_vblank_int_ack(struct amdgpu_device *adev, 3365 - int crtc) 3366 - { 3367 - u32 tmp; 3368 - 3369 - if (crtc < 0 || crtc >= adev->mode_info.num_crtc) { 3370 - DRM_DEBUG("invalid crtc %d\n", crtc); 3371 - return; 3372 - } 3373 - 3374 - tmp = RREG32(mmLB_VBLANK_STATUS + crtc_offsets[crtc]); 3375 - tmp = REG_SET_FIELD(tmp, LB_VBLANK_STATUS, VBLANK_ACK, 1); 3376 - WREG32(mmLB_VBLANK_STATUS + crtc_offsets[crtc], tmp); 3377 - } 3378 - 3379 - static void dce_v11_0_crtc_vline_int_ack(struct amdgpu_device *adev, 3380 - int crtc) 3381 - { 3382 - u32 tmp; 3383 - 3384 - if (crtc < 0 || crtc >= adev->mode_info.num_crtc) { 3385 - DRM_DEBUG("invalid crtc %d\n", crtc); 3386 - return; 3387 - } 3388 - 3389 - tmp = RREG32(mmLB_VLINE_STATUS + crtc_offsets[crtc]); 3390 - tmp = REG_SET_FIELD(tmp, LB_VLINE_STATUS, VLINE_ACK, 1); 3391 - WREG32(mmLB_VLINE_STATUS + crtc_offsets[crtc], tmp); 3392 - } 3393 - 3394 - static int dce_v11_0_crtc_irq(struct amdgpu_device *adev, 3395 - struct amdgpu_irq_src *source, 3396 - struct amdgpu_iv_entry *entry) 3397 - { 3398 - unsigned crtc = entry->src_id - 1; 3399 - uint32_t disp_int = RREG32(interrupt_status_offsets[crtc].reg); 3400 - unsigned int irq_type = amdgpu_display_crtc_idx_to_irq_type(adev, 3401 - crtc); 3402 - 3403 - switch (entry->src_data[0]) { 3404 - case 0: /* vblank */ 3405 - if (disp_int & interrupt_status_offsets[crtc].vblank) 3406 - dce_v11_0_crtc_vblank_int_ack(adev, crtc); 3407 - else 3408 - DRM_DEBUG("IH: IH event w/o asserted irq bit?\n"); 3409 - 3410 - if (amdgpu_irq_enabled(adev, source, irq_type)) { 3411 - drm_handle_vblank(adev_to_drm(adev), crtc); 3412 - } 3413 - DRM_DEBUG("IH: D%d vblank\n", crtc + 1); 3414 - 3415 - break; 3416 - case 1: /* vline */ 3417 - if (disp_int & interrupt_status_offsets[crtc].vline) 3418 - dce_v11_0_crtc_vline_int_ack(adev, crtc); 3419 - else 3420 - DRM_DEBUG("IH: IH event w/o asserted irq bit?\n"); 3421 - 3422 - DRM_DEBUG("IH: D%d vline\n", crtc + 1); 3423 - 3424 - break; 3425 - default: 3426 - DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]); 3427 - break; 3428 - } 3429 - 3430 - return 0; 3431 - } 3432 - 3433 - static int dce_v11_0_hpd_irq(struct amdgpu_device *adev, 3434 - struct amdgpu_irq_src *source, 3435 - struct amdgpu_iv_entry *entry) 3436 - { 3437 - uint32_t disp_int, mask; 3438 - unsigned hpd; 3439 - 3440 - if (entry->src_data[0] >= adev->mode_info.num_hpd) { 3441 - DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]); 3442 - return 0; 3443 - } 3444 - 3445 - hpd = entry->src_data[0]; 3446 - disp_int = RREG32(interrupt_status_offsets[hpd].reg); 3447 - mask = interrupt_status_offsets[hpd].hpd; 3448 - 3449 - if (disp_int & mask) { 3450 - dce_v11_0_hpd_int_ack(adev, hpd); 3451 - schedule_delayed_work(&adev->hotplug_work, 0); 3452 - DRM_DEBUG("IH: HPD%d\n", hpd + 1); 3453 - } 3454 - 3455 - return 0; 3456 - } 3457 - 3458 - static int dce_v11_0_set_clockgating_state(struct amdgpu_ip_block *ip_block, 3459 - enum amd_clockgating_state state) 3460 - { 3461 - return 0; 3462 - } 3463 - 3464 - static int dce_v11_0_set_powergating_state(struct amdgpu_ip_block *ip_block, 3465 - enum amd_powergating_state state) 3466 - { 3467 - return 0; 3468 - } 3469 - 3470 - static const struct amd_ip_funcs dce_v11_0_ip_funcs = { 3471 - .name = "dce_v11_0", 3472 - .early_init = dce_v11_0_early_init, 3473 - .sw_init = dce_v11_0_sw_init, 3474 - .sw_fini = dce_v11_0_sw_fini, 3475 - .hw_init = dce_v11_0_hw_init, 3476 - .hw_fini = dce_v11_0_hw_fini, 3477 - .suspend = dce_v11_0_suspend, 3478 - .resume = dce_v11_0_resume, 3479 - .is_idle = dce_v11_0_is_idle, 3480 - .soft_reset = dce_v11_0_soft_reset, 3481 - .set_clockgating_state = dce_v11_0_set_clockgating_state, 3482 - .set_powergating_state = dce_v11_0_set_powergating_state, 3483 - }; 3484 - 3485 - static void dce_v11_0_encoder_mode_set(struct drm_encoder *encoder, 3486 - struct drm_display_mode *mode, 3487 - struct drm_display_mode *adjusted_mode) 3488 - { 3489 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 3490 - 3491 - amdgpu_encoder->pixel_clock = adjusted_mode->clock; 3492 - 3493 - /* need to call this here rather than in prepare() since we need some crtc info */ 3494 - amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 3495 - 3496 - /* set scaler clears this on some chips */ 3497 - dce_v11_0_set_interleave(encoder->crtc, mode); 3498 - 3499 - if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) { 3500 - dce_v11_0_afmt_enable(encoder, true); 3501 - dce_v11_0_afmt_setmode(encoder, adjusted_mode); 3502 - } 3503 - } 3504 - 3505 - static void dce_v11_0_encoder_prepare(struct drm_encoder *encoder) 3506 - { 3507 - struct amdgpu_device *adev = drm_to_adev(encoder->dev); 3508 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 3509 - struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder); 3510 - 3511 - if ((amdgpu_encoder->active_device & 3512 - (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) || 3513 - (amdgpu_encoder_get_dp_bridge_encoder_id(encoder) != 3514 - ENCODER_OBJECT_ID_NONE)) { 3515 - struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv; 3516 - if (dig) { 3517 - dig->dig_encoder = dce_v11_0_pick_dig_encoder(encoder); 3518 - if (amdgpu_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT) 3519 - dig->afmt = adev->mode_info.afmt[dig->dig_encoder]; 3520 - } 3521 - } 3522 - 3523 - amdgpu_atombios_scratch_regs_lock(adev, true); 3524 - 3525 - if (connector) { 3526 - struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector); 3527 - 3528 - /* select the clock/data port if it uses a router */ 3529 - if (amdgpu_connector->router.cd_valid) 3530 - amdgpu_i2c_router_select_cd_port(amdgpu_connector); 3531 - 3532 - /* turn eDP panel on for mode set */ 3533 - if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) 3534 - amdgpu_atombios_encoder_set_edp_panel_power(connector, 3535 - ATOM_TRANSMITTER_ACTION_POWER_ON); 3536 - } 3537 - 3538 - /* this is needed for the pll/ss setup to work correctly in some cases */ 3539 - amdgpu_atombios_encoder_set_crtc_source(encoder); 3540 - /* set up the FMT blocks */ 3541 - dce_v11_0_program_fmt(encoder); 3542 - } 3543 - 3544 - static void dce_v11_0_encoder_commit(struct drm_encoder *encoder) 3545 - { 3546 - struct drm_device *dev = encoder->dev; 3547 - struct amdgpu_device *adev = drm_to_adev(dev); 3548 - 3549 - /* need to call this here as we need the crtc set up */ 3550 - amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_ON); 3551 - amdgpu_atombios_scratch_regs_lock(adev, false); 3552 - } 3553 - 3554 - static void dce_v11_0_encoder_disable(struct drm_encoder *encoder) 3555 - { 3556 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 3557 - struct amdgpu_encoder_atom_dig *dig; 3558 - 3559 - amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); 3560 - 3561 - if (amdgpu_atombios_encoder_is_digital(encoder)) { 3562 - if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) 3563 - dce_v11_0_afmt_enable(encoder, false); 3564 - dig = amdgpu_encoder->enc_priv; 3565 - dig->dig_encoder = -1; 3566 - } 3567 - amdgpu_encoder->active_device = 0; 3568 - } 3569 - 3570 - /* these are handled by the primary encoders */ 3571 - static void dce_v11_0_ext_prepare(struct drm_encoder *encoder) 3572 - { 3573 - 3574 - } 3575 - 3576 - static void dce_v11_0_ext_commit(struct drm_encoder *encoder) 3577 - { 3578 - 3579 - } 3580 - 3581 - static void 3582 - dce_v11_0_ext_mode_set(struct drm_encoder *encoder, 3583 - struct drm_display_mode *mode, 3584 - struct drm_display_mode *adjusted_mode) 3585 - { 3586 - 3587 - } 3588 - 3589 - static void dce_v11_0_ext_disable(struct drm_encoder *encoder) 3590 - { 3591 - 3592 - } 3593 - 3594 - static void 3595 - dce_v11_0_ext_dpms(struct drm_encoder *encoder, int mode) 3596 - { 3597 - 3598 - } 3599 - 3600 - static const struct drm_encoder_helper_funcs dce_v11_0_ext_helper_funcs = { 3601 - .dpms = dce_v11_0_ext_dpms, 3602 - .prepare = dce_v11_0_ext_prepare, 3603 - .mode_set = dce_v11_0_ext_mode_set, 3604 - .commit = dce_v11_0_ext_commit, 3605 - .disable = dce_v11_0_ext_disable, 3606 - /* no detect for TMDS/LVDS yet */ 3607 - }; 3608 - 3609 - static const struct drm_encoder_helper_funcs dce_v11_0_dig_helper_funcs = { 3610 - .dpms = amdgpu_atombios_encoder_dpms, 3611 - .mode_fixup = amdgpu_atombios_encoder_mode_fixup, 3612 - .prepare = dce_v11_0_encoder_prepare, 3613 - .mode_set = dce_v11_0_encoder_mode_set, 3614 - .commit = dce_v11_0_encoder_commit, 3615 - .disable = dce_v11_0_encoder_disable, 3616 - .detect = amdgpu_atombios_encoder_dig_detect, 3617 - }; 3618 - 3619 - static const struct drm_encoder_helper_funcs dce_v11_0_dac_helper_funcs = { 3620 - .dpms = amdgpu_atombios_encoder_dpms, 3621 - .mode_fixup = amdgpu_atombios_encoder_mode_fixup, 3622 - .prepare = dce_v11_0_encoder_prepare, 3623 - .mode_set = dce_v11_0_encoder_mode_set, 3624 - .commit = dce_v11_0_encoder_commit, 3625 - .detect = amdgpu_atombios_encoder_dac_detect, 3626 - }; 3627 - 3628 - static void dce_v11_0_encoder_destroy(struct drm_encoder *encoder) 3629 - { 3630 - struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); 3631 - if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 3632 - amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder); 3633 - kfree(amdgpu_encoder->enc_priv); 3634 - drm_encoder_cleanup(encoder); 3635 - kfree(amdgpu_encoder); 3636 - } 3637 - 3638 - static const struct drm_encoder_funcs dce_v11_0_encoder_funcs = { 3639 - .destroy = dce_v11_0_encoder_destroy, 3640 - }; 3641 - 3642 - static void dce_v11_0_encoder_add(struct amdgpu_device *adev, 3643 - uint32_t encoder_enum, 3644 - uint32_t supported_device, 3645 - u16 caps) 3646 - { 3647 - struct drm_device *dev = adev_to_drm(adev); 3648 - struct drm_encoder *encoder; 3649 - struct amdgpu_encoder *amdgpu_encoder; 3650 - 3651 - /* see if we already added it */ 3652 - list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 3653 - amdgpu_encoder = to_amdgpu_encoder(encoder); 3654 - if (amdgpu_encoder->encoder_enum == encoder_enum) { 3655 - amdgpu_encoder->devices |= supported_device; 3656 - return; 3657 - } 3658 - 3659 - } 3660 - 3661 - /* add a new one */ 3662 - amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL); 3663 - if (!amdgpu_encoder) 3664 - return; 3665 - 3666 - encoder = &amdgpu_encoder->base; 3667 - switch (adev->mode_info.num_crtc) { 3668 - case 1: 3669 - encoder->possible_crtcs = 0x1; 3670 - break; 3671 - case 2: 3672 - default: 3673 - encoder->possible_crtcs = 0x3; 3674 - break; 3675 - case 3: 3676 - encoder->possible_crtcs = 0x7; 3677 - break; 3678 - case 4: 3679 - encoder->possible_crtcs = 0xf; 3680 - break; 3681 - case 5: 3682 - encoder->possible_crtcs = 0x1f; 3683 - break; 3684 - case 6: 3685 - encoder->possible_crtcs = 0x3f; 3686 - break; 3687 - } 3688 - 3689 - amdgpu_encoder->enc_priv = NULL; 3690 - 3691 - amdgpu_encoder->encoder_enum = encoder_enum; 3692 - amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; 3693 - amdgpu_encoder->devices = supported_device; 3694 - amdgpu_encoder->rmx_type = RMX_OFF; 3695 - amdgpu_encoder->underscan_type = UNDERSCAN_OFF; 3696 - amdgpu_encoder->is_ext_encoder = false; 3697 - amdgpu_encoder->caps = caps; 3698 - 3699 - switch (amdgpu_encoder->encoder_id) { 3700 - case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1: 3701 - case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2: 3702 - drm_encoder_init(dev, encoder, &dce_v11_0_encoder_funcs, 3703 - DRM_MODE_ENCODER_DAC, NULL); 3704 - drm_encoder_helper_add(encoder, &dce_v11_0_dac_helper_funcs); 3705 - break; 3706 - case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: 3707 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: 3708 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: 3709 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: 3710 - case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3: 3711 - if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 3712 - amdgpu_encoder->rmx_type = RMX_FULL; 3713 - drm_encoder_init(dev, encoder, &dce_v11_0_encoder_funcs, 3714 - DRM_MODE_ENCODER_LVDS, NULL); 3715 - amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder); 3716 - } else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) { 3717 - drm_encoder_init(dev, encoder, &dce_v11_0_encoder_funcs, 3718 - DRM_MODE_ENCODER_DAC, NULL); 3719 - amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder); 3720 - } else { 3721 - drm_encoder_init(dev, encoder, &dce_v11_0_encoder_funcs, 3722 - DRM_MODE_ENCODER_TMDS, NULL); 3723 - amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder); 3724 - } 3725 - drm_encoder_helper_add(encoder, &dce_v11_0_dig_helper_funcs); 3726 - break; 3727 - case ENCODER_OBJECT_ID_SI170B: 3728 - case ENCODER_OBJECT_ID_CH7303: 3729 - case ENCODER_OBJECT_ID_EXTERNAL_SDVOA: 3730 - case ENCODER_OBJECT_ID_EXTERNAL_SDVOB: 3731 - case ENCODER_OBJECT_ID_TITFP513: 3732 - case ENCODER_OBJECT_ID_VT1623: 3733 - case ENCODER_OBJECT_ID_HDMI_SI1930: 3734 - case ENCODER_OBJECT_ID_TRAVIS: 3735 - case ENCODER_OBJECT_ID_NUTMEG: 3736 - /* these are handled by the primary encoders */ 3737 - amdgpu_encoder->is_ext_encoder = true; 3738 - if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 3739 - drm_encoder_init(dev, encoder, &dce_v11_0_encoder_funcs, 3740 - DRM_MODE_ENCODER_LVDS, NULL); 3741 - else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) 3742 - drm_encoder_init(dev, encoder, &dce_v11_0_encoder_funcs, 3743 - DRM_MODE_ENCODER_DAC, NULL); 3744 - else 3745 - drm_encoder_init(dev, encoder, &dce_v11_0_encoder_funcs, 3746 - DRM_MODE_ENCODER_TMDS, NULL); 3747 - drm_encoder_helper_add(encoder, &dce_v11_0_ext_helper_funcs); 3748 - break; 3749 - } 3750 - } 3751 - 3752 - static const struct amdgpu_display_funcs dce_v11_0_display_funcs = { 3753 - .bandwidth_update = &dce_v11_0_bandwidth_update, 3754 - .vblank_get_counter = &dce_v11_0_vblank_get_counter, 3755 - .backlight_set_level = &amdgpu_atombios_encoder_set_backlight_level, 3756 - .backlight_get_level = &amdgpu_atombios_encoder_get_backlight_level, 3757 - .hpd_sense = &dce_v11_0_hpd_sense, 3758 - .hpd_set_polarity = &dce_v11_0_hpd_set_polarity, 3759 - .hpd_get_gpio_reg = &dce_v11_0_hpd_get_gpio_reg, 3760 - .page_flip = &dce_v11_0_page_flip, 3761 - .page_flip_get_scanoutpos = &dce_v11_0_crtc_get_scanoutpos, 3762 - .add_encoder = &dce_v11_0_encoder_add, 3763 - .add_connector = &amdgpu_connector_add, 3764 - }; 3765 - 3766 - static void dce_v11_0_set_display_funcs(struct amdgpu_device *adev) 3767 - { 3768 - adev->mode_info.funcs = &dce_v11_0_display_funcs; 3769 - } 3770 - 3771 - static const struct amdgpu_irq_src_funcs dce_v11_0_crtc_irq_funcs = { 3772 - .set = dce_v11_0_set_crtc_irq_state, 3773 - .process = dce_v11_0_crtc_irq, 3774 - }; 3775 - 3776 - static const struct amdgpu_irq_src_funcs dce_v11_0_pageflip_irq_funcs = { 3777 - .set = dce_v11_0_set_pageflip_irq_state, 3778 - .process = dce_v11_0_pageflip_irq, 3779 - }; 3780 - 3781 - static const struct amdgpu_irq_src_funcs dce_v11_0_hpd_irq_funcs = { 3782 - .set = dce_v11_0_set_hpd_irq_state, 3783 - .process = dce_v11_0_hpd_irq, 3784 - }; 3785 - 3786 - static void dce_v11_0_set_irq_funcs(struct amdgpu_device *adev) 3787 - { 3788 - if (adev->mode_info.num_crtc > 0) 3789 - adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_VLINE1 + adev->mode_info.num_crtc; 3790 - else 3791 - adev->crtc_irq.num_types = 0; 3792 - adev->crtc_irq.funcs = &dce_v11_0_crtc_irq_funcs; 3793 - 3794 - adev->pageflip_irq.num_types = adev->mode_info.num_crtc; 3795 - adev->pageflip_irq.funcs = &dce_v11_0_pageflip_irq_funcs; 3796 - 3797 - adev->hpd_irq.num_types = adev->mode_info.num_hpd; 3798 - adev->hpd_irq.funcs = &dce_v11_0_hpd_irq_funcs; 3799 - } 3800 - 3801 - const struct amdgpu_ip_block_version dce_v11_0_ip_block = 3802 - { 3803 - .type = AMD_IP_BLOCK_TYPE_DCE, 3804 - .major = 11, 3805 - .minor = 0, 3806 - .rev = 0, 3807 - .funcs = &dce_v11_0_ip_funcs, 3808 - }; 3809 - 3810 - const struct amdgpu_ip_block_version dce_v11_2_ip_block = 3811 - { 3812 - .type = AMD_IP_BLOCK_TYPE_DCE, 3813 - .major = 11, 3814 - .minor = 2, 3815 - .rev = 0, 3816 - .funcs = &dce_v11_0_ip_funcs, 3817 - };
-32
drivers/gpu/drm/amd/amdgpu/dce_v11_0.h
··· 1 - /* 2 - * Copyright 2014 Advanced Micro Devices, Inc. 3 - * 4 - * Permission is hereby granted, free of charge, to any person obtaining a 5 - * copy of this software and associated documentation files (the "Software"), 6 - * to deal in the Software without restriction, including without limitation 7 - * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 - * and/or sell copies of the Software, and to permit persons to whom the 9 - * Software is furnished to do so, subject to the following conditions: 10 - * 11 - * The above copyright notice and this permission notice shall be included in 12 - * all copies or substantial portions of the Software. 13 - * 14 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 - * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 - * OTHER DEALINGS IN THE SOFTWARE. 21 - * 22 - */ 23 - 24 - #ifndef __DCE_V11_0_H__ 25 - #define __DCE_V11_0_H__ 26 - 27 - extern const struct amdgpu_ip_block_version dce_v11_0_ip_block; 28 - extern const struct amdgpu_ip_block_version dce_v11_2_ip_block; 29 - 30 - void dce_v11_0_disable_dce(struct amdgpu_device *adev); 31 - 32 - #endif
-7
drivers/gpu/drm/amd/amdgpu/vi.c
··· 67 67 #include "sdma_v2_4.h" 68 68 #include "sdma_v3_0.h" 69 69 #include "dce_v10_0.h" 70 - #include "dce_v11_0.h" 71 70 #include "iceland_ih.h" 72 71 #include "tonga_ih.h" 73 72 #include "cz_ih.h" ··· 2123 2124 else if (amdgpu_device_has_dc_support(adev)) 2124 2125 amdgpu_device_ip_block_add(adev, &dm_ip_block); 2125 2126 #endif 2126 - else 2127 - amdgpu_device_ip_block_add(adev, &dce_v11_2_ip_block); 2128 2127 amdgpu_device_ip_block_add(adev, &uvd_v6_3_ip_block); 2129 2128 amdgpu_device_ip_block_add(adev, &vce_v3_4_ip_block); 2130 2129 break; ··· 2139 2142 else if (amdgpu_device_has_dc_support(adev)) 2140 2143 amdgpu_device_ip_block_add(adev, &dm_ip_block); 2141 2144 #endif 2142 - else 2143 - amdgpu_device_ip_block_add(adev, &dce_v11_0_ip_block); 2144 2145 amdgpu_device_ip_block_add(adev, &uvd_v6_0_ip_block); 2145 2146 amdgpu_device_ip_block_add(adev, &vce_v3_1_ip_block); 2146 2147 #if defined(CONFIG_DRM_AMD_ACP) ··· 2158 2163 else if (amdgpu_device_has_dc_support(adev)) 2159 2164 amdgpu_device_ip_block_add(adev, &dm_ip_block); 2160 2165 #endif 2161 - else 2162 - amdgpu_device_ip_block_add(adev, &dce_v11_0_ip_block); 2163 2166 amdgpu_device_ip_block_add(adev, &uvd_v6_2_ip_block); 2164 2167 amdgpu_device_ip_block_add(adev, &vce_v3_4_ip_block); 2165 2168 #if defined(CONFIG_DRM_AMD_ACP)