2 * Copyright 2015 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include "amdgpu_pm.h"
26 #include "amdgpu_i2c.h"
28 #include "amdgpu_atombios.h"
29 #include "atombios_crtc.h"
30 #include "atombios_encoders.h"
31 #include "amdgpu_pll.h"
32 #include "amdgpu_connectors.h"
34 #include "bif/bif_3_0_d.h"
35 #include "bif/bif_3_0_sh_mask.h"
36 #include "oss/oss_1_0_d.h"
37 #include "oss/oss_1_0_sh_mask.h"
38 #include "gca/gfx_6_0_d.h"
39 #include "gca/gfx_6_0_sh_mask.h"
40 #include "gmc/gmc_6_0_d.h"
41 #include "gmc/gmc_6_0_sh_mask.h"
42 #include "dce/dce_6_0_d.h"
43 #include "dce/dce_6_0_sh_mask.h"
44 #include "gca/gfx_7_2_enum.h"
47 static void dce_v6_0_set_display_funcs(struct amdgpu_device *adev);
48 static void dce_v6_0_set_irq_funcs(struct amdgpu_device *adev);
50 static const u32 crtc_offsets[6] =
52 SI_CRTC0_REGISTER_OFFSET,
53 SI_CRTC1_REGISTER_OFFSET,
54 SI_CRTC2_REGISTER_OFFSET,
55 SI_CRTC3_REGISTER_OFFSET,
56 SI_CRTC4_REGISTER_OFFSET,
57 SI_CRTC5_REGISTER_OFFSET
60 static const u32 hpd_offsets[] =
62 mmDC_HPD1_INT_STATUS - mmDC_HPD1_INT_STATUS,
63 mmDC_HPD2_INT_STATUS - mmDC_HPD1_INT_STATUS,
64 mmDC_HPD3_INT_STATUS - mmDC_HPD1_INT_STATUS,
65 mmDC_HPD4_INT_STATUS - mmDC_HPD1_INT_STATUS,
66 mmDC_HPD5_INT_STATUS - mmDC_HPD1_INT_STATUS,
67 mmDC_HPD6_INT_STATUS - mmDC_HPD1_INT_STATUS,
70 static const uint32_t dig_offsets[] = {
71 SI_CRTC0_REGISTER_OFFSET,
72 SI_CRTC1_REGISTER_OFFSET,
73 SI_CRTC2_REGISTER_OFFSET,
74 SI_CRTC3_REGISTER_OFFSET,
75 SI_CRTC4_REGISTER_OFFSET,
76 SI_CRTC5_REGISTER_OFFSET,
77 (0x13830 - 0x7030) >> 2,
86 } interrupt_status_offsets[6] = { {
87 .reg = mmDISP_INTERRUPT_STATUS,
88 .vblank = DISP_INTERRUPT_STATUS__LB_D1_VBLANK_INTERRUPT_MASK,
89 .vline = DISP_INTERRUPT_STATUS__LB_D1_VLINE_INTERRUPT_MASK,
90 .hpd = DISP_INTERRUPT_STATUS__DC_HPD1_INTERRUPT_MASK
92 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE,
93 .vblank = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VBLANK_INTERRUPT_MASK,
94 .vline = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VLINE_INTERRUPT_MASK,
95 .hpd = DISP_INTERRUPT_STATUS_CONTINUE__DC_HPD2_INTERRUPT_MASK
97 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE2,
98 .vblank = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VBLANK_INTERRUPT_MASK,
99 .vline = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VLINE_INTERRUPT_MASK,
100 .hpd = DISP_INTERRUPT_STATUS_CONTINUE2__DC_HPD3_INTERRUPT_MASK
102 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE3,
103 .vblank = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VBLANK_INTERRUPT_MASK,
104 .vline = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VLINE_INTERRUPT_MASK,
105 .hpd = DISP_INTERRUPT_STATUS_CONTINUE3__DC_HPD4_INTERRUPT_MASK
107 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE4,
108 .vblank = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VBLANK_INTERRUPT_MASK,
109 .vline = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VLINE_INTERRUPT_MASK,
110 .hpd = DISP_INTERRUPT_STATUS_CONTINUE4__DC_HPD5_INTERRUPT_MASK
112 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE5,
113 .vblank = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VBLANK_INTERRUPT_MASK,
114 .vline = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VLINE_INTERRUPT_MASK,
115 .hpd = DISP_INTERRUPT_STATUS_CONTINUE5__DC_HPD6_INTERRUPT_MASK
118 static u32 dce_v6_0_audio_endpt_rreg(struct amdgpu_device *adev,
119 u32 block_offset, u32 reg)
121 DRM_INFO("xxxx: dce_v6_0_audio_endpt_rreg ----no impl!!!!\n");
125 static void dce_v6_0_audio_endpt_wreg(struct amdgpu_device *adev,
126 u32 block_offset, u32 reg, u32 v)
128 DRM_INFO("xxxx: dce_v6_0_audio_endpt_wreg ----no impl!!!!\n");
131 static bool dce_v6_0_is_in_vblank(struct amdgpu_device *adev, int crtc)
133 if (RREG32(mmCRTC_STATUS + crtc_offsets[crtc]) & CRTC_STATUS__CRTC_V_BLANK_MASK)
139 static bool dce_v6_0_is_counter_moving(struct amdgpu_device *adev, int crtc)
143 pos1 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
144 pos2 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
153 * dce_v6_0_wait_for_vblank - vblank wait asic callback.
155 * @crtc: crtc to wait for vblank on
157 * Wait for vblank on the requested crtc (evergreen+).
159 static void dce_v6_0_vblank_wait(struct amdgpu_device *adev, int crtc)
163 if (crtc >= adev->mode_info.num_crtc)
166 if (!(RREG32(mmCRTC_CONTROL + crtc_offsets[crtc]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK))
169 /* depending on when we hit vblank, we may be close to active; if so,
170 * wait for another frame.
172 while (dce_v6_0_is_in_vblank(adev, crtc)) {
175 if (!dce_v6_0_is_counter_moving(adev, crtc))
180 while (!dce_v6_0_is_in_vblank(adev, crtc)) {
183 if (!dce_v6_0_is_counter_moving(adev, crtc))
189 static u32 dce_v6_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
191 if (crtc >= adev->mode_info.num_crtc)
194 return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
197 static void dce_v6_0_pageflip_interrupt_init(struct amdgpu_device *adev)
201 /* Enable pflip interrupts */
202 for (i = 0; i < adev->mode_info.num_crtc; i++)
203 amdgpu_irq_get(adev, &adev->pageflip_irq, i);
206 static void dce_v6_0_pageflip_interrupt_fini(struct amdgpu_device *adev)
210 /* Disable pflip interrupts */
211 for (i = 0; i < adev->mode_info.num_crtc; i++)
212 amdgpu_irq_put(adev, &adev->pageflip_irq, i);
216 * dce_v6_0_page_flip - pageflip callback.
218 * @adev: amdgpu_device pointer
219 * @crtc_id: crtc to cleanup pageflip on
220 * @crtc_base: new address of the crtc (GPU MC address)
222 * Does the actual pageflip (evergreen+).
223 * During vblank we take the crtc lock and wait for the update_pending
224 * bit to go high, when it does, we release the lock, and allow the
225 * double buffered update to take place.
226 * Returns the current update pending status.
228 static void dce_v6_0_page_flip(struct amdgpu_device *adev,
229 int crtc_id, u64 crtc_base, bool async)
231 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
233 /* flip at hsync for async, default is vsync */
234 WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, async ?
235 GRPH_FLIP_CONTROL__GRPH_SURFACE_UPDATE_H_RETRACE_EN_MASK : 0);
236 /* update the scanout addresses */
237 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
238 upper_32_bits(crtc_base));
239 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
243 RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
246 static int dce_v6_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
247 u32 *vbl, u32 *position)
249 if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
251 *vbl = RREG32(mmCRTC_V_BLANK_START_END + crtc_offsets[crtc]);
252 *position = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
259 * dce_v6_0_hpd_sense - hpd sense callback.
261 * @adev: amdgpu_device pointer
262 * @hpd: hpd (hotplug detect) pin
264 * Checks if a digital monitor is connected (evergreen+).
265 * Returns true if connected, false if not connected.
267 static bool dce_v6_0_hpd_sense(struct amdgpu_device *adev,
268 enum amdgpu_hpd_id hpd)
270 bool connected = false;
272 if (hpd >= adev->mode_info.num_hpd)
275 if (RREG32(mmDC_HPD1_INT_STATUS + hpd_offsets[hpd]) & DC_HPD1_INT_STATUS__DC_HPD1_SENSE_MASK)
282 * dce_v6_0_hpd_set_polarity - hpd set polarity callback.
284 * @adev: amdgpu_device pointer
285 * @hpd: hpd (hotplug detect) pin
287 * Set the polarity of the hpd pin (evergreen+).
289 static void dce_v6_0_hpd_set_polarity(struct amdgpu_device *adev,
290 enum amdgpu_hpd_id hpd)
293 bool connected = dce_v6_0_hpd_sense(adev, hpd);
295 if (hpd >= adev->mode_info.num_hpd)
298 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
300 tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
302 tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
303 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
307 * dce_v6_0_hpd_init - hpd setup callback.
309 * @adev: amdgpu_device pointer
311 * Setup the hpd pins used by the card (evergreen+).
312 * Enable the pin, set the polarity, and enable the hpd interrupts.
314 static void dce_v6_0_hpd_init(struct amdgpu_device *adev)
316 struct drm_device *dev = adev->ddev;
317 struct drm_connector *connector;
320 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
321 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
323 if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
326 tmp = RREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
327 tmp |= DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
328 WREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
330 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
331 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
332 /* don't try to enable hpd on eDP or LVDS avoid breaking the
333 * aux dp channel on imac and help (but not completely fix)
334 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
335 * also avoid interrupt storms during dpms.
337 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
338 tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
339 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
343 dce_v6_0_hpd_set_polarity(adev, amdgpu_connector->hpd.hpd);
344 amdgpu_irq_get(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
350 * dce_v6_0_hpd_fini - hpd tear down callback.
352 * @adev: amdgpu_device pointer
354 * Tear down the hpd pins used by the card (evergreen+).
355 * Disable the hpd interrupts.
357 static void dce_v6_0_hpd_fini(struct amdgpu_device *adev)
359 struct drm_device *dev = adev->ddev;
360 struct drm_connector *connector;
363 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
364 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
366 if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
369 tmp = RREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
370 tmp &= ~DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
371 WREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], 0);
373 amdgpu_irq_put(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
377 static u32 dce_v6_0_hpd_get_gpio_reg(struct amdgpu_device *adev)
379 return mmDC_GPIO_HPD_A;
382 static u32 evergreen_get_vblank_counter(struct amdgpu_device* adev, int crtc)
384 if (crtc >= adev->mode_info.num_crtc)
387 return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
390 static void dce_v6_0_stop_mc_access(struct amdgpu_device *adev,
391 struct amdgpu_mode_mc_save *save)
393 u32 crtc_enabled, tmp, frame_count;
396 save->vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
397 save->vga_hdp_control = RREG32(mmVGA_HDP_CONTROL);
399 /* disable VGA render */
400 WREG32(mmVGA_RENDER_CONTROL, 0);
402 /* blank the display controllers */
403 for (i = 0; i < adev->mode_info.num_crtc; i++) {
404 crtc_enabled = RREG32(mmCRTC_CONTROL + crtc_offsets[i]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK;
406 save->crtc_enabled[i] = true;
407 tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
409 if (!(tmp & CRTC_BLANK_CONTROL__CRTC_BLANK_DATA_EN_MASK)) {
410 dce_v6_0_vblank_wait(adev, i);
411 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
412 tmp |= CRTC_BLANK_CONTROL__CRTC_BLANK_DATA_EN_MASK;
413 WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
414 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
416 /* wait for the next frame */
417 frame_count = evergreen_get_vblank_counter(adev, i);
418 for (j = 0; j < adev->usec_timeout; j++) {
419 if (evergreen_get_vblank_counter(adev, i) != frame_count)
424 /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
425 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
426 tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
427 tmp &= ~CRTC_CONTROL__CRTC_MASTER_EN_MASK;
428 WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
429 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
430 save->crtc_enabled[i] = false;
433 save->crtc_enabled[i] = false;
438 static void dce_v6_0_resume_mc_access(struct amdgpu_device *adev,
439 struct amdgpu_mode_mc_save *save)
444 /* update crtc base addresses */
445 for (i = 0; i < adev->mode_info.num_crtc; i++) {
446 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
447 upper_32_bits(adev->mc.vram_start));
448 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
449 upper_32_bits(adev->mc.vram_start));
450 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
451 (u32)adev->mc.vram_start);
452 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
453 (u32)adev->mc.vram_start);
456 WREG32(mmVGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(adev->mc.vram_start));
457 WREG32(mmVGA_MEMORY_BASE_ADDRESS, (u32)adev->mc.vram_start);
459 /* unlock regs and wait for update */
460 for (i = 0; i < adev->mode_info.num_crtc; i++) {
461 if (save->crtc_enabled[i]) {
462 tmp = RREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i]);
463 if ((tmp & 0x7) != 0) {
465 WREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i], tmp);
467 tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
468 if (tmp & GRPH_UPDATE__GRPH_UPDATE_LOCK_MASK) {
469 tmp &= ~GRPH_UPDATE__GRPH_UPDATE_LOCK_MASK;
470 WREG32(mmGRPH_UPDATE + crtc_offsets[i], tmp);
472 tmp = RREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i]);
475 WREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
477 for (j = 0; j < adev->usec_timeout; j++) {
478 tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
479 if ((tmp & GRPH_UPDATE__GRPH_SURFACE_UPDATE_PENDING_MASK) == 0)
486 /* Unlock vga access */
487 WREG32(mmVGA_HDP_CONTROL, save->vga_hdp_control);
489 WREG32(mmVGA_RENDER_CONTROL, save->vga_render_control);
493 static void dce_v6_0_set_vga_render_state(struct amdgpu_device *adev,
497 WREG32(mmVGA_RENDER_CONTROL,
498 RREG32(mmVGA_RENDER_CONTROL) & VGA_VSTATUS_CNTL);
502 static int dce_v6_0_get_num_crtc(struct amdgpu_device *adev)
506 switch (adev->asic_type) {
521 void dce_v6_0_disable_dce(struct amdgpu_device *adev)
523 /*Disable VGA render and enabled crtc, if has DCE engine*/
524 if (amdgpu_atombios_has_dce_engine_info(adev)) {
528 dce_v6_0_set_vga_render_state(adev, false);
531 for (i = 0; i < dce_v6_0_get_num_crtc(adev); i++) {
532 crtc_enabled = RREG32(mmCRTC_CONTROL + crtc_offsets[i]) &
533 CRTC_CONTROL__CRTC_MASTER_EN_MASK;
535 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
536 tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
537 tmp &= ~CRTC_CONTROL__CRTC_MASTER_EN_MASK;
538 WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
539 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
545 static void dce_v6_0_program_fmt(struct drm_encoder *encoder)
548 struct drm_device *dev = encoder->dev;
549 struct amdgpu_device *adev = dev->dev_private;
550 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
551 struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
552 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
555 enum amdgpu_connector_dither dither = AMDGPU_FMT_DITHER_DISABLE;
558 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
559 bpc = amdgpu_connector_get_monitor_bpc(connector);
560 dither = amdgpu_connector->dither;
563 /* LVDS FMT is set up by atom */
564 if (amdgpu_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
573 if (dither == AMDGPU_FMT_DITHER_ENABLE)
574 /* XXX sort out optimal dither settings */
575 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
576 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
577 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK);
579 tmp |= FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK;
582 if (dither == AMDGPU_FMT_DITHER_ENABLE)
583 /* XXX sort out optimal dither settings */
584 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
585 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
586 FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
587 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
588 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH_MASK);
590 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
591 FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH_MASK);
599 WREG32(mmFMT_BIT_DEPTH_CONTROL + amdgpu_crtc->crtc_offset, tmp);
603 * cik_get_number_of_dram_channels - get the number of dram channels
605 * @adev: amdgpu_device pointer
607 * Look up the number of video ram channels (CIK).
608 * Used for display watermark bandwidth calculations
609 * Returns the number of dram channels
611 static u32 si_get_number_of_dram_channels(struct amdgpu_device *adev)
613 u32 tmp = RREG32(mmMC_SHARED_CHMAP);
615 switch ((tmp & MC_SHARED_CHMAP__NOOFCHAN_MASK) >> MC_SHARED_CHMAP__NOOFCHAN__SHIFT) {
638 struct dce6_wm_params {
639 u32 dram_channels; /* number of dram channels */
640 u32 yclk; /* bandwidth per dram data pin in kHz */
641 u32 sclk; /* engine clock in kHz */
642 u32 disp_clk; /* display clock in kHz */
643 u32 src_width; /* viewport width */
644 u32 active_time; /* active display time in ns */
645 u32 blank_time; /* blank time in ns */
646 bool interlaced; /* mode is interlaced */
647 fixed20_12 vsc; /* vertical scale ratio */
648 u32 num_heads; /* number of active crtcs */
649 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
650 u32 lb_size; /* line buffer allocated to pipe */
651 u32 vtaps; /* vertical scaler taps */
655 * dce_v6_0_dram_bandwidth - get the dram bandwidth
657 * @wm: watermark calculation data
659 * Calculate the raw dram bandwidth (CIK).
660 * Used for display watermark bandwidth calculations
661 * Returns the dram bandwidth in MBytes/s
663 static u32 dce_v6_0_dram_bandwidth(struct dce6_wm_params *wm)
665 /* Calculate raw DRAM Bandwidth */
666 fixed20_12 dram_efficiency; /* 0.7 */
667 fixed20_12 yclk, dram_channels, bandwidth;
670 a.full = dfixed_const(1000);
671 yclk.full = dfixed_const(wm->yclk);
672 yclk.full = dfixed_div(yclk, a);
673 dram_channels.full = dfixed_const(wm->dram_channels * 4);
674 a.full = dfixed_const(10);
675 dram_efficiency.full = dfixed_const(7);
676 dram_efficiency.full = dfixed_div(dram_efficiency, a);
677 bandwidth.full = dfixed_mul(dram_channels, yclk);
678 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
680 return dfixed_trunc(bandwidth);
684 * dce_v6_0_dram_bandwidth_for_display - get the dram bandwidth for display
686 * @wm: watermark calculation data
688 * Calculate the dram bandwidth used for display (CIK).
689 * Used for display watermark bandwidth calculations
690 * Returns the dram bandwidth for display in MBytes/s
692 static u32 dce_v6_0_dram_bandwidth_for_display(struct dce6_wm_params *wm)
694 /* Calculate DRAM Bandwidth and the part allocated to display. */
695 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
696 fixed20_12 yclk, dram_channels, bandwidth;
699 a.full = dfixed_const(1000);
700 yclk.full = dfixed_const(wm->yclk);
701 yclk.full = dfixed_div(yclk, a);
702 dram_channels.full = dfixed_const(wm->dram_channels * 4);
703 a.full = dfixed_const(10);
704 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
705 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
706 bandwidth.full = dfixed_mul(dram_channels, yclk);
707 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
709 return dfixed_trunc(bandwidth);
713 * dce_v6_0_data_return_bandwidth - get the data return bandwidth
715 * @wm: watermark calculation data
717 * Calculate the data return bandwidth used for display (CIK).
718 * Used for display watermark bandwidth calculations
719 * Returns the data return bandwidth in MBytes/s
721 static u32 dce_v6_0_data_return_bandwidth(struct dce6_wm_params *wm)
723 /* Calculate the display Data return Bandwidth */
724 fixed20_12 return_efficiency; /* 0.8 */
725 fixed20_12 sclk, bandwidth;
728 a.full = dfixed_const(1000);
729 sclk.full = dfixed_const(wm->sclk);
730 sclk.full = dfixed_div(sclk, a);
731 a.full = dfixed_const(10);
732 return_efficiency.full = dfixed_const(8);
733 return_efficiency.full = dfixed_div(return_efficiency, a);
734 a.full = dfixed_const(32);
735 bandwidth.full = dfixed_mul(a, sclk);
736 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
738 return dfixed_trunc(bandwidth);
742 * dce_v6_0_dmif_request_bandwidth - get the dmif bandwidth
744 * @wm: watermark calculation data
746 * Calculate the dmif bandwidth used for display (CIK).
747 * Used for display watermark bandwidth calculations
748 * Returns the dmif bandwidth in MBytes/s
750 static u32 dce_v6_0_dmif_request_bandwidth(struct dce6_wm_params *wm)
752 /* Calculate the DMIF Request Bandwidth */
753 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
754 fixed20_12 disp_clk, bandwidth;
757 a.full = dfixed_const(1000);
758 disp_clk.full = dfixed_const(wm->disp_clk);
759 disp_clk.full = dfixed_div(disp_clk, a);
760 a.full = dfixed_const(32);
761 b.full = dfixed_mul(a, disp_clk);
763 a.full = dfixed_const(10);
764 disp_clk_request_efficiency.full = dfixed_const(8);
765 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
767 bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
769 return dfixed_trunc(bandwidth);
773 * dce_v6_0_available_bandwidth - get the min available bandwidth
775 * @wm: watermark calculation data
777 * Calculate the min available bandwidth used for display (CIK).
778 * Used for display watermark bandwidth calculations
779 * Returns the min available bandwidth in MBytes/s
781 static u32 dce_v6_0_available_bandwidth(struct dce6_wm_params *wm)
783 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
784 u32 dram_bandwidth = dce_v6_0_dram_bandwidth(wm);
785 u32 data_return_bandwidth = dce_v6_0_data_return_bandwidth(wm);
786 u32 dmif_req_bandwidth = dce_v6_0_dmif_request_bandwidth(wm);
788 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
792 * dce_v6_0_average_bandwidth - get the average available bandwidth
794 * @wm: watermark calculation data
796 * Calculate the average available bandwidth used for display (CIK).
797 * Used for display watermark bandwidth calculations
798 * Returns the average available bandwidth in MBytes/s
800 static u32 dce_v6_0_average_bandwidth(struct dce6_wm_params *wm)
802 /* Calculate the display mode Average Bandwidth
803 * DisplayMode should contain the source and destination dimensions,
807 fixed20_12 line_time;
808 fixed20_12 src_width;
809 fixed20_12 bandwidth;
812 a.full = dfixed_const(1000);
813 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
814 line_time.full = dfixed_div(line_time, a);
815 bpp.full = dfixed_const(wm->bytes_per_pixel);
816 src_width.full = dfixed_const(wm->src_width);
817 bandwidth.full = dfixed_mul(src_width, bpp);
818 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
819 bandwidth.full = dfixed_div(bandwidth, line_time);
821 return dfixed_trunc(bandwidth);
825 * dce_v6_0_latency_watermark - get the latency watermark
827 * @wm: watermark calculation data
829 * Calculate the latency watermark (CIK).
830 * Used for display watermark bandwidth calculations
831 * Returns the latency watermark in ns
833 static u32 dce_v6_0_latency_watermark(struct dce6_wm_params *wm)
835 /* First calculate the latency in ns */
836 u32 mc_latency = 2000; /* 2000 ns. */
837 u32 available_bandwidth = dce_v6_0_available_bandwidth(wm);
838 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
839 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
840 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
841 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
842 (wm->num_heads * cursor_line_pair_return_time);
843 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
844 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
845 u32 tmp, dmif_size = 12288;
848 if (wm->num_heads == 0)
851 a.full = dfixed_const(2);
852 b.full = dfixed_const(1);
853 if ((wm->vsc.full > a.full) ||
854 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
856 ((wm->vsc.full >= a.full) && wm->interlaced))
857 max_src_lines_per_dst_line = 4;
859 max_src_lines_per_dst_line = 2;
861 a.full = dfixed_const(available_bandwidth);
862 b.full = dfixed_const(wm->num_heads);
863 a.full = dfixed_div(a, b);
864 tmp = div_u64((u64) dmif_size * (u64) wm->disp_clk, mc_latency + 512);
865 tmp = min(dfixed_trunc(a), tmp);
867 lb_fill_bw = min(tmp, wm->disp_clk * wm->bytes_per_pixel / 1000);
869 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
870 b.full = dfixed_const(1000);
871 c.full = dfixed_const(lb_fill_bw);
872 b.full = dfixed_div(c, b);
873 a.full = dfixed_div(a, b);
874 line_fill_time = dfixed_trunc(a);
876 if (line_fill_time < wm->active_time)
879 return latency + (line_fill_time - wm->active_time);
884 * dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display - check
885 * average and available dram bandwidth
887 * @wm: watermark calculation data
889 * Check if the display average bandwidth fits in the display
890 * dram bandwidth (CIK).
891 * Used for display watermark bandwidth calculations
892 * Returns true if the display fits, false if not.
894 static bool dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
896 if (dce_v6_0_average_bandwidth(wm) <=
897 (dce_v6_0_dram_bandwidth_for_display(wm) / wm->num_heads))
904 * dce_v6_0_average_bandwidth_vs_available_bandwidth - check
905 * average and available bandwidth
907 * @wm: watermark calculation data
909 * Check if the display average bandwidth fits in the display
910 * available bandwidth (CIK).
911 * Used for display watermark bandwidth calculations
912 * Returns true if the display fits, false if not.
914 static bool dce_v6_0_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
916 if (dce_v6_0_average_bandwidth(wm) <=
917 (dce_v6_0_available_bandwidth(wm) / wm->num_heads))
924 * dce_v6_0_check_latency_hiding - check latency hiding
926 * @wm: watermark calculation data
928 * Check latency hiding (CIK).
929 * Used for display watermark bandwidth calculations
930 * Returns true if the display fits, false if not.
932 static bool dce_v6_0_check_latency_hiding(struct dce6_wm_params *wm)
934 u32 lb_partitions = wm->lb_size / wm->src_width;
935 u32 line_time = wm->active_time + wm->blank_time;
936 u32 latency_tolerant_lines;
940 a.full = dfixed_const(1);
941 if (wm->vsc.full > a.full)
942 latency_tolerant_lines = 1;
944 if (lb_partitions <= (wm->vtaps + 1))
945 latency_tolerant_lines = 1;
947 latency_tolerant_lines = 2;
950 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
952 if (dce_v6_0_latency_watermark(wm) <= latency_hiding)
959 * dce_v6_0_program_watermarks - program display watermarks
961 * @adev: amdgpu_device pointer
962 * @amdgpu_crtc: the selected display controller
963 * @lb_size: line buffer size
964 * @num_heads: number of display controllers in use
966 * Calculate and program the display watermarks for the
967 * selected display controller (CIK).
969 static void dce_v6_0_program_watermarks(struct amdgpu_device *adev,
970 struct amdgpu_crtc *amdgpu_crtc,
971 u32 lb_size, u32 num_heads)
973 struct drm_display_mode *mode = &amdgpu_crtc->base.mode;
974 struct dce6_wm_params wm_low, wm_high;
978 u32 latency_watermark_a = 0, latency_watermark_b = 0;
979 u32 priority_a_mark = 0, priority_b_mark = 0;
980 u32 priority_a_cnt = PRIORITY_OFF;
981 u32 priority_b_cnt = PRIORITY_OFF;
982 u32 tmp, arb_control3, lb_vblank_lead_lines = 0;
985 if (amdgpu_crtc->base.enabled && num_heads && mode) {
986 active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
988 line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
990 line_time = min(line_time, (u32)65535);
994 dram_channels = si_get_number_of_dram_channels(adev);
996 /* watermark for high clocks */
997 if (adev->pm.dpm_enabled) {
999 amdgpu_dpm_get_mclk(adev, false) * 10;
1001 amdgpu_dpm_get_sclk(adev, false) * 10;
1003 wm_high.yclk = adev->pm.current_mclk * 10;
1004 wm_high.sclk = adev->pm.current_sclk * 10;
1007 wm_high.disp_clk = mode->clock;
1008 wm_high.src_width = mode->crtc_hdisplay;
1009 wm_high.active_time = active_time;
1010 wm_high.blank_time = line_time - wm_high.active_time;
1011 wm_high.interlaced = false;
1012 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1013 wm_high.interlaced = true;
1014 wm_high.vsc = amdgpu_crtc->vsc;
1016 if (amdgpu_crtc->rmx_type != RMX_OFF)
1018 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
1019 wm_high.lb_size = lb_size;
1020 wm_high.dram_channels = dram_channels;
1021 wm_high.num_heads = num_heads;
1023 if (adev->pm.dpm_enabled) {
1024 /* watermark for low clocks */
1026 amdgpu_dpm_get_mclk(adev, true) * 10;
1028 amdgpu_dpm_get_sclk(adev, true) * 10;
1030 wm_low.yclk = adev->pm.current_mclk * 10;
1031 wm_low.sclk = adev->pm.current_sclk * 10;
1034 wm_low.disp_clk = mode->clock;
1035 wm_low.src_width = mode->crtc_hdisplay;
1036 wm_low.active_time = active_time;
1037 wm_low.blank_time = line_time - wm_low.active_time;
1038 wm_low.interlaced = false;
1039 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1040 wm_low.interlaced = true;
1041 wm_low.vsc = amdgpu_crtc->vsc;
1043 if (amdgpu_crtc->rmx_type != RMX_OFF)
1045 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
1046 wm_low.lb_size = lb_size;
1047 wm_low.dram_channels = dram_channels;
1048 wm_low.num_heads = num_heads;
1050 /* set for high clocks */
1051 latency_watermark_a = min(dce_v6_0_latency_watermark(&wm_high), (u32)65535);
1052 /* set for low clocks */
1053 latency_watermark_b = min(dce_v6_0_latency_watermark(&wm_low), (u32)65535);
1055 /* possibly force display priority to high */
1056 /* should really do this at mode validation time... */
1057 if (!dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
1058 !dce_v6_0_average_bandwidth_vs_available_bandwidth(&wm_high) ||
1059 !dce_v6_0_check_latency_hiding(&wm_high) ||
1060 (adev->mode_info.disp_priority == 2)) {
1061 DRM_DEBUG_KMS("force priority to high\n");
1062 priority_a_cnt |= PRIORITY_ALWAYS_ON;
1063 priority_b_cnt |= PRIORITY_ALWAYS_ON;
1065 if (!dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
1066 !dce_v6_0_average_bandwidth_vs_available_bandwidth(&wm_low) ||
1067 !dce_v6_0_check_latency_hiding(&wm_low) ||
1068 (adev->mode_info.disp_priority == 2)) {
1069 DRM_DEBUG_KMS("force priority to high\n");
1070 priority_a_cnt |= PRIORITY_ALWAYS_ON;
1071 priority_b_cnt |= PRIORITY_ALWAYS_ON;
1074 a.full = dfixed_const(1000);
1075 b.full = dfixed_const(mode->clock);
1076 b.full = dfixed_div(b, a);
1077 c.full = dfixed_const(latency_watermark_a);
1078 c.full = dfixed_mul(c, b);
1079 c.full = dfixed_mul(c, amdgpu_crtc->hsc);
1080 c.full = dfixed_div(c, a);
1081 a.full = dfixed_const(16);
1082 c.full = dfixed_div(c, a);
1083 priority_a_mark = dfixed_trunc(c);
1084 priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
1086 a.full = dfixed_const(1000);
1087 b.full = dfixed_const(mode->clock);
1088 b.full = dfixed_div(b, a);
1089 c.full = dfixed_const(latency_watermark_b);
1090 c.full = dfixed_mul(c, b);
1091 c.full = dfixed_mul(c, amdgpu_crtc->hsc);
1092 c.full = dfixed_div(c, a);
1093 a.full = dfixed_const(16);
1094 c.full = dfixed_div(c, a);
1095 priority_b_mark = dfixed_trunc(c);
1096 priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
1098 lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
1102 arb_control3 = RREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset);
1104 tmp &= ~LATENCY_WATERMARK_MASK(3);
1105 tmp |= LATENCY_WATERMARK_MASK(1);
1106 WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, tmp);
1107 WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
1108 ((latency_watermark_a << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
1109 (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
1111 tmp = RREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset);
1112 tmp &= ~LATENCY_WATERMARK_MASK(3);
1113 tmp |= LATENCY_WATERMARK_MASK(2);
1114 WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, tmp);
1115 WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
1116 ((latency_watermark_b << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
1117 (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
1118 /* restore original selection */
1119 WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, arb_control3);
1121 /* write the priority marks */
1122 WREG32(mmPRIORITY_A_CNT + amdgpu_crtc->crtc_offset, priority_a_cnt);
1123 WREG32(mmPRIORITY_B_CNT + amdgpu_crtc->crtc_offset, priority_b_cnt);
1125 /* save values for DPM */
1126 amdgpu_crtc->line_time = line_time;
1127 amdgpu_crtc->wm_high = latency_watermark_a;
1129 /* Save number of lines the linebuffer leads before the scanout */
1130 amdgpu_crtc->lb_vblank_lead_lines = lb_vblank_lead_lines;
1133 /* watermark setup */
1134 static u32 dce_v6_0_line_buffer_adjust(struct amdgpu_device *adev,
1135 struct amdgpu_crtc *amdgpu_crtc,
1136 struct drm_display_mode *mode,
1137 struct drm_display_mode *other_mode)
1139 u32 tmp, buffer_alloc, i;
1140 u32 pipe_offset = amdgpu_crtc->crtc_id * 0x8;
1143 * There are 3 line buffers, each one shared by 2 display controllers.
1144 * mmDC_LB_MEMORY_SPLIT controls how that line buffer is shared between
1145 * the display controllers. The paritioning is done via one of four
1146 * preset allocations specified in bits 21:20:
1148 * 2 - whole lb, other crtc must be disabled
1150 /* this can get tricky if we have two large displays on a paired group
1151 * of crtcs. Ideally for multiple large displays we'd assign them to
1152 * non-linked crtcs for maximum line buffer allocation.
1154 if (amdgpu_crtc->base.enabled && mode) {
1159 tmp = 2; /* whole */
1167 WREG32(mmDC_LB_MEMORY_SPLIT + amdgpu_crtc->crtc_offset,
1168 DC_LB_MEMORY_CONFIG(tmp));
1170 WREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
1171 (buffer_alloc << PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATED__SHIFT));
1172 for (i = 0; i < adev->usec_timeout; i++) {
1173 if (RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
1174 PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATION_COMPLETED_MASK)
1179 if (amdgpu_crtc->base.enabled && mode) {
1189 /* controller not enabled, so no lb used */
1196 * dce_v6_0_bandwidth_update - program display watermarks
1198 * @adev: amdgpu_device pointer
1200 * Calculate and program the display watermarks and line
1201 * buffer allocation (CIK).
1203 static void dce_v6_0_bandwidth_update(struct amdgpu_device *adev)
1205 struct drm_display_mode *mode0 = NULL;
1206 struct drm_display_mode *mode1 = NULL;
1207 u32 num_heads = 0, lb_size;
1210 if (!adev->mode_info.mode_config_initialized)
1213 amdgpu_update_display_priority(adev);
1215 for (i = 0; i < adev->mode_info.num_crtc; i++) {
1216 if (adev->mode_info.crtcs[i]->base.enabled)
1219 for (i = 0; i < adev->mode_info.num_crtc; i += 2) {
1220 mode0 = &adev->mode_info.crtcs[i]->base.mode;
1221 mode1 = &adev->mode_info.crtcs[i+1]->base.mode;
1222 lb_size = dce_v6_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i], mode0, mode1);
1223 dce_v6_0_program_watermarks(adev, adev->mode_info.crtcs[i], lb_size, num_heads);
1224 lb_size = dce_v6_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i+1], mode1, mode0);
1225 dce_v6_0_program_watermarks(adev, adev->mode_info.crtcs[i+1], lb_size, num_heads);
1229 static void dce_v6_0_audio_get_connected_pins(struct amdgpu_device *adev)
1234 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1235 offset = adev->mode_info.audio.pin[i].offset;
1236 tmp = RREG32_AUDIO_ENDPT(offset,
1237 AZ_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT);
1238 if (((tmp & PORT_CONNECTIVITY_MASK) >> PORT_CONNECTIVITY_SHIFT) == 1)
1239 adev->mode_info.audio.pin[i].connected = false;
1241 adev->mode_info.audio.pin[i].connected = true;
1246 static struct amdgpu_audio_pin *dce_v6_0_audio_get_pin(struct amdgpu_device *adev)
1250 dce_v6_0_audio_get_connected_pins(adev);
1252 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1253 if (adev->mode_info.audio.pin[i].connected)
1254 return &adev->mode_info.audio.pin[i];
1256 DRM_ERROR("No connected audio pins found!\n");
1260 static void dce_v6_0_afmt_audio_select_pin(struct drm_encoder *encoder)
1262 struct amdgpu_device *adev = encoder->dev->dev_private;
1263 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1264 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1267 if (!dig || !dig->afmt || !dig->afmt->pin)
1270 offset = dig->afmt->offset;
1272 WREG32(AFMT_AUDIO_SRC_CONTROL + offset,
1273 AFMT_AUDIO_SRC_SELECT(dig->afmt->pin->id));
1277 static void dce_v6_0_audio_write_latency_fields(struct drm_encoder *encoder,
1278 struct drm_display_mode *mode)
1280 DRM_INFO("xxxx: dce_v6_0_audio_write_latency_fields---no imp!!!!!\n");
1283 static void dce_v6_0_audio_write_speaker_allocation(struct drm_encoder *encoder)
1285 DRM_INFO("xxxx: dce_v6_0_audio_write_speaker_allocation---no imp!!!!!\n");
1288 static void dce_v6_0_audio_write_sad_regs(struct drm_encoder *encoder)
1290 DRM_INFO("xxxx: dce_v6_0_audio_write_sad_regs---no imp!!!!!\n");
1294 static void dce_v6_0_audio_enable(struct amdgpu_device *adev,
1295 struct amdgpu_audio_pin *pin,
1298 DRM_INFO("xxxx: dce_v6_0_audio_enable---no imp!!!!!\n");
1301 static const u32 pin_offsets[7] =
1312 static int dce_v6_0_audio_init(struct amdgpu_device *adev)
1317 static void dce_v6_0_audio_fini(struct amdgpu_device *adev)
1323 static void dce_v6_0_afmt_update_ACR(struct drm_encoder *encoder, uint32_t clock)
1325 DRM_INFO("xxxx: dce_v6_0_afmt_update_ACR---no imp!!!!!\n");
1329 * build a HDMI Video Info Frame
1332 static void dce_v6_0_afmt_update_avi_infoframe(struct drm_encoder *encoder,
1333 void *buffer, size_t size)
1335 DRM_INFO("xxxx: dce_v6_0_afmt_update_avi_infoframe---no imp!!!!!\n");
1338 static void dce_v6_0_audio_set_dto(struct drm_encoder *encoder, u32 clock)
1340 DRM_INFO("xxxx: dce_v6_0_audio_set_dto---no imp!!!!!\n");
1344 * update the info frames with the data from the current display mode
1346 static void dce_v6_0_afmt_setmode(struct drm_encoder *encoder,
1347 struct drm_display_mode *mode)
1349 DRM_INFO("xxxx: dce_v6_0_afmt_setmode ----no impl !!!!!!!!\n");
1352 static void dce_v6_0_afmt_enable(struct drm_encoder *encoder, bool enable)
1354 struct drm_device *dev = encoder->dev;
1355 struct amdgpu_device *adev = dev->dev_private;
1356 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1357 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1359 if (!dig || !dig->afmt)
1362 /* Silent, r600_hdmi_enable will raise WARN for us */
1363 if (enable && dig->afmt->enabled)
1365 if (!enable && !dig->afmt->enabled)
1368 if (!enable && dig->afmt->pin) {
1369 dce_v6_0_audio_enable(adev, dig->afmt->pin, false);
1370 dig->afmt->pin = NULL;
1373 dig->afmt->enabled = enable;
1375 DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
1376 enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id);
1379 static int dce_v6_0_afmt_init(struct amdgpu_device *adev)
1383 for (i = 0; i < adev->mode_info.num_dig; i++)
1384 adev->mode_info.afmt[i] = NULL;
1386 /* DCE6 has audio blocks tied to DIG encoders */
1387 for (i = 0; i < adev->mode_info.num_dig; i++) {
1388 adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL);
1389 if (adev->mode_info.afmt[i]) {
1390 adev->mode_info.afmt[i]->offset = dig_offsets[i];
1391 adev->mode_info.afmt[i]->id = i;
1393 for (j = 0; j < i; j++) {
1394 kfree(adev->mode_info.afmt[j]);
1395 adev->mode_info.afmt[j] = NULL;
1397 DRM_ERROR("Out of memory allocating afmt table\n");
1404 static void dce_v6_0_afmt_fini(struct amdgpu_device *adev)
1408 for (i = 0; i < adev->mode_info.num_dig; i++) {
1409 kfree(adev->mode_info.afmt[i]);
1410 adev->mode_info.afmt[i] = NULL;
1414 static const u32 vga_control_regs[6] =
1424 static void dce_v6_0_vga_enable(struct drm_crtc *crtc, bool enable)
1426 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1427 struct drm_device *dev = crtc->dev;
1428 struct amdgpu_device *adev = dev->dev_private;
1431 vga_control = RREG32(vga_control_regs[amdgpu_crtc->crtc_id]) & ~1;
1432 WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control | (enable ? 1 : 0));
1435 static void dce_v6_0_grph_enable(struct drm_crtc *crtc, bool enable)
1437 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1438 struct drm_device *dev = crtc->dev;
1439 struct amdgpu_device *adev = dev->dev_private;
1441 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, enable ? 1 : 0);
1444 static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
1445 struct drm_framebuffer *fb,
1446 int x, int y, int atomic)
1448 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1449 struct drm_device *dev = crtc->dev;
1450 struct amdgpu_device *adev = dev->dev_private;
1451 struct amdgpu_framebuffer *amdgpu_fb;
1452 struct drm_framebuffer *target_fb;
1453 struct drm_gem_object *obj;
1454 struct amdgpu_bo *abo;
1455 uint64_t fb_location, tiling_flags;
1456 uint32_t fb_format, fb_pitch_pixels, pipe_config;
1457 u32 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_NONE);
1458 u32 viewport_w, viewport_h;
1460 bool bypass_lut = false;
1461 struct drm_format_name_buf format_name;
1464 if (!atomic && !crtc->primary->fb) {
1465 DRM_DEBUG_KMS("No FB bound\n");
1470 amdgpu_fb = to_amdgpu_framebuffer(fb);
1473 amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
1474 target_fb = crtc->primary->fb;
1477 /* If atomic, assume fb object is pinned & idle & fenced and
1478 * just update base pointers
1480 obj = amdgpu_fb->obj;
1481 abo = gem_to_amdgpu_bo(obj);
1482 r = amdgpu_bo_reserve(abo, false);
1483 if (unlikely(r != 0))
1487 fb_location = amdgpu_bo_gpu_offset(abo);
1489 r = amdgpu_bo_pin(abo, AMDGPU_GEM_DOMAIN_VRAM, &fb_location);
1490 if (unlikely(r != 0)) {
1491 amdgpu_bo_unreserve(abo);
1496 amdgpu_bo_get_tiling_flags(abo, &tiling_flags);
1497 amdgpu_bo_unreserve(abo);
1499 switch (target_fb->format->format) {
1501 fb_format = (GRPH_DEPTH(GRPH_DEPTH_8BPP) |
1502 GRPH_FORMAT(GRPH_FORMAT_INDEXED));
1504 case DRM_FORMAT_XRGB4444:
1505 case DRM_FORMAT_ARGB4444:
1506 fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
1507 GRPH_FORMAT(GRPH_FORMAT_ARGB4444));
1509 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
1512 case DRM_FORMAT_XRGB1555:
1513 case DRM_FORMAT_ARGB1555:
1514 fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
1515 GRPH_FORMAT(GRPH_FORMAT_ARGB1555));
1517 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
1520 case DRM_FORMAT_BGRX5551:
1521 case DRM_FORMAT_BGRA5551:
1522 fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
1523 GRPH_FORMAT(GRPH_FORMAT_BGRA5551));
1525 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
1528 case DRM_FORMAT_RGB565:
1529 fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
1530 GRPH_FORMAT(GRPH_FORMAT_ARGB565));
1532 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
1535 case DRM_FORMAT_XRGB8888:
1536 case DRM_FORMAT_ARGB8888:
1537 fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
1538 GRPH_FORMAT(GRPH_FORMAT_ARGB8888));
1540 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
1543 case DRM_FORMAT_XRGB2101010:
1544 case DRM_FORMAT_ARGB2101010:
1545 fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
1546 GRPH_FORMAT(GRPH_FORMAT_ARGB2101010));
1548 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
1550 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
1553 case DRM_FORMAT_BGRX1010102:
1554 case DRM_FORMAT_BGRA1010102:
1555 fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
1556 GRPH_FORMAT(GRPH_FORMAT_BGRA1010102));
1558 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
1560 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
1564 DRM_ERROR("Unsupported screen format %s\n",
1565 drm_get_format_name(target_fb->format->format, &format_name));
1569 if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
1570 unsigned bankw, bankh, mtaspect, tile_split, num_banks;
1572 bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
1573 bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
1574 mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
1575 tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
1576 num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
1578 fb_format |= GRPH_NUM_BANKS(num_banks);
1579 fb_format |= GRPH_ARRAY_MODE(GRPH_ARRAY_2D_TILED_THIN1);
1580 fb_format |= GRPH_TILE_SPLIT(tile_split);
1581 fb_format |= GRPH_BANK_WIDTH(bankw);
1582 fb_format |= GRPH_BANK_HEIGHT(bankh);
1583 fb_format |= GRPH_MACRO_TILE_ASPECT(mtaspect);
1584 } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
1585 fb_format |= GRPH_ARRAY_MODE(GRPH_ARRAY_1D_TILED_THIN1);
1588 pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
1589 fb_format |= GRPH_PIPE_CONFIG(pipe_config);
1591 dce_v6_0_vga_enable(crtc, false);
1593 /* Make sure surface address is updated at vertical blank rather than
1596 WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, 0);
1598 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
1599 upper_32_bits(fb_location));
1600 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
1601 upper_32_bits(fb_location));
1602 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
1603 (u32)fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
1604 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
1605 (u32) fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
1606 WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format);
1607 WREG32(mmGRPH_SWAP_CNTL + amdgpu_crtc->crtc_offset, fb_swap);
1610 * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
1611 * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
1612 * retain the full precision throughout the pipeline.
1614 WREG32_P(mmGRPH_LUT_10BIT_BYPASS + amdgpu_crtc->crtc_offset,
1615 (bypass_lut ? GRPH_LUT_10BIT_BYPASS__GRPH_LUT_10BIT_BYPASS_EN_MASK : 0),
1616 ~GRPH_LUT_10BIT_BYPASS__GRPH_LUT_10BIT_BYPASS_EN_MASK);
1619 DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
1621 WREG32(mmGRPH_SURFACE_OFFSET_X + amdgpu_crtc->crtc_offset, 0);
1622 WREG32(mmGRPH_SURFACE_OFFSET_Y + amdgpu_crtc->crtc_offset, 0);
1623 WREG32(mmGRPH_X_START + amdgpu_crtc->crtc_offset, 0);
1624 WREG32(mmGRPH_Y_START + amdgpu_crtc->crtc_offset, 0);
1625 WREG32(mmGRPH_X_END + amdgpu_crtc->crtc_offset, target_fb->width);
1626 WREG32(mmGRPH_Y_END + amdgpu_crtc->crtc_offset, target_fb->height);
1628 fb_pitch_pixels = target_fb->pitches[0] / target_fb->format->cpp[0];
1629 WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, fb_pitch_pixels);
1631 dce_v6_0_grph_enable(crtc, true);
1633 WREG32(mmDESKTOP_HEIGHT + amdgpu_crtc->crtc_offset,
1637 WREG32(mmVIEWPORT_START + amdgpu_crtc->crtc_offset,
1639 viewport_w = crtc->mode.hdisplay;
1640 viewport_h = (crtc->mode.vdisplay + 1) & ~1;
1642 WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
1643 (viewport_w << 16) | viewport_h);
1645 /* set pageflip to happen anywhere in vblank interval */
1646 WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
1648 if (!atomic && fb && fb != crtc->primary->fb) {
1649 amdgpu_fb = to_amdgpu_framebuffer(fb);
1650 abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
1651 r = amdgpu_bo_reserve(abo, true);
1652 if (unlikely(r != 0))
1654 amdgpu_bo_unpin(abo);
1655 amdgpu_bo_unreserve(abo);
1658 /* Bytes per pixel may have changed */
1659 dce_v6_0_bandwidth_update(adev);
1665 static void dce_v6_0_set_interleave(struct drm_crtc *crtc,
1666 struct drm_display_mode *mode)
1668 struct drm_device *dev = crtc->dev;
1669 struct amdgpu_device *adev = dev->dev_private;
1670 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1672 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1673 WREG32(mmDATA_FORMAT + amdgpu_crtc->crtc_offset,
1676 WREG32(mmDATA_FORMAT + amdgpu_crtc->crtc_offset, 0);
1679 static void dce_v6_0_crtc_load_lut(struct drm_crtc *crtc)
1682 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1683 struct drm_device *dev = crtc->dev;
1684 struct amdgpu_device *adev = dev->dev_private;
1687 DRM_DEBUG_KMS("%d\n", amdgpu_crtc->crtc_id);
1689 WREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
1690 ((0 << INPUT_CSC_CONTROL__INPUT_CSC_GRPH_MODE__SHIFT) |
1691 (0 << INPUT_CSC_CONTROL__INPUT_CSC_OVL_MODE__SHIFT)));
1692 WREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset,
1693 PRESCALE_GRPH_CONTROL__GRPH_PRESCALE_BYPASS_MASK);
1694 WREG32(mmPRESCALE_OVL_CONTROL + amdgpu_crtc->crtc_offset,
1695 PRESCALE_OVL_CONTROL__OVL_PRESCALE_BYPASS_MASK);
1696 WREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset,
1697 ((0 << INPUT_GAMMA_CONTROL__GRPH_INPUT_GAMMA_MODE__SHIFT) |
1698 (0 << INPUT_GAMMA_CONTROL__OVL_INPUT_GAMMA_MODE__SHIFT)));
1700 WREG32(mmDC_LUT_CONTROL + amdgpu_crtc->crtc_offset, 0);
1702 WREG32(mmDC_LUT_BLACK_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0);
1703 WREG32(mmDC_LUT_BLACK_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0);
1704 WREG32(mmDC_LUT_BLACK_OFFSET_RED + amdgpu_crtc->crtc_offset, 0);
1706 WREG32(mmDC_LUT_WHITE_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0xffff);
1707 WREG32(mmDC_LUT_WHITE_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0xffff);
1708 WREG32(mmDC_LUT_WHITE_OFFSET_RED + amdgpu_crtc->crtc_offset, 0xffff);
1710 WREG32(mmDC_LUT_RW_MODE + amdgpu_crtc->crtc_offset, 0);
1711 WREG32(mmDC_LUT_WRITE_EN_MASK + amdgpu_crtc->crtc_offset, 0x00000007);
1713 WREG32(mmDC_LUT_RW_INDEX + amdgpu_crtc->crtc_offset, 0);
1714 for (i = 0; i < 256; i++) {
1715 WREG32(mmDC_LUT_30_COLOR + amdgpu_crtc->crtc_offset,
1716 (amdgpu_crtc->lut_r[i] << 20) |
1717 (amdgpu_crtc->lut_g[i] << 10) |
1718 (amdgpu_crtc->lut_b[i] << 0));
1721 WREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
1722 ((0 << DEGAMMA_CONTROL__GRPH_DEGAMMA_MODE__SHIFT) |
1723 (0 << DEGAMMA_CONTROL__OVL_DEGAMMA_MODE__SHIFT) |
1724 ICON_DEGAMMA_MODE(0) |
1725 (0 << DEGAMMA_CONTROL__CURSOR_DEGAMMA_MODE__SHIFT)));
1726 WREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset,
1727 ((0 << GAMUT_REMAP_CONTROL__GRPH_GAMUT_REMAP_MODE__SHIFT) |
1728 (0 << GAMUT_REMAP_CONTROL__OVL_GAMUT_REMAP_MODE__SHIFT)));
1729 WREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
1730 ((0 << REGAMMA_CONTROL__GRPH_REGAMMA_MODE__SHIFT) |
1731 (0 << REGAMMA_CONTROL__OVL_REGAMMA_MODE__SHIFT)));
1732 WREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
1733 ((0 << OUTPUT_CSC_CONTROL__OUTPUT_CSC_GRPH_MODE__SHIFT) |
1734 (0 << OUTPUT_CSC_CONTROL__OUTPUT_CSC_OVL_MODE__SHIFT)));
1735 /* XXX match this to the depth of the crtc fmt block, move to modeset? */
1736 WREG32(0x1a50 + amdgpu_crtc->crtc_offset, 0);
1741 static int dce_v6_0_pick_dig_encoder(struct drm_encoder *encoder)
1743 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1744 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1746 switch (amdgpu_encoder->encoder_id) {
1747 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1748 return dig->linkb ? 1 : 0;
1749 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1750 return dig->linkb ? 3 : 2;
1751 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1752 return dig->linkb ? 5 : 4;
1753 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
1756 DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id);
1762 * dce_v6_0_pick_pll - Allocate a PPLL for use by the crtc.
1766 * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
1767 * a single PPLL can be used for all DP crtcs/encoders. For non-DP
1768 * monitors a dedicated PPLL must be used. If a particular board has
1769 * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
1770 * as there is no need to program the PLL itself. If we are not able to
1771 * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
1772 * avoid messing up an existing monitor.
1776 static u32 dce_v6_0_pick_pll(struct drm_crtc *crtc)
1778 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1779 struct drm_device *dev = crtc->dev;
1780 struct amdgpu_device *adev = dev->dev_private;
1784 if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) {
1785 if (adev->clock.dp_extclk)
1786 /* skip PPLL programming if using ext clock */
1787 return ATOM_PPLL_INVALID;
1791 /* use the same PPLL for all monitors with the same clock */
1792 pll = amdgpu_pll_get_shared_nondp_ppll(crtc);
1793 if (pll != ATOM_PPLL_INVALID)
1797 /* PPLL1, and PPLL2 */
1798 pll_in_use = amdgpu_pll_get_use_mask(crtc);
1799 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1801 if (!(pll_in_use & (1 << ATOM_PPLL1)))
1803 DRM_ERROR("unable to allocate a PPLL\n");
1804 return ATOM_PPLL_INVALID;
1807 static void dce_v6_0_lock_cursor(struct drm_crtc *crtc, bool lock)
1809 struct amdgpu_device *adev = crtc->dev->dev_private;
1810 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1813 cur_lock = RREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset);
1815 cur_lock |= CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
1817 cur_lock &= ~CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
1818 WREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset, cur_lock);
1821 static void dce_v6_0_hide_cursor(struct drm_crtc *crtc)
1823 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1824 struct amdgpu_device *adev = crtc->dev->dev_private;
1826 WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
1827 (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
1828 (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
1833 static void dce_v6_0_show_cursor(struct drm_crtc *crtc)
1835 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1836 struct amdgpu_device *adev = crtc->dev->dev_private;
1838 WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
1839 upper_32_bits(amdgpu_crtc->cursor_addr));
1840 WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
1841 lower_32_bits(amdgpu_crtc->cursor_addr));
1843 WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
1844 CUR_CONTROL__CURSOR_EN_MASK |
1845 (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
1846 (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
1850 static int dce_v6_0_cursor_move_locked(struct drm_crtc *crtc,
1853 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1854 struct amdgpu_device *adev = crtc->dev->dev_private;
1855 int xorigin = 0, yorigin = 0;
1857 int w = amdgpu_crtc->cursor_width;
1859 amdgpu_crtc->cursor_x = x;
1860 amdgpu_crtc->cursor_y = y;
1862 /* avivo cursor are offset into the total surface */
1865 DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
1868 xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
1872 yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
1876 WREG32(mmCUR_POSITION + amdgpu_crtc->crtc_offset, (x << 16) | y);
1877 WREG32(mmCUR_HOT_SPOT + amdgpu_crtc->crtc_offset, (xorigin << 16) | yorigin);
1878 WREG32(mmCUR_SIZE + amdgpu_crtc->crtc_offset,
1879 ((w - 1) << 16) | (amdgpu_crtc->cursor_height - 1));
1884 static int dce_v6_0_crtc_cursor_move(struct drm_crtc *crtc,
1889 dce_v6_0_lock_cursor(crtc, true);
1890 ret = dce_v6_0_cursor_move_locked(crtc, x, y);
1891 dce_v6_0_lock_cursor(crtc, false);
1896 static int dce_v6_0_crtc_cursor_set2(struct drm_crtc *crtc,
1897 struct drm_file *file_priv,
1904 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1905 struct drm_gem_object *obj;
1906 struct amdgpu_bo *aobj;
1910 /* turn off cursor */
1911 dce_v6_0_hide_cursor(crtc);
1916 if ((width > amdgpu_crtc->max_cursor_width) ||
1917 (height > amdgpu_crtc->max_cursor_height)) {
1918 DRM_ERROR("bad cursor width or height %d x %d\n", width, height);
1922 obj = drm_gem_object_lookup(file_priv, handle);
1924 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, amdgpu_crtc->crtc_id);
1928 aobj = gem_to_amdgpu_bo(obj);
1929 ret = amdgpu_bo_reserve(aobj, false);
1931 drm_gem_object_unreference_unlocked(obj);
1935 ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM, &amdgpu_crtc->cursor_addr);
1936 amdgpu_bo_unreserve(aobj);
1938 DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret);
1939 drm_gem_object_unreference_unlocked(obj);
1943 dce_v6_0_lock_cursor(crtc, true);
1945 if (width != amdgpu_crtc->cursor_width ||
1946 height != amdgpu_crtc->cursor_height ||
1947 hot_x != amdgpu_crtc->cursor_hot_x ||
1948 hot_y != amdgpu_crtc->cursor_hot_y) {
1951 x = amdgpu_crtc->cursor_x + amdgpu_crtc->cursor_hot_x - hot_x;
1952 y = amdgpu_crtc->cursor_y + amdgpu_crtc->cursor_hot_y - hot_y;
1954 dce_v6_0_cursor_move_locked(crtc, x, y);
1956 amdgpu_crtc->cursor_width = width;
1957 amdgpu_crtc->cursor_height = height;
1958 amdgpu_crtc->cursor_hot_x = hot_x;
1959 amdgpu_crtc->cursor_hot_y = hot_y;
1962 dce_v6_0_show_cursor(crtc);
1963 dce_v6_0_lock_cursor(crtc, false);
1966 if (amdgpu_crtc->cursor_bo) {
1967 struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
1968 ret = amdgpu_bo_reserve(aobj, true);
1969 if (likely(ret == 0)) {
1970 amdgpu_bo_unpin(aobj);
1971 amdgpu_bo_unreserve(aobj);
1973 drm_gem_object_unreference_unlocked(amdgpu_crtc->cursor_bo);
1976 amdgpu_crtc->cursor_bo = obj;
1980 static void dce_v6_0_cursor_reset(struct drm_crtc *crtc)
1982 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1984 if (amdgpu_crtc->cursor_bo) {
1985 dce_v6_0_lock_cursor(crtc, true);
1987 dce_v6_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x,
1988 amdgpu_crtc->cursor_y);
1990 dce_v6_0_show_cursor(crtc);
1991 dce_v6_0_lock_cursor(crtc, false);
1995 static int dce_v6_0_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
1996 u16 *blue, uint32_t size,
1997 struct drm_modeset_acquire_ctx *ctx)
1999 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2002 /* userspace palettes are always correct as is */
2003 for (i = 0; i < size; i++) {
2004 amdgpu_crtc->lut_r[i] = red[i] >> 6;
2005 amdgpu_crtc->lut_g[i] = green[i] >> 6;
2006 amdgpu_crtc->lut_b[i] = blue[i] >> 6;
2008 dce_v6_0_crtc_load_lut(crtc);
2013 static void dce_v6_0_crtc_destroy(struct drm_crtc *crtc)
2015 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2017 drm_crtc_cleanup(crtc);
2021 static const struct drm_crtc_funcs dce_v6_0_crtc_funcs = {
2022 .cursor_set2 = dce_v6_0_crtc_cursor_set2,
2023 .cursor_move = dce_v6_0_crtc_cursor_move,
2024 .gamma_set = dce_v6_0_crtc_gamma_set,
2025 .set_config = amdgpu_crtc_set_config,
2026 .destroy = dce_v6_0_crtc_destroy,
2027 .page_flip_target = amdgpu_crtc_page_flip_target,
2030 static void dce_v6_0_crtc_dpms(struct drm_crtc *crtc, int mode)
2032 struct drm_device *dev = crtc->dev;
2033 struct amdgpu_device *adev = dev->dev_private;
2034 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2038 case DRM_MODE_DPMS_ON:
2039 amdgpu_crtc->enabled = true;
2040 amdgpu_atombios_crtc_enable(crtc, ATOM_ENABLE);
2041 amdgpu_atombios_crtc_blank(crtc, ATOM_DISABLE);
2042 /* Make sure VBLANK and PFLIP interrupts are still enabled */
2043 type = amdgpu_crtc_idx_to_irq_type(adev, amdgpu_crtc->crtc_id);
2044 amdgpu_irq_update(adev, &adev->crtc_irq, type);
2045 amdgpu_irq_update(adev, &adev->pageflip_irq, type);
2046 drm_crtc_vblank_on(crtc);
2047 dce_v6_0_crtc_load_lut(crtc);
2049 case DRM_MODE_DPMS_STANDBY:
2050 case DRM_MODE_DPMS_SUSPEND:
2051 case DRM_MODE_DPMS_OFF:
2052 drm_crtc_vblank_off(crtc);
2053 if (amdgpu_crtc->enabled)
2054 amdgpu_atombios_crtc_blank(crtc, ATOM_ENABLE);
2055 amdgpu_atombios_crtc_enable(crtc, ATOM_DISABLE);
2056 amdgpu_crtc->enabled = false;
2059 /* adjust pm to dpms */
2060 amdgpu_pm_compute_clocks(adev);
2063 static void dce_v6_0_crtc_prepare(struct drm_crtc *crtc)
2065 /* disable crtc pair power gating before programming */
2066 amdgpu_atombios_crtc_powergate(crtc, ATOM_DISABLE);
2067 amdgpu_atombios_crtc_lock(crtc, ATOM_ENABLE);
2068 dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
2071 static void dce_v6_0_crtc_commit(struct drm_crtc *crtc)
2073 dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
2074 amdgpu_atombios_crtc_lock(crtc, ATOM_DISABLE);
2077 static void dce_v6_0_crtc_disable(struct drm_crtc *crtc)
2080 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2081 struct drm_device *dev = crtc->dev;
2082 struct amdgpu_device *adev = dev->dev_private;
2083 struct amdgpu_atom_ss ss;
2086 dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
2087 if (crtc->primary->fb) {
2089 struct amdgpu_framebuffer *amdgpu_fb;
2090 struct amdgpu_bo *abo;
2092 amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
2093 abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
2094 r = amdgpu_bo_reserve(abo, true);
2096 DRM_ERROR("failed to reserve abo before unpin\n");
2098 amdgpu_bo_unpin(abo);
2099 amdgpu_bo_unreserve(abo);
2102 /* disable the GRPH */
2103 dce_v6_0_grph_enable(crtc, false);
2105 amdgpu_atombios_crtc_powergate(crtc, ATOM_ENABLE);
2107 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2108 if (adev->mode_info.crtcs[i] &&
2109 adev->mode_info.crtcs[i]->enabled &&
2110 i != amdgpu_crtc->crtc_id &&
2111 amdgpu_crtc->pll_id == adev->mode_info.crtcs[i]->pll_id) {
2112 /* one other crtc is using this pll don't turn
2119 switch (amdgpu_crtc->pll_id) {
2122 /* disable the ppll */
2123 amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
2124 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
2130 amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
2131 amdgpu_crtc->adjusted_clock = 0;
2132 amdgpu_crtc->encoder = NULL;
2133 amdgpu_crtc->connector = NULL;
2136 static int dce_v6_0_crtc_mode_set(struct drm_crtc *crtc,
2137 struct drm_display_mode *mode,
2138 struct drm_display_mode *adjusted_mode,
2139 int x, int y, struct drm_framebuffer *old_fb)
2141 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2143 if (!amdgpu_crtc->adjusted_clock)
2146 amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode);
2147 amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode);
2148 dce_v6_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
2149 amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode);
2150 amdgpu_atombios_crtc_scaler_setup(crtc);
2151 dce_v6_0_cursor_reset(crtc);
2152 /* update the hw version fpr dpm */
2153 amdgpu_crtc->hw_mode = *adjusted_mode;
2158 static bool dce_v6_0_crtc_mode_fixup(struct drm_crtc *crtc,
2159 const struct drm_display_mode *mode,
2160 struct drm_display_mode *adjusted_mode)
2163 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2164 struct drm_device *dev = crtc->dev;
2165 struct drm_encoder *encoder;
2167 /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
2168 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2169 if (encoder->crtc == crtc) {
2170 amdgpu_crtc->encoder = encoder;
2171 amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder);
2175 if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) {
2176 amdgpu_crtc->encoder = NULL;
2177 amdgpu_crtc->connector = NULL;
2180 if (!amdgpu_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
2182 if (amdgpu_atombios_crtc_prepare_pll(crtc, adjusted_mode))
2185 amdgpu_crtc->pll_id = dce_v6_0_pick_pll(crtc);
2186 /* if we can't get a PPLL for a non-DP encoder, fail */
2187 if ((amdgpu_crtc->pll_id == ATOM_PPLL_INVALID) &&
2188 !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder)))
2194 static int dce_v6_0_crtc_set_base(struct drm_crtc *crtc, int x, int y,
2195 struct drm_framebuffer *old_fb)
2197 return dce_v6_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
2200 static int dce_v6_0_crtc_set_base_atomic(struct drm_crtc *crtc,
2201 struct drm_framebuffer *fb,
2202 int x, int y, enum mode_set_atomic state)
2204 return dce_v6_0_crtc_do_set_base(crtc, fb, x, y, 1);
2207 static const struct drm_crtc_helper_funcs dce_v6_0_crtc_helper_funcs = {
2208 .dpms = dce_v6_0_crtc_dpms,
2209 .mode_fixup = dce_v6_0_crtc_mode_fixup,
2210 .mode_set = dce_v6_0_crtc_mode_set,
2211 .mode_set_base = dce_v6_0_crtc_set_base,
2212 .mode_set_base_atomic = dce_v6_0_crtc_set_base_atomic,
2213 .prepare = dce_v6_0_crtc_prepare,
2214 .commit = dce_v6_0_crtc_commit,
2215 .load_lut = dce_v6_0_crtc_load_lut,
2216 .disable = dce_v6_0_crtc_disable,
2219 static int dce_v6_0_crtc_init(struct amdgpu_device *adev, int index)
2221 struct amdgpu_crtc *amdgpu_crtc;
2224 amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) +
2225 (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
2226 if (amdgpu_crtc == NULL)
2229 drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_v6_0_crtc_funcs);
2231 drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256);
2232 amdgpu_crtc->crtc_id = index;
2233 adev->mode_info.crtcs[index] = amdgpu_crtc;
2235 amdgpu_crtc->max_cursor_width = CURSOR_WIDTH;
2236 amdgpu_crtc->max_cursor_height = CURSOR_HEIGHT;
2237 adev->ddev->mode_config.cursor_width = amdgpu_crtc->max_cursor_width;
2238 adev->ddev->mode_config.cursor_height = amdgpu_crtc->max_cursor_height;
2240 for (i = 0; i < 256; i++) {
2241 amdgpu_crtc->lut_r[i] = i << 2;
2242 amdgpu_crtc->lut_g[i] = i << 2;
2243 amdgpu_crtc->lut_b[i] = i << 2;
2246 amdgpu_crtc->crtc_offset = crtc_offsets[amdgpu_crtc->crtc_id];
2248 amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
2249 amdgpu_crtc->adjusted_clock = 0;
2250 amdgpu_crtc->encoder = NULL;
2251 amdgpu_crtc->connector = NULL;
2252 drm_crtc_helper_add(&amdgpu_crtc->base, &dce_v6_0_crtc_helper_funcs);
2257 static int dce_v6_0_early_init(void *handle)
2259 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2261 adev->audio_endpt_rreg = &dce_v6_0_audio_endpt_rreg;
2262 adev->audio_endpt_wreg = &dce_v6_0_audio_endpt_wreg;
2264 dce_v6_0_set_display_funcs(adev);
2265 dce_v6_0_set_irq_funcs(adev);
2267 adev->mode_info.num_crtc = dce_v6_0_get_num_crtc(adev);
2269 switch (adev->asic_type) {
2273 adev->mode_info.num_hpd = 6;
2274 adev->mode_info.num_dig = 6;
2277 adev->mode_info.num_hpd = 2;
2278 adev->mode_info.num_dig = 2;
2287 static int dce_v6_0_sw_init(void *handle)
2291 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2293 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2294 r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, i + 1, &adev->crtc_irq);
2299 for (i = 8; i < 20; i += 2) {
2300 r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, i, &adev->pageflip_irq);
2306 r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 42, &adev->hpd_irq);
2310 adev->mode_info.mode_config_initialized = true;
2312 adev->ddev->mode_config.funcs = &amdgpu_mode_funcs;
2313 adev->ddev->mode_config.async_page_flip = true;
2314 adev->ddev->mode_config.max_width = 16384;
2315 adev->ddev->mode_config.max_height = 16384;
2316 adev->ddev->mode_config.preferred_depth = 24;
2317 adev->ddev->mode_config.prefer_shadow = 1;
2318 adev->ddev->mode_config.fb_base = adev->mc.aper_base;
2320 r = amdgpu_modeset_create_props(adev);
2324 adev->ddev->mode_config.max_width = 16384;
2325 adev->ddev->mode_config.max_height = 16384;
2327 /* allocate crtcs */
2328 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2329 r = dce_v6_0_crtc_init(adev, i);
2334 ret = amdgpu_atombios_get_connector_info_from_object_table(adev);
2336 amdgpu_print_display_setup(adev->ddev);
2341 r = dce_v6_0_afmt_init(adev);
2345 r = dce_v6_0_audio_init(adev);
2349 drm_kms_helper_poll_init(adev->ddev);
2354 static int dce_v6_0_sw_fini(void *handle)
2356 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2358 kfree(adev->mode_info.bios_hardcoded_edid);
2360 drm_kms_helper_poll_fini(adev->ddev);
2362 dce_v6_0_audio_fini(adev);
2363 dce_v6_0_afmt_fini(adev);
2365 drm_mode_config_cleanup(adev->ddev);
2366 adev->mode_info.mode_config_initialized = false;
2371 static int dce_v6_0_hw_init(void *handle)
2374 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2376 /* init dig PHYs, disp eng pll */
2377 amdgpu_atombios_encoder_init_dig(adev);
2378 amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk);
2380 /* initialize hpd */
2381 dce_v6_0_hpd_init(adev);
2383 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
2384 dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
2387 dce_v6_0_pageflip_interrupt_init(adev);
2392 static int dce_v6_0_hw_fini(void *handle)
2395 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2397 dce_v6_0_hpd_fini(adev);
2399 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
2400 dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
2403 dce_v6_0_pageflip_interrupt_fini(adev);
2408 static int dce_v6_0_suspend(void *handle)
2410 return dce_v6_0_hw_fini(handle);
2413 static int dce_v6_0_resume(void *handle)
2415 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2418 ret = dce_v6_0_hw_init(handle);
2420 /* turn on the BL */
2421 if (adev->mode_info.bl_encoder) {
2422 u8 bl_level = amdgpu_display_backlight_get_level(adev,
2423 adev->mode_info.bl_encoder);
2424 amdgpu_display_backlight_set_level(adev, adev->mode_info.bl_encoder,
2431 static bool dce_v6_0_is_idle(void *handle)
2436 static int dce_v6_0_wait_for_idle(void *handle)
2441 static int dce_v6_0_soft_reset(void *handle)
2443 DRM_INFO("xxxx: dce_v6_0_soft_reset --- no impl!!\n");
2447 static void dce_v6_0_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev,
2449 enum amdgpu_interrupt_state state)
2451 u32 reg_block, interrupt_mask;
2453 if (crtc >= adev->mode_info.num_crtc) {
2454 DRM_DEBUG("invalid crtc %d\n", crtc);
2460 reg_block = SI_CRTC0_REGISTER_OFFSET;
2463 reg_block = SI_CRTC1_REGISTER_OFFSET;
2466 reg_block = SI_CRTC2_REGISTER_OFFSET;
2469 reg_block = SI_CRTC3_REGISTER_OFFSET;
2472 reg_block = SI_CRTC4_REGISTER_OFFSET;
2475 reg_block = SI_CRTC5_REGISTER_OFFSET;
2478 DRM_DEBUG("invalid crtc %d\n", crtc);
2483 case AMDGPU_IRQ_STATE_DISABLE:
2484 interrupt_mask = RREG32(mmINT_MASK + reg_block);
2485 interrupt_mask &= ~VBLANK_INT_MASK;
2486 WREG32(mmINT_MASK + reg_block, interrupt_mask);
2488 case AMDGPU_IRQ_STATE_ENABLE:
2489 interrupt_mask = RREG32(mmINT_MASK + reg_block);
2490 interrupt_mask |= VBLANK_INT_MASK;
2491 WREG32(mmINT_MASK + reg_block, interrupt_mask);
2498 static void dce_v6_0_set_crtc_vline_interrupt_state(struct amdgpu_device *adev,
2500 enum amdgpu_interrupt_state state)
2505 static int dce_v6_0_set_hpd_interrupt_state(struct amdgpu_device *adev,
2506 struct amdgpu_irq_src *src,
2508 enum amdgpu_interrupt_state state)
2510 u32 dc_hpd_int_cntl;
2512 if (type >= adev->mode_info.num_hpd) {
2513 DRM_DEBUG("invalid hdp %d\n", type);
2518 case AMDGPU_IRQ_STATE_DISABLE:
2519 dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
2520 dc_hpd_int_cntl &= ~DC_HPDx_INT_EN;
2521 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
2523 case AMDGPU_IRQ_STATE_ENABLE:
2524 dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
2525 dc_hpd_int_cntl |= DC_HPDx_INT_EN;
2526 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
2535 static int dce_v6_0_set_crtc_interrupt_state(struct amdgpu_device *adev,
2536 struct amdgpu_irq_src *src,
2538 enum amdgpu_interrupt_state state)
2541 case AMDGPU_CRTC_IRQ_VBLANK1:
2542 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 0, state);
2544 case AMDGPU_CRTC_IRQ_VBLANK2:
2545 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 1, state);
2547 case AMDGPU_CRTC_IRQ_VBLANK3:
2548 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 2, state);
2550 case AMDGPU_CRTC_IRQ_VBLANK4:
2551 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 3, state);
2553 case AMDGPU_CRTC_IRQ_VBLANK5:
2554 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 4, state);
2556 case AMDGPU_CRTC_IRQ_VBLANK6:
2557 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 5, state);
2559 case AMDGPU_CRTC_IRQ_VLINE1:
2560 dce_v6_0_set_crtc_vline_interrupt_state(adev, 0, state);
2562 case AMDGPU_CRTC_IRQ_VLINE2:
2563 dce_v6_0_set_crtc_vline_interrupt_state(adev, 1, state);
2565 case AMDGPU_CRTC_IRQ_VLINE3:
2566 dce_v6_0_set_crtc_vline_interrupt_state(adev, 2, state);
2568 case AMDGPU_CRTC_IRQ_VLINE4:
2569 dce_v6_0_set_crtc_vline_interrupt_state(adev, 3, state);
2571 case AMDGPU_CRTC_IRQ_VLINE5:
2572 dce_v6_0_set_crtc_vline_interrupt_state(adev, 4, state);
2574 case AMDGPU_CRTC_IRQ_VLINE6:
2575 dce_v6_0_set_crtc_vline_interrupt_state(adev, 5, state);
2583 static int dce_v6_0_crtc_irq(struct amdgpu_device *adev,
2584 struct amdgpu_irq_src *source,
2585 struct amdgpu_iv_entry *entry)
2587 unsigned crtc = entry->src_id - 1;
2588 uint32_t disp_int = RREG32(interrupt_status_offsets[crtc].reg);
2589 unsigned irq_type = amdgpu_crtc_idx_to_irq_type(adev, crtc);
2591 switch (entry->src_data[0]) {
2592 case 0: /* vblank */
2593 if (disp_int & interrupt_status_offsets[crtc].vblank)
2594 WREG32(mmVBLANK_STATUS + crtc_offsets[crtc], VBLANK_ACK);
2596 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
2598 if (amdgpu_irq_enabled(adev, source, irq_type)) {
2599 drm_handle_vblank(adev->ddev, crtc);
2601 DRM_DEBUG("IH: D%d vblank\n", crtc + 1);
2604 if (disp_int & interrupt_status_offsets[crtc].vline)
2605 WREG32(mmVLINE_STATUS + crtc_offsets[crtc], VLINE_ACK);
2607 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
2609 DRM_DEBUG("IH: D%d vline\n", crtc + 1);
2612 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]);
2619 static int dce_v6_0_set_pageflip_interrupt_state(struct amdgpu_device *adev,
2620 struct amdgpu_irq_src *src,
2622 enum amdgpu_interrupt_state state)
2626 if (type >= adev->mode_info.num_crtc) {
2627 DRM_ERROR("invalid pageflip crtc %d\n", type);
2631 reg = RREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type]);
2632 if (state == AMDGPU_IRQ_STATE_DISABLE)
2633 WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
2634 reg & ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
2636 WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
2637 reg | GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
2642 static int dce_v6_0_pageflip_irq(struct amdgpu_device *adev,
2643 struct amdgpu_irq_src *source,
2644 struct amdgpu_iv_entry *entry)
2646 unsigned long flags;
2648 struct amdgpu_crtc *amdgpu_crtc;
2649 struct amdgpu_flip_work *works;
2651 crtc_id = (entry->src_id - 8) >> 1;
2652 amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
2654 if (crtc_id >= adev->mode_info.num_crtc) {
2655 DRM_ERROR("invalid pageflip crtc %d\n", crtc_id);
2659 if (RREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id]) &
2660 GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK)
2661 WREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id],
2662 GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK);
2664 /* IRQ could occur when in initial stage */
2665 if (amdgpu_crtc == NULL)
2668 spin_lock_irqsave(&adev->ddev->event_lock, flags);
2669 works = amdgpu_crtc->pflip_works;
2670 if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){
2671 DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
2672 "AMDGPU_FLIP_SUBMITTED(%d)\n",
2673 amdgpu_crtc->pflip_status,
2674 AMDGPU_FLIP_SUBMITTED);
2675 spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
2679 /* page flip completed. clean up */
2680 amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
2681 amdgpu_crtc->pflip_works = NULL;
2683 /* wakeup usersapce */
2685 drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event);
2687 spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
2689 drm_crtc_vblank_put(&amdgpu_crtc->base);
2690 schedule_work(&works->unpin_work);
2695 static int dce_v6_0_hpd_irq(struct amdgpu_device *adev,
2696 struct amdgpu_irq_src *source,
2697 struct amdgpu_iv_entry *entry)
2699 uint32_t disp_int, mask, tmp;
2702 if (entry->src_data[0] >= adev->mode_info.num_hpd) {
2703 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]);
2707 hpd = entry->src_data[0];
2708 disp_int = RREG32(interrupt_status_offsets[hpd].reg);
2709 mask = interrupt_status_offsets[hpd].hpd;
2711 if (disp_int & mask) {
2712 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
2713 tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_ACK_MASK;
2714 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
2715 schedule_work(&adev->hotplug_work);
2716 DRM_INFO("IH: HPD%d\n", hpd + 1);
2723 static int dce_v6_0_set_clockgating_state(void *handle,
2724 enum amd_clockgating_state state)
2729 static int dce_v6_0_set_powergating_state(void *handle,
2730 enum amd_powergating_state state)
2735 static const struct amd_ip_funcs dce_v6_0_ip_funcs = {
2737 .early_init = dce_v6_0_early_init,
2739 .sw_init = dce_v6_0_sw_init,
2740 .sw_fini = dce_v6_0_sw_fini,
2741 .hw_init = dce_v6_0_hw_init,
2742 .hw_fini = dce_v6_0_hw_fini,
2743 .suspend = dce_v6_0_suspend,
2744 .resume = dce_v6_0_resume,
2745 .is_idle = dce_v6_0_is_idle,
2746 .wait_for_idle = dce_v6_0_wait_for_idle,
2747 .soft_reset = dce_v6_0_soft_reset,
2748 .set_clockgating_state = dce_v6_0_set_clockgating_state,
2749 .set_powergating_state = dce_v6_0_set_powergating_state,
2753 dce_v6_0_encoder_mode_set(struct drm_encoder *encoder,
2754 struct drm_display_mode *mode,
2755 struct drm_display_mode *adjusted_mode)
2758 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2760 amdgpu_encoder->pixel_clock = adjusted_mode->clock;
2762 /* need to call this here rather than in prepare() since we need some crtc info */
2763 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2765 /* set scaler clears this on some chips */
2766 dce_v6_0_set_interleave(encoder->crtc, mode);
2768 if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
2769 dce_v6_0_afmt_enable(encoder, true);
2770 dce_v6_0_afmt_setmode(encoder, adjusted_mode);
2774 static void dce_v6_0_encoder_prepare(struct drm_encoder *encoder)
2777 struct amdgpu_device *adev = encoder->dev->dev_private;
2778 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2779 struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
2781 if ((amdgpu_encoder->active_device &
2782 (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
2783 (amdgpu_encoder_get_dp_bridge_encoder_id(encoder) !=
2784 ENCODER_OBJECT_ID_NONE)) {
2785 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
2787 dig->dig_encoder = dce_v6_0_pick_dig_encoder(encoder);
2788 if (amdgpu_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT)
2789 dig->afmt = adev->mode_info.afmt[dig->dig_encoder];
2793 amdgpu_atombios_scratch_regs_lock(adev, true);
2796 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
2798 /* select the clock/data port if it uses a router */
2799 if (amdgpu_connector->router.cd_valid)
2800 amdgpu_i2c_router_select_cd_port(amdgpu_connector);
2802 /* turn eDP panel on for mode set */
2803 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
2804 amdgpu_atombios_encoder_set_edp_panel_power(connector,
2805 ATOM_TRANSMITTER_ACTION_POWER_ON);
2808 /* this is needed for the pll/ss setup to work correctly in some cases */
2809 amdgpu_atombios_encoder_set_crtc_source(encoder);
2810 /* set up the FMT blocks */
2811 dce_v6_0_program_fmt(encoder);
2814 static void dce_v6_0_encoder_commit(struct drm_encoder *encoder)
2817 struct drm_device *dev = encoder->dev;
2818 struct amdgpu_device *adev = dev->dev_private;
2820 /* need to call this here as we need the crtc set up */
2821 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
2822 amdgpu_atombios_scratch_regs_lock(adev, false);
2825 static void dce_v6_0_encoder_disable(struct drm_encoder *encoder)
2828 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2829 struct amdgpu_encoder_atom_dig *dig;
2831 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2833 if (amdgpu_atombios_encoder_is_digital(encoder)) {
2834 if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
2835 dce_v6_0_afmt_enable(encoder, false);
2836 dig = amdgpu_encoder->enc_priv;
2837 dig->dig_encoder = -1;
2839 amdgpu_encoder->active_device = 0;
2842 /* these are handled by the primary encoders */
2843 static void dce_v6_0_ext_prepare(struct drm_encoder *encoder)
2848 static void dce_v6_0_ext_commit(struct drm_encoder *encoder)
2854 dce_v6_0_ext_mode_set(struct drm_encoder *encoder,
2855 struct drm_display_mode *mode,
2856 struct drm_display_mode *adjusted_mode)
2861 static void dce_v6_0_ext_disable(struct drm_encoder *encoder)
2867 dce_v6_0_ext_dpms(struct drm_encoder *encoder, int mode)
2872 static bool dce_v6_0_ext_mode_fixup(struct drm_encoder *encoder,
2873 const struct drm_display_mode *mode,
2874 struct drm_display_mode *adjusted_mode)
2879 static const struct drm_encoder_helper_funcs dce_v6_0_ext_helper_funcs = {
2880 .dpms = dce_v6_0_ext_dpms,
2881 .mode_fixup = dce_v6_0_ext_mode_fixup,
2882 .prepare = dce_v6_0_ext_prepare,
2883 .mode_set = dce_v6_0_ext_mode_set,
2884 .commit = dce_v6_0_ext_commit,
2885 .disable = dce_v6_0_ext_disable,
2886 /* no detect for TMDS/LVDS yet */
2889 static const struct drm_encoder_helper_funcs dce_v6_0_dig_helper_funcs = {
2890 .dpms = amdgpu_atombios_encoder_dpms,
2891 .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
2892 .prepare = dce_v6_0_encoder_prepare,
2893 .mode_set = dce_v6_0_encoder_mode_set,
2894 .commit = dce_v6_0_encoder_commit,
2895 .disable = dce_v6_0_encoder_disable,
2896 .detect = amdgpu_atombios_encoder_dig_detect,
2899 static const struct drm_encoder_helper_funcs dce_v6_0_dac_helper_funcs = {
2900 .dpms = amdgpu_atombios_encoder_dpms,
2901 .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
2902 .prepare = dce_v6_0_encoder_prepare,
2903 .mode_set = dce_v6_0_encoder_mode_set,
2904 .commit = dce_v6_0_encoder_commit,
2905 .detect = amdgpu_atombios_encoder_dac_detect,
2908 static void dce_v6_0_encoder_destroy(struct drm_encoder *encoder)
2910 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2911 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
2912 amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder);
2913 kfree(amdgpu_encoder->enc_priv);
2914 drm_encoder_cleanup(encoder);
2915 kfree(amdgpu_encoder);
2918 static const struct drm_encoder_funcs dce_v6_0_encoder_funcs = {
2919 .destroy = dce_v6_0_encoder_destroy,
2922 static void dce_v6_0_encoder_add(struct amdgpu_device *adev,
2923 uint32_t encoder_enum,
2924 uint32_t supported_device,
2927 struct drm_device *dev = adev->ddev;
2928 struct drm_encoder *encoder;
2929 struct amdgpu_encoder *amdgpu_encoder;
2931 /* see if we already added it */
2932 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2933 amdgpu_encoder = to_amdgpu_encoder(encoder);
2934 if (amdgpu_encoder->encoder_enum == encoder_enum) {
2935 amdgpu_encoder->devices |= supported_device;
2942 amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL);
2943 if (!amdgpu_encoder)
2946 encoder = &amdgpu_encoder->base;
2947 switch (adev->mode_info.num_crtc) {
2949 encoder->possible_crtcs = 0x1;
2953 encoder->possible_crtcs = 0x3;
2956 encoder->possible_crtcs = 0xf;
2959 encoder->possible_crtcs = 0x3f;
2963 amdgpu_encoder->enc_priv = NULL;
2964 amdgpu_encoder->encoder_enum = encoder_enum;
2965 amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
2966 amdgpu_encoder->devices = supported_device;
2967 amdgpu_encoder->rmx_type = RMX_OFF;
2968 amdgpu_encoder->underscan_type = UNDERSCAN_OFF;
2969 amdgpu_encoder->is_ext_encoder = false;
2970 amdgpu_encoder->caps = caps;
2972 switch (amdgpu_encoder->encoder_id) {
2973 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2974 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2975 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
2976 DRM_MODE_ENCODER_DAC, NULL);
2977 drm_encoder_helper_add(encoder, &dce_v6_0_dac_helper_funcs);
2979 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2980 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2981 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2982 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2983 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
2984 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
2985 amdgpu_encoder->rmx_type = RMX_FULL;
2986 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
2987 DRM_MODE_ENCODER_LVDS, NULL);
2988 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder);
2989 } else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
2990 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
2991 DRM_MODE_ENCODER_DAC, NULL);
2992 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
2994 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
2995 DRM_MODE_ENCODER_TMDS, NULL);
2996 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
2998 drm_encoder_helper_add(encoder, &dce_v6_0_dig_helper_funcs);
3000 case ENCODER_OBJECT_ID_SI170B:
3001 case ENCODER_OBJECT_ID_CH7303:
3002 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
3003 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
3004 case ENCODER_OBJECT_ID_TITFP513:
3005 case ENCODER_OBJECT_ID_VT1623:
3006 case ENCODER_OBJECT_ID_HDMI_SI1930:
3007 case ENCODER_OBJECT_ID_TRAVIS:
3008 case ENCODER_OBJECT_ID_NUTMEG:
3009 /* these are handled by the primary encoders */
3010 amdgpu_encoder->is_ext_encoder = true;
3011 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
3012 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
3013 DRM_MODE_ENCODER_LVDS, NULL);
3014 else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
3015 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
3016 DRM_MODE_ENCODER_DAC, NULL);
3018 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
3019 DRM_MODE_ENCODER_TMDS, NULL);
3020 drm_encoder_helper_add(encoder, &dce_v6_0_ext_helper_funcs);
3025 static const struct amdgpu_display_funcs dce_v6_0_display_funcs = {
3026 .set_vga_render_state = &dce_v6_0_set_vga_render_state,
3027 .bandwidth_update = &dce_v6_0_bandwidth_update,
3028 .vblank_get_counter = &dce_v6_0_vblank_get_counter,
3029 .vblank_wait = &dce_v6_0_vblank_wait,
3030 .backlight_set_level = &amdgpu_atombios_encoder_set_backlight_level,
3031 .backlight_get_level = &amdgpu_atombios_encoder_get_backlight_level,
3032 .hpd_sense = &dce_v6_0_hpd_sense,
3033 .hpd_set_polarity = &dce_v6_0_hpd_set_polarity,
3034 .hpd_get_gpio_reg = &dce_v6_0_hpd_get_gpio_reg,
3035 .page_flip = &dce_v6_0_page_flip,
3036 .page_flip_get_scanoutpos = &dce_v6_0_crtc_get_scanoutpos,
3037 .add_encoder = &dce_v6_0_encoder_add,
3038 .add_connector = &amdgpu_connector_add,
3039 .stop_mc_access = &dce_v6_0_stop_mc_access,
3040 .resume_mc_access = &dce_v6_0_resume_mc_access,
3043 static void dce_v6_0_set_display_funcs(struct amdgpu_device *adev)
3045 if (adev->mode_info.funcs == NULL)
3046 adev->mode_info.funcs = &dce_v6_0_display_funcs;
3049 static const struct amdgpu_irq_src_funcs dce_v6_0_crtc_irq_funcs = {
3050 .set = dce_v6_0_set_crtc_interrupt_state,
3051 .process = dce_v6_0_crtc_irq,
3054 static const struct amdgpu_irq_src_funcs dce_v6_0_pageflip_irq_funcs = {
3055 .set = dce_v6_0_set_pageflip_interrupt_state,
3056 .process = dce_v6_0_pageflip_irq,
3059 static const struct amdgpu_irq_src_funcs dce_v6_0_hpd_irq_funcs = {
3060 .set = dce_v6_0_set_hpd_interrupt_state,
3061 .process = dce_v6_0_hpd_irq,
3064 static void dce_v6_0_set_irq_funcs(struct amdgpu_device *adev)
3066 adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_LAST;
3067 adev->crtc_irq.funcs = &dce_v6_0_crtc_irq_funcs;
3069 adev->pageflip_irq.num_types = AMDGPU_PAGEFLIP_IRQ_LAST;
3070 adev->pageflip_irq.funcs = &dce_v6_0_pageflip_irq_funcs;
3072 adev->hpd_irq.num_types = AMDGPU_HPD_LAST;
3073 adev->hpd_irq.funcs = &dce_v6_0_hpd_irq_funcs;
3076 const struct amdgpu_ip_block_version dce_v6_0_ip_block =
3078 .type = AMD_IP_BLOCK_TYPE_DCE,
3082 .funcs = &dce_v6_0_ip_funcs,
3085 const struct amdgpu_ip_block_version dce_v6_4_ip_block =
3087 .type = AMD_IP_BLOCK_TYPE_DCE,
3091 .funcs = &dce_v6_0_ip_funcs,