2 * Copyright 2014 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"
29 #include "amdgpu_atombios.h"
30 #include "atombios_crtc.h"
31 #include "atombios_encoders.h"
32 #include "amdgpu_pll.h"
33 #include "amdgpu_connectors.h"
35 #include "dce/dce_11_0_d.h"
36 #include "dce/dce_11_0_sh_mask.h"
37 #include "dce/dce_11_0_enum.h"
38 #include "oss/oss_3_0_d.h"
39 #include "oss/oss_3_0_sh_mask.h"
40 #include "gmc/gmc_8_1_d.h"
41 #include "gmc/gmc_8_1_sh_mask.h"
43 static void dce_v11_0_set_display_funcs(struct amdgpu_device
*adev
);
44 static void dce_v11_0_set_irq_funcs(struct amdgpu_device
*adev
);
46 static const u32 crtc_offsets
[] =
48 CRTC0_REGISTER_OFFSET
,
49 CRTC1_REGISTER_OFFSET
,
50 CRTC2_REGISTER_OFFSET
,
51 CRTC3_REGISTER_OFFSET
,
52 CRTC4_REGISTER_OFFSET
,
53 CRTC5_REGISTER_OFFSET
,
57 static const u32 hpd_offsets
[] =
67 static const uint32_t dig_offsets
[] = {
85 } interrupt_status_offsets
[] = { {
86 .reg
= mmDISP_INTERRUPT_STATUS
,
87 .vblank
= DISP_INTERRUPT_STATUS__LB_D1_VBLANK_INTERRUPT_MASK
,
88 .vline
= DISP_INTERRUPT_STATUS__LB_D1_VLINE_INTERRUPT_MASK
,
89 .hpd
= DISP_INTERRUPT_STATUS__DC_HPD1_INTERRUPT_MASK
91 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE
,
92 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VBLANK_INTERRUPT_MASK
,
93 .vline
= DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VLINE_INTERRUPT_MASK
,
94 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE__DC_HPD2_INTERRUPT_MASK
96 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE2
,
97 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VBLANK_INTERRUPT_MASK
,
98 .vline
= DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VLINE_INTERRUPT_MASK
,
99 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE2__DC_HPD3_INTERRUPT_MASK
101 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE3
,
102 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VBLANK_INTERRUPT_MASK
,
103 .vline
= DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VLINE_INTERRUPT_MASK
,
104 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE3__DC_HPD4_INTERRUPT_MASK
106 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE4
,
107 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VBLANK_INTERRUPT_MASK
,
108 .vline
= DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VLINE_INTERRUPT_MASK
,
109 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE4__DC_HPD5_INTERRUPT_MASK
111 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE5
,
112 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VBLANK_INTERRUPT_MASK
,
113 .vline
= DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VLINE_INTERRUPT_MASK
,
114 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE5__DC_HPD6_INTERRUPT_MASK
117 static const u32 cz_golden_settings_a11
[] =
119 mmCRTC_DOUBLE_BUFFER_CONTROL
, 0x00010101, 0x00010000,
120 mmFBC_MISC
, 0x1f311fff, 0x14300000,
123 static const u32 cz_mgcg_cgcg_init
[] =
125 mmXDMA_CLOCK_GATING_CNTL
, 0xffffffff, 0x00000100,
126 mmXDMA_MEM_POWER_CNTL
, 0x00000101, 0x00000000,
129 static void dce_v11_0_init_golden_registers(struct amdgpu_device
*adev
)
131 switch (adev
->asic_type
) {
133 amdgpu_program_register_sequence(adev
,
135 (const u32
)ARRAY_SIZE(cz_mgcg_cgcg_init
));
136 amdgpu_program_register_sequence(adev
,
137 cz_golden_settings_a11
,
138 (const u32
)ARRAY_SIZE(cz_golden_settings_a11
));
145 static u32
dce_v11_0_audio_endpt_rreg(struct amdgpu_device
*adev
,
146 u32 block_offset
, u32 reg
)
151 spin_lock_irqsave(&adev
->audio_endpt_idx_lock
, flags
);
152 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX
+ block_offset
, reg
);
153 r
= RREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA
+ block_offset
);
154 spin_unlock_irqrestore(&adev
->audio_endpt_idx_lock
, flags
);
159 static void dce_v11_0_audio_endpt_wreg(struct amdgpu_device
*adev
,
160 u32 block_offset
, u32 reg
, u32 v
)
164 spin_lock_irqsave(&adev
->audio_endpt_idx_lock
, flags
);
165 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX
+ block_offset
, reg
);
166 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA
+ block_offset
, v
);
167 spin_unlock_irqrestore(&adev
->audio_endpt_idx_lock
, flags
);
170 static bool dce_v11_0_is_in_vblank(struct amdgpu_device
*adev
, int crtc
)
172 if (RREG32(mmCRTC_STATUS
+ crtc_offsets
[crtc
]) &
173 CRTC_V_BLANK_START_END__CRTC_V_BLANK_START_MASK
)
179 static bool dce_v11_0_is_counter_moving(struct amdgpu_device
*adev
, int crtc
)
183 pos1
= RREG32(mmCRTC_STATUS_POSITION
+ crtc_offsets
[crtc
]);
184 pos2
= RREG32(mmCRTC_STATUS_POSITION
+ crtc_offsets
[crtc
]);
193 * dce_v11_0_vblank_wait - vblank wait asic callback.
195 * @adev: amdgpu_device pointer
196 * @crtc: crtc to wait for vblank on
198 * Wait for vblank on the requested crtc (evergreen+).
200 static void dce_v11_0_vblank_wait(struct amdgpu_device
*adev
, int crtc
)
204 if (crtc
>= adev
->mode_info
.num_crtc
)
207 if (!(RREG32(mmCRTC_CONTROL
+ crtc_offsets
[crtc
]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK
))
210 /* depending on when we hit vblank, we may be close to active; if so,
211 * wait for another frame.
213 while (dce_v11_0_is_in_vblank(adev
, crtc
)) {
214 if (i
++ % 100 == 0) {
215 if (!dce_v11_0_is_counter_moving(adev
, crtc
))
220 while (!dce_v11_0_is_in_vblank(adev
, crtc
)) {
221 if (i
++ % 100 == 0) {
222 if (!dce_v11_0_is_counter_moving(adev
, crtc
))
228 static u32
dce_v11_0_vblank_get_counter(struct amdgpu_device
*adev
, int crtc
)
230 if (crtc
>= adev
->mode_info
.num_crtc
)
233 return RREG32(mmCRTC_STATUS_FRAME_COUNT
+ crtc_offsets
[crtc
]);
236 static void dce_v11_0_pageflip_interrupt_init(struct amdgpu_device
*adev
)
240 /* Enable pflip interrupts */
241 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++)
242 amdgpu_irq_get(adev
, &adev
->pageflip_irq
, i
);
245 static void dce_v11_0_pageflip_interrupt_fini(struct amdgpu_device
*adev
)
249 /* Disable pflip interrupts */
250 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++)
251 amdgpu_irq_put(adev
, &adev
->pageflip_irq
, i
);
255 * dce_v11_0_page_flip - pageflip callback.
257 * @adev: amdgpu_device pointer
258 * @crtc_id: crtc to cleanup pageflip on
259 * @crtc_base: new address of the crtc (GPU MC address)
261 * Does the actual pageflip (evergreen+).
262 * During vblank we take the crtc lock and wait for the update_pending
263 * bit to go high, when it does, we release the lock, and allow the
264 * double buffered update to take place.
265 * Returns the current update pending status.
267 static void dce_v11_0_page_flip(struct amdgpu_device
*adev
,
268 int crtc_id
, u64 crtc_base
)
270 struct amdgpu_crtc
*amdgpu_crtc
= adev
->mode_info
.crtcs
[crtc_id
];
271 u32 tmp
= RREG32(mmGRPH_UPDATE
+ amdgpu_crtc
->crtc_offset
);
274 /* Lock the graphics update lock */
275 tmp
= REG_SET_FIELD(tmp
, GRPH_UPDATE
, GRPH_UPDATE_LOCK
, 1);
276 WREG32(mmGRPH_UPDATE
+ amdgpu_crtc
->crtc_offset
, tmp
);
278 /* update the scanout addresses */
279 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
280 upper_32_bits(crtc_base
));
281 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
282 lower_32_bits(crtc_base
));
284 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
285 upper_32_bits(crtc_base
));
286 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
287 lower_32_bits(crtc_base
));
289 /* Wait for update_pending to go high. */
290 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
291 if (RREG32(mmGRPH_UPDATE
+ amdgpu_crtc
->crtc_offset
) &
292 GRPH_UPDATE__GRPH_SURFACE_UPDATE_PENDING_MASK
)
296 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
298 /* Unlock the lock, so double-buffering can take place inside vblank */
299 tmp
= REG_SET_FIELD(tmp
, GRPH_UPDATE
, GRPH_UPDATE_LOCK
, 0);
300 WREG32(mmGRPH_UPDATE
+ amdgpu_crtc
->crtc_offset
, tmp
);
303 static int dce_v11_0_crtc_get_scanoutpos(struct amdgpu_device
*adev
, int crtc
,
304 u32
*vbl
, u32
*position
)
306 if ((crtc
< 0) || (crtc
>= adev
->mode_info
.num_crtc
))
309 *vbl
= RREG32(mmCRTC_V_BLANK_START_END
+ crtc_offsets
[crtc
]);
310 *position
= RREG32(mmCRTC_STATUS_POSITION
+ crtc_offsets
[crtc
]);
316 * dce_v11_0_hpd_sense - hpd sense callback.
318 * @adev: amdgpu_device pointer
319 * @hpd: hpd (hotplug detect) pin
321 * Checks if a digital monitor is connected (evergreen+).
322 * Returns true if connected, false if not connected.
324 static bool dce_v11_0_hpd_sense(struct amdgpu_device
*adev
,
325 enum amdgpu_hpd_id hpd
)
328 bool connected
= false;
353 if (RREG32(mmDC_HPD_INT_STATUS
+ hpd_offsets
[idx
]) &
354 DC_HPD_INT_STATUS__DC_HPD_SENSE_MASK
)
361 * dce_v11_0_hpd_set_polarity - hpd set polarity callback.
363 * @adev: amdgpu_device pointer
364 * @hpd: hpd (hotplug detect) pin
366 * Set the polarity of the hpd pin (evergreen+).
368 static void dce_v11_0_hpd_set_polarity(struct amdgpu_device
*adev
,
369 enum amdgpu_hpd_id hpd
)
372 bool connected
= dce_v11_0_hpd_sense(adev
, hpd
);
398 tmp
= RREG32(mmDC_HPD_INT_CONTROL
+ hpd_offsets
[idx
]);
400 tmp
= REG_SET_FIELD(tmp
, DC_HPD_INT_CONTROL
, DC_HPD_INT_POLARITY
, 0);
402 tmp
= REG_SET_FIELD(tmp
, DC_HPD_INT_CONTROL
, DC_HPD_INT_POLARITY
, 1);
403 WREG32(mmDC_HPD_INT_CONTROL
+ hpd_offsets
[idx
], tmp
);
407 * dce_v11_0_hpd_init - hpd setup callback.
409 * @adev: amdgpu_device pointer
411 * Setup the hpd pins used by the card (evergreen+).
412 * Enable the pin, set the polarity, and enable the hpd interrupts.
414 static void dce_v11_0_hpd_init(struct amdgpu_device
*adev
)
416 struct drm_device
*dev
= adev
->ddev
;
417 struct drm_connector
*connector
;
421 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
422 struct amdgpu_connector
*amdgpu_connector
= to_amdgpu_connector(connector
);
424 if (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
||
425 connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
) {
426 /* don't try to enable hpd on eDP or LVDS avoid breaking the
427 * aux dp channel on imac and help (but not completely fix)
428 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
429 * also avoid interrupt storms during dpms.
434 switch (amdgpu_connector
->hpd
.hpd
) {
457 tmp
= RREG32(mmDC_HPD_CONTROL
+ hpd_offsets
[idx
]);
458 tmp
= REG_SET_FIELD(tmp
, DC_HPD_CONTROL
, DC_HPD_EN
, 1);
459 WREG32(mmDC_HPD_CONTROL
+ hpd_offsets
[idx
], tmp
);
461 tmp
= RREG32(mmDC_HPD_TOGGLE_FILT_CNTL
+ hpd_offsets
[idx
]);
462 tmp
= REG_SET_FIELD(tmp
, DC_HPD_TOGGLE_FILT_CNTL
,
463 DC_HPD_CONNECT_INT_DELAY
,
464 AMDGPU_HPD_CONNECT_INT_DELAY_IN_MS
);
465 tmp
= REG_SET_FIELD(tmp
, DC_HPD_TOGGLE_FILT_CNTL
,
466 DC_HPD_DISCONNECT_INT_DELAY
,
467 AMDGPU_HPD_DISCONNECT_INT_DELAY_IN_MS
);
468 WREG32(mmDC_HPD_TOGGLE_FILT_CNTL
+ hpd_offsets
[idx
], tmp
);
470 dce_v11_0_hpd_set_polarity(adev
, amdgpu_connector
->hpd
.hpd
);
471 amdgpu_irq_get(adev
, &adev
->hpd_irq
, amdgpu_connector
->hpd
.hpd
);
476 * dce_v11_0_hpd_fini - hpd tear down callback.
478 * @adev: amdgpu_device pointer
480 * Tear down the hpd pins used by the card (evergreen+).
481 * Disable the hpd interrupts.
483 static void dce_v11_0_hpd_fini(struct amdgpu_device
*adev
)
485 struct drm_device
*dev
= adev
->ddev
;
486 struct drm_connector
*connector
;
490 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
491 struct amdgpu_connector
*amdgpu_connector
= to_amdgpu_connector(connector
);
493 switch (amdgpu_connector
->hpd
.hpd
) {
516 tmp
= RREG32(mmDC_HPD_CONTROL
+ hpd_offsets
[idx
]);
517 tmp
= REG_SET_FIELD(tmp
, DC_HPD_CONTROL
, DC_HPD_EN
, 0);
518 WREG32(mmDC_HPD_CONTROL
+ hpd_offsets
[idx
], tmp
);
520 amdgpu_irq_put(adev
, &adev
->hpd_irq
, amdgpu_connector
->hpd
.hpd
);
524 static u32
dce_v11_0_hpd_get_gpio_reg(struct amdgpu_device
*adev
)
526 return mmDC_GPIO_HPD_A
;
529 static bool dce_v11_0_is_display_hung(struct amdgpu_device
*adev
)
535 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
536 tmp
= RREG32(mmCRTC_CONTROL
+ crtc_offsets
[i
]);
537 if (REG_GET_FIELD(tmp
, CRTC_CONTROL
, CRTC_MASTER_EN
)) {
538 crtc_status
[i
] = RREG32(mmCRTC_STATUS_HV_COUNT
+ crtc_offsets
[i
]);
539 crtc_hung
|= (1 << i
);
543 for (j
= 0; j
< 10; j
++) {
544 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
545 if (crtc_hung
& (1 << i
)) {
546 tmp
= RREG32(mmCRTC_STATUS_HV_COUNT
+ crtc_offsets
[i
]);
547 if (tmp
!= crtc_status
[i
])
548 crtc_hung
&= ~(1 << i
);
559 static void dce_v11_0_stop_mc_access(struct amdgpu_device
*adev
,
560 struct amdgpu_mode_mc_save
*save
)
562 u32 crtc_enabled
, tmp
;
565 save
->vga_render_control
= RREG32(mmVGA_RENDER_CONTROL
);
566 save
->vga_hdp_control
= RREG32(mmVGA_HDP_CONTROL
);
568 /* disable VGA render */
569 tmp
= RREG32(mmVGA_RENDER_CONTROL
);
570 tmp
= REG_SET_FIELD(tmp
, VGA_RENDER_CONTROL
, VGA_VSTATUS_CNTL
, 0);
571 WREG32(mmVGA_RENDER_CONTROL
, tmp
);
573 /* blank the display controllers */
574 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
575 crtc_enabled
= REG_GET_FIELD(RREG32(mmCRTC_CONTROL
+ crtc_offsets
[i
]),
576 CRTC_CONTROL
, CRTC_MASTER_EN
);
582 save
->crtc_enabled
[i
] = true;
583 tmp
= RREG32(mmCRTC_BLANK_CONTROL
+ crtc_offsets
[i
]);
584 if (REG_GET_FIELD(tmp
, CRTC_BLANK_CONTROL
, CRTC_BLANK_DATA_EN
) == 0) {
585 amdgpu_display_vblank_wait(adev
, i
);
586 WREG32(mmCRTC_UPDATE_LOCK
+ crtc_offsets
[i
], 1);
587 tmp
= REG_SET_FIELD(tmp
, CRTC_BLANK_CONTROL
, CRTC_BLANK_DATA_EN
, 1);
588 WREG32(mmCRTC_BLANK_CONTROL
+ crtc_offsets
[i
], tmp
);
589 WREG32(mmCRTC_UPDATE_LOCK
+ crtc_offsets
[i
], 0);
591 /* wait for the next frame */
592 frame_count
= amdgpu_display_vblank_get_counter(adev
, i
);
593 for (j
= 0; j
< adev
->usec_timeout
; j
++) {
594 if (amdgpu_display_vblank_get_counter(adev
, i
) != frame_count
)
598 tmp
= RREG32(mmGRPH_UPDATE
+ crtc_offsets
[i
]);
599 if (REG_GET_FIELD(tmp
, GRPH_UPDATE
, GRPH_UPDATE_LOCK
) == 0) {
600 tmp
= REG_SET_FIELD(tmp
, GRPH_UPDATE
, GRPH_UPDATE_LOCK
, 1);
601 WREG32(mmGRPH_UPDATE
+ crtc_offsets
[i
], tmp
);
603 tmp
= RREG32(mmCRTC_MASTER_UPDATE_LOCK
+ crtc_offsets
[i
]);
604 if (REG_GET_FIELD(tmp
, CRTC_MASTER_UPDATE_LOCK
, MASTER_UPDATE_LOCK
) == 0) {
605 tmp
= REG_SET_FIELD(tmp
, CRTC_MASTER_UPDATE_LOCK
, MASTER_UPDATE_LOCK
, 1);
606 WREG32(mmCRTC_MASTER_UPDATE_LOCK
+ crtc_offsets
[i
], tmp
);
609 /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
610 WREG32(mmCRTC_UPDATE_LOCK
+ crtc_offsets
[i
], 1);
611 tmp
= RREG32(mmCRTC_CONTROL
+ crtc_offsets
[i
]);
612 tmp
= REG_SET_FIELD(tmp
, CRTC_CONTROL
, CRTC_MASTER_EN
, 0);
613 WREG32(mmCRTC_CONTROL
+ crtc_offsets
[i
], tmp
);
614 WREG32(mmCRTC_UPDATE_LOCK
+ crtc_offsets
[i
], 0);
615 save
->crtc_enabled
[i
] = false;
619 save
->crtc_enabled
[i
] = false;
624 static void dce_v11_0_resume_mc_access(struct amdgpu_device
*adev
,
625 struct amdgpu_mode_mc_save
*save
)
627 u32 tmp
, frame_count
;
630 /* update crtc base addresses */
631 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
632 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH
+ crtc_offsets
[i
],
633 upper_32_bits(adev
->mc
.vram_start
));
634 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH
+ crtc_offsets
[i
],
635 upper_32_bits(adev
->mc
.vram_start
));
636 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS
+ crtc_offsets
[i
],
637 (u32
)adev
->mc
.vram_start
);
638 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS
+ crtc_offsets
[i
],
639 (u32
)adev
->mc
.vram_start
);
641 if (save
->crtc_enabled
[i
]) {
642 tmp
= RREG32(mmCRTC_MASTER_UPDATE_MODE
+ crtc_offsets
[i
]);
643 if (REG_GET_FIELD(tmp
, CRTC_MASTER_UPDATE_MODE
, MASTER_UPDATE_MODE
) != 3) {
644 tmp
= REG_SET_FIELD(tmp
, CRTC_MASTER_UPDATE_MODE
, MASTER_UPDATE_MODE
, 3);
645 WREG32(mmCRTC_MASTER_UPDATE_MODE
+ crtc_offsets
[i
], tmp
);
647 tmp
= RREG32(mmGRPH_UPDATE
+ crtc_offsets
[i
]);
648 if (REG_GET_FIELD(tmp
, GRPH_UPDATE
, GRPH_UPDATE_LOCK
)) {
649 tmp
= REG_SET_FIELD(tmp
, GRPH_UPDATE
, GRPH_UPDATE_LOCK
, 0);
650 WREG32(mmGRPH_UPDATE
+ crtc_offsets
[i
], tmp
);
652 tmp
= RREG32(mmCRTC_MASTER_UPDATE_LOCK
+ crtc_offsets
[i
]);
653 if (REG_GET_FIELD(tmp
, CRTC_MASTER_UPDATE_LOCK
, MASTER_UPDATE_LOCK
)) {
654 tmp
= REG_SET_FIELD(tmp
, CRTC_MASTER_UPDATE_LOCK
, MASTER_UPDATE_LOCK
, 0);
655 WREG32(mmCRTC_MASTER_UPDATE_LOCK
+ crtc_offsets
[i
], tmp
);
657 for (j
= 0; j
< adev
->usec_timeout
; j
++) {
658 tmp
= RREG32(mmGRPH_UPDATE
+ crtc_offsets
[i
]);
659 if (REG_GET_FIELD(tmp
, GRPH_UPDATE
, GRPH_SURFACE_UPDATE_PENDING
) == 0)
663 tmp
= RREG32(mmCRTC_BLANK_CONTROL
+ crtc_offsets
[i
]);
664 tmp
= REG_SET_FIELD(tmp
, CRTC_BLANK_CONTROL
, CRTC_BLANK_DATA_EN
, 0);
665 WREG32(mmCRTC_UPDATE_LOCK
+ crtc_offsets
[i
], 1);
666 WREG32(mmCRTC_BLANK_CONTROL
+ crtc_offsets
[i
], tmp
);
667 WREG32(mmCRTC_UPDATE_LOCK
+ crtc_offsets
[i
], 0);
668 /* wait for the next frame */
669 frame_count
= amdgpu_display_vblank_get_counter(adev
, i
);
670 for (j
= 0; j
< adev
->usec_timeout
; j
++) {
671 if (amdgpu_display_vblank_get_counter(adev
, i
) != frame_count
)
678 WREG32(mmVGA_MEMORY_BASE_ADDRESS_HIGH
, upper_32_bits(adev
->mc
.vram_start
));
679 WREG32(mmVGA_MEMORY_BASE_ADDRESS
, lower_32_bits(adev
->mc
.vram_start
));
681 /* Unlock vga access */
682 WREG32(mmVGA_HDP_CONTROL
, save
->vga_hdp_control
);
684 WREG32(mmVGA_RENDER_CONTROL
, save
->vga_render_control
);
687 static void dce_v11_0_set_vga_render_state(struct amdgpu_device
*adev
,
692 /* Lockout access through VGA aperture*/
693 tmp
= RREG32(mmVGA_HDP_CONTROL
);
695 tmp
= REG_SET_FIELD(tmp
, VGA_HDP_CONTROL
, VGA_MEMORY_DISABLE
, 0);
697 tmp
= REG_SET_FIELD(tmp
, VGA_HDP_CONTROL
, VGA_MEMORY_DISABLE
, 1);
698 WREG32(mmVGA_HDP_CONTROL
, tmp
);
700 /* disable VGA render */
701 tmp
= RREG32(mmVGA_RENDER_CONTROL
);
703 tmp
= REG_SET_FIELD(tmp
, VGA_RENDER_CONTROL
, VGA_VSTATUS_CNTL
, 1);
705 tmp
= REG_SET_FIELD(tmp
, VGA_RENDER_CONTROL
, VGA_VSTATUS_CNTL
, 0);
706 WREG32(mmVGA_RENDER_CONTROL
, tmp
);
709 static void dce_v11_0_program_fmt(struct drm_encoder
*encoder
)
711 struct drm_device
*dev
= encoder
->dev
;
712 struct amdgpu_device
*adev
= dev
->dev_private
;
713 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
714 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(encoder
->crtc
);
715 struct drm_connector
*connector
= amdgpu_get_connector_for_encoder(encoder
);
718 enum amdgpu_connector_dither dither
= AMDGPU_FMT_DITHER_DISABLE
;
721 struct amdgpu_connector
*amdgpu_connector
= to_amdgpu_connector(connector
);
722 bpc
= amdgpu_connector_get_monitor_bpc(connector
);
723 dither
= amdgpu_connector
->dither
;
726 /* LVDS/eDP FMT is set up by atom */
727 if (amdgpu_encoder
->devices
& ATOM_DEVICE_LCD_SUPPORT
)
730 /* not needed for analog */
731 if ((amdgpu_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
) ||
732 (amdgpu_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
))
740 if (dither
== AMDGPU_FMT_DITHER_ENABLE
) {
741 /* XXX sort out optimal dither settings */
742 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_FRAME_RANDOM_ENABLE
, 1);
743 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_HIGHPASS_RANDOM_ENABLE
, 1);
744 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_SPATIAL_DITHER_EN
, 1);
745 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_SPATIAL_DITHER_DEPTH
, 0);
747 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_TRUNCATE_EN
, 1);
748 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_TRUNCATE_DEPTH
, 0);
752 if (dither
== AMDGPU_FMT_DITHER_ENABLE
) {
753 /* XXX sort out optimal dither settings */
754 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_FRAME_RANDOM_ENABLE
, 1);
755 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_HIGHPASS_RANDOM_ENABLE
, 1);
756 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_RGB_RANDOM_ENABLE
, 1);
757 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_SPATIAL_DITHER_EN
, 1);
758 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_SPATIAL_DITHER_DEPTH
, 1);
760 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_TRUNCATE_EN
, 1);
761 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_TRUNCATE_DEPTH
, 1);
765 if (dither
== AMDGPU_FMT_DITHER_ENABLE
) {
766 /* XXX sort out optimal dither settings */
767 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_FRAME_RANDOM_ENABLE
, 1);
768 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_HIGHPASS_RANDOM_ENABLE
, 1);
769 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_RGB_RANDOM_ENABLE
, 1);
770 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_SPATIAL_DITHER_EN
, 1);
771 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_SPATIAL_DITHER_DEPTH
, 2);
773 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_TRUNCATE_EN
, 1);
774 tmp
= REG_SET_FIELD(tmp
, FMT_BIT_DEPTH_CONTROL
, FMT_TRUNCATE_DEPTH
, 2);
782 WREG32(mmFMT_BIT_DEPTH_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
786 /* display watermark setup */
788 * dce_v11_0_line_buffer_adjust - Set up the line buffer
790 * @adev: amdgpu_device pointer
791 * @amdgpu_crtc: the selected display controller
792 * @mode: the current display mode on the selected display
795 * Setup up the line buffer allocation for
796 * the selected display controller (CIK).
797 * Returns the line buffer size in pixels.
799 static u32
dce_v11_0_line_buffer_adjust(struct amdgpu_device
*adev
,
800 struct amdgpu_crtc
*amdgpu_crtc
,
801 struct drm_display_mode
*mode
)
803 u32 tmp
, buffer_alloc
, i
, mem_cfg
;
804 u32 pipe_offset
= amdgpu_crtc
->crtc_id
;
807 * There are 6 line buffers, one for each display controllers.
808 * There are 3 partitions per LB. Select the number of partitions
809 * to enable based on the display width. For display widths larger
810 * than 4096, you need use to use 2 display controllers and combine
811 * them using the stereo blender.
813 if (amdgpu_crtc
->base
.enabled
&& mode
) {
814 if (mode
->crtc_hdisplay
< 1920) {
817 } else if (mode
->crtc_hdisplay
< 2560) {
820 } else if (mode
->crtc_hdisplay
< 4096) {
822 buffer_alloc
= (adev
->flags
& AMD_IS_APU
) ? 2 : 4;
824 DRM_DEBUG_KMS("Mode too big for LB!\n");
826 buffer_alloc
= (adev
->flags
& AMD_IS_APU
) ? 2 : 4;
833 tmp
= RREG32(mmLB_MEMORY_CTRL
+ amdgpu_crtc
->crtc_offset
);
834 tmp
= REG_SET_FIELD(tmp
, LB_MEMORY_CTRL
, LB_MEMORY_CONFIG
, mem_cfg
);
835 WREG32(mmLB_MEMORY_CTRL
+ amdgpu_crtc
->crtc_offset
, tmp
);
837 tmp
= RREG32(mmPIPE0_DMIF_BUFFER_CONTROL
+ pipe_offset
);
838 tmp
= REG_SET_FIELD(tmp
, PIPE0_DMIF_BUFFER_CONTROL
, DMIF_BUFFERS_ALLOCATED
, buffer_alloc
);
839 WREG32(mmPIPE0_DMIF_BUFFER_CONTROL
+ pipe_offset
, tmp
);
841 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
842 tmp
= RREG32(mmPIPE0_DMIF_BUFFER_CONTROL
+ pipe_offset
);
843 if (REG_GET_FIELD(tmp
, PIPE0_DMIF_BUFFER_CONTROL
, DMIF_BUFFERS_ALLOCATION_COMPLETED
))
848 if (amdgpu_crtc
->base
.enabled
&& mode
) {
860 /* controller not enabled, so no lb used */
865 * cik_get_number_of_dram_channels - get the number of dram channels
867 * @adev: amdgpu_device pointer
869 * Look up the number of video ram channels (CIK).
870 * Used for display watermark bandwidth calculations
871 * Returns the number of dram channels
873 static u32
cik_get_number_of_dram_channels(struct amdgpu_device
*adev
)
875 u32 tmp
= RREG32(mmMC_SHARED_CHMAP
);
877 switch (REG_GET_FIELD(tmp
, MC_SHARED_CHMAP
, NOOFCHAN
)) {
900 struct dce10_wm_params
{
901 u32 dram_channels
; /* number of dram channels */
902 u32 yclk
; /* bandwidth per dram data pin in kHz */
903 u32 sclk
; /* engine clock in kHz */
904 u32 disp_clk
; /* display clock in kHz */
905 u32 src_width
; /* viewport width */
906 u32 active_time
; /* active display time in ns */
907 u32 blank_time
; /* blank time in ns */
908 bool interlaced
; /* mode is interlaced */
909 fixed20_12 vsc
; /* vertical scale ratio */
910 u32 num_heads
; /* number of active crtcs */
911 u32 bytes_per_pixel
; /* bytes per pixel display + overlay */
912 u32 lb_size
; /* line buffer allocated to pipe */
913 u32 vtaps
; /* vertical scaler taps */
917 * dce_v11_0_dram_bandwidth - get the dram bandwidth
919 * @wm: watermark calculation data
921 * Calculate the raw dram bandwidth (CIK).
922 * Used for display watermark bandwidth calculations
923 * Returns the dram bandwidth in MBytes/s
925 static u32
dce_v11_0_dram_bandwidth(struct dce10_wm_params
*wm
)
927 /* Calculate raw DRAM Bandwidth */
928 fixed20_12 dram_efficiency
; /* 0.7 */
929 fixed20_12 yclk
, dram_channels
, bandwidth
;
932 a
.full
= dfixed_const(1000);
933 yclk
.full
= dfixed_const(wm
->yclk
);
934 yclk
.full
= dfixed_div(yclk
, a
);
935 dram_channels
.full
= dfixed_const(wm
->dram_channels
* 4);
936 a
.full
= dfixed_const(10);
937 dram_efficiency
.full
= dfixed_const(7);
938 dram_efficiency
.full
= dfixed_div(dram_efficiency
, a
);
939 bandwidth
.full
= dfixed_mul(dram_channels
, yclk
);
940 bandwidth
.full
= dfixed_mul(bandwidth
, dram_efficiency
);
942 return dfixed_trunc(bandwidth
);
946 * dce_v11_0_dram_bandwidth_for_display - get the dram bandwidth for display
948 * @wm: watermark calculation data
950 * Calculate the dram bandwidth used for display (CIK).
951 * Used for display watermark bandwidth calculations
952 * Returns the dram bandwidth for display in MBytes/s
954 static u32
dce_v11_0_dram_bandwidth_for_display(struct dce10_wm_params
*wm
)
956 /* Calculate DRAM Bandwidth and the part allocated to display. */
957 fixed20_12 disp_dram_allocation
; /* 0.3 to 0.7 */
958 fixed20_12 yclk
, dram_channels
, bandwidth
;
961 a
.full
= dfixed_const(1000);
962 yclk
.full
= dfixed_const(wm
->yclk
);
963 yclk
.full
= dfixed_div(yclk
, a
);
964 dram_channels
.full
= dfixed_const(wm
->dram_channels
* 4);
965 a
.full
= dfixed_const(10);
966 disp_dram_allocation
.full
= dfixed_const(3); /* XXX worse case value 0.3 */
967 disp_dram_allocation
.full
= dfixed_div(disp_dram_allocation
, a
);
968 bandwidth
.full
= dfixed_mul(dram_channels
, yclk
);
969 bandwidth
.full
= dfixed_mul(bandwidth
, disp_dram_allocation
);
971 return dfixed_trunc(bandwidth
);
975 * dce_v11_0_data_return_bandwidth - get the data return bandwidth
977 * @wm: watermark calculation data
979 * Calculate the data return bandwidth used for display (CIK).
980 * Used for display watermark bandwidth calculations
981 * Returns the data return bandwidth in MBytes/s
983 static u32
dce_v11_0_data_return_bandwidth(struct dce10_wm_params
*wm
)
985 /* Calculate the display Data return Bandwidth */
986 fixed20_12 return_efficiency
; /* 0.8 */
987 fixed20_12 sclk
, bandwidth
;
990 a
.full
= dfixed_const(1000);
991 sclk
.full
= dfixed_const(wm
->sclk
);
992 sclk
.full
= dfixed_div(sclk
, a
);
993 a
.full
= dfixed_const(10);
994 return_efficiency
.full
= dfixed_const(8);
995 return_efficiency
.full
= dfixed_div(return_efficiency
, a
);
996 a
.full
= dfixed_const(32);
997 bandwidth
.full
= dfixed_mul(a
, sclk
);
998 bandwidth
.full
= dfixed_mul(bandwidth
, return_efficiency
);
1000 return dfixed_trunc(bandwidth
);
1004 * dce_v11_0_dmif_request_bandwidth - get the dmif bandwidth
1006 * @wm: watermark calculation data
1008 * Calculate the dmif bandwidth used for display (CIK).
1009 * Used for display watermark bandwidth calculations
1010 * Returns the dmif bandwidth in MBytes/s
1012 static u32
dce_v11_0_dmif_request_bandwidth(struct dce10_wm_params
*wm
)
1014 /* Calculate the DMIF Request Bandwidth */
1015 fixed20_12 disp_clk_request_efficiency
; /* 0.8 */
1016 fixed20_12 disp_clk
, bandwidth
;
1019 a
.full
= dfixed_const(1000);
1020 disp_clk
.full
= dfixed_const(wm
->disp_clk
);
1021 disp_clk
.full
= dfixed_div(disp_clk
, a
);
1022 a
.full
= dfixed_const(32);
1023 b
.full
= dfixed_mul(a
, disp_clk
);
1025 a
.full
= dfixed_const(10);
1026 disp_clk_request_efficiency
.full
= dfixed_const(8);
1027 disp_clk_request_efficiency
.full
= dfixed_div(disp_clk_request_efficiency
, a
);
1029 bandwidth
.full
= dfixed_mul(b
, disp_clk_request_efficiency
);
1031 return dfixed_trunc(bandwidth
);
1035 * dce_v11_0_available_bandwidth - get the min available bandwidth
1037 * @wm: watermark calculation data
1039 * Calculate the min available bandwidth used for display (CIK).
1040 * Used for display watermark bandwidth calculations
1041 * Returns the min available bandwidth in MBytes/s
1043 static u32
dce_v11_0_available_bandwidth(struct dce10_wm_params
*wm
)
1045 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
1046 u32 dram_bandwidth
= dce_v11_0_dram_bandwidth(wm
);
1047 u32 data_return_bandwidth
= dce_v11_0_data_return_bandwidth(wm
);
1048 u32 dmif_req_bandwidth
= dce_v11_0_dmif_request_bandwidth(wm
);
1050 return min(dram_bandwidth
, min(data_return_bandwidth
, dmif_req_bandwidth
));
1054 * dce_v11_0_average_bandwidth - get the average available bandwidth
1056 * @wm: watermark calculation data
1058 * Calculate the average available bandwidth used for display (CIK).
1059 * Used for display watermark bandwidth calculations
1060 * Returns the average available bandwidth in MBytes/s
1062 static u32
dce_v11_0_average_bandwidth(struct dce10_wm_params
*wm
)
1064 /* Calculate the display mode Average Bandwidth
1065 * DisplayMode should contain the source and destination dimensions,
1069 fixed20_12 line_time
;
1070 fixed20_12 src_width
;
1071 fixed20_12 bandwidth
;
1074 a
.full
= dfixed_const(1000);
1075 line_time
.full
= dfixed_const(wm
->active_time
+ wm
->blank_time
);
1076 line_time
.full
= dfixed_div(line_time
, a
);
1077 bpp
.full
= dfixed_const(wm
->bytes_per_pixel
);
1078 src_width
.full
= dfixed_const(wm
->src_width
);
1079 bandwidth
.full
= dfixed_mul(src_width
, bpp
);
1080 bandwidth
.full
= dfixed_mul(bandwidth
, wm
->vsc
);
1081 bandwidth
.full
= dfixed_div(bandwidth
, line_time
);
1083 return dfixed_trunc(bandwidth
);
1087 * dce_v11_0_latency_watermark - get the latency watermark
1089 * @wm: watermark calculation data
1091 * Calculate the latency watermark (CIK).
1092 * Used for display watermark bandwidth calculations
1093 * Returns the latency watermark in ns
1095 static u32
dce_v11_0_latency_watermark(struct dce10_wm_params
*wm
)
1097 /* First calculate the latency in ns */
1098 u32 mc_latency
= 2000; /* 2000 ns. */
1099 u32 available_bandwidth
= dce_v11_0_available_bandwidth(wm
);
1100 u32 worst_chunk_return_time
= (512 * 8 * 1000) / available_bandwidth
;
1101 u32 cursor_line_pair_return_time
= (128 * 4 * 1000) / available_bandwidth
;
1102 u32 dc_latency
= 40000000 / wm
->disp_clk
; /* dc pipe latency */
1103 u32 other_heads_data_return_time
= ((wm
->num_heads
+ 1) * worst_chunk_return_time
) +
1104 (wm
->num_heads
* cursor_line_pair_return_time
);
1105 u32 latency
= mc_latency
+ other_heads_data_return_time
+ dc_latency
;
1106 u32 max_src_lines_per_dst_line
, lb_fill_bw
, line_fill_time
;
1107 u32 tmp
, dmif_size
= 12288;
1110 if (wm
->num_heads
== 0)
1113 a
.full
= dfixed_const(2);
1114 b
.full
= dfixed_const(1);
1115 if ((wm
->vsc
.full
> a
.full
) ||
1116 ((wm
->vsc
.full
> b
.full
) && (wm
->vtaps
>= 3)) ||
1118 ((wm
->vsc
.full
>= a
.full
) && wm
->interlaced
))
1119 max_src_lines_per_dst_line
= 4;
1121 max_src_lines_per_dst_line
= 2;
1123 a
.full
= dfixed_const(available_bandwidth
);
1124 b
.full
= dfixed_const(wm
->num_heads
);
1125 a
.full
= dfixed_div(a
, b
);
1127 b
.full
= dfixed_const(mc_latency
+ 512);
1128 c
.full
= dfixed_const(wm
->disp_clk
);
1129 b
.full
= dfixed_div(b
, c
);
1131 c
.full
= dfixed_const(dmif_size
);
1132 b
.full
= dfixed_div(c
, b
);
1134 tmp
= min(dfixed_trunc(a
), dfixed_trunc(b
));
1136 b
.full
= dfixed_const(1000);
1137 c
.full
= dfixed_const(wm
->disp_clk
);
1138 b
.full
= dfixed_div(c
, b
);
1139 c
.full
= dfixed_const(wm
->bytes_per_pixel
);
1140 b
.full
= dfixed_mul(b
, c
);
1142 lb_fill_bw
= min(tmp
, dfixed_trunc(b
));
1144 a
.full
= dfixed_const(max_src_lines_per_dst_line
* wm
->src_width
* wm
->bytes_per_pixel
);
1145 b
.full
= dfixed_const(1000);
1146 c
.full
= dfixed_const(lb_fill_bw
);
1147 b
.full
= dfixed_div(c
, b
);
1148 a
.full
= dfixed_div(a
, b
);
1149 line_fill_time
= dfixed_trunc(a
);
1151 if (line_fill_time
< wm
->active_time
)
1154 return latency
+ (line_fill_time
- wm
->active_time
);
1159 * dce_v11_0_average_bandwidth_vs_dram_bandwidth_for_display - check
1160 * average and available dram bandwidth
1162 * @wm: watermark calculation data
1164 * Check if the display average bandwidth fits in the display
1165 * dram bandwidth (CIK).
1166 * Used for display watermark bandwidth calculations
1167 * Returns true if the display fits, false if not.
1169 static bool dce_v11_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce10_wm_params
*wm
)
1171 if (dce_v11_0_average_bandwidth(wm
) <=
1172 (dce_v11_0_dram_bandwidth_for_display(wm
) / wm
->num_heads
))
1179 * dce_v11_0_average_bandwidth_vs_available_bandwidth - check
1180 * average and available bandwidth
1182 * @wm: watermark calculation data
1184 * Check if the display average bandwidth fits in the display
1185 * available bandwidth (CIK).
1186 * Used for display watermark bandwidth calculations
1187 * Returns true if the display fits, false if not.
1189 static bool dce_v11_0_average_bandwidth_vs_available_bandwidth(struct dce10_wm_params
*wm
)
1191 if (dce_v11_0_average_bandwidth(wm
) <=
1192 (dce_v11_0_available_bandwidth(wm
) / wm
->num_heads
))
1199 * dce_v11_0_check_latency_hiding - check latency hiding
1201 * @wm: watermark calculation data
1203 * Check latency hiding (CIK).
1204 * Used for display watermark bandwidth calculations
1205 * Returns true if the display fits, false if not.
1207 static bool dce_v11_0_check_latency_hiding(struct dce10_wm_params
*wm
)
1209 u32 lb_partitions
= wm
->lb_size
/ wm
->src_width
;
1210 u32 line_time
= wm
->active_time
+ wm
->blank_time
;
1211 u32 latency_tolerant_lines
;
1215 a
.full
= dfixed_const(1);
1216 if (wm
->vsc
.full
> a
.full
)
1217 latency_tolerant_lines
= 1;
1219 if (lb_partitions
<= (wm
->vtaps
+ 1))
1220 latency_tolerant_lines
= 1;
1222 latency_tolerant_lines
= 2;
1225 latency_hiding
= (latency_tolerant_lines
* line_time
+ wm
->blank_time
);
1227 if (dce_v11_0_latency_watermark(wm
) <= latency_hiding
)
1234 * dce_v11_0_program_watermarks - program display watermarks
1236 * @adev: amdgpu_device pointer
1237 * @amdgpu_crtc: the selected display controller
1238 * @lb_size: line buffer size
1239 * @num_heads: number of display controllers in use
1241 * Calculate and program the display watermarks for the
1242 * selected display controller (CIK).
1244 static void dce_v11_0_program_watermarks(struct amdgpu_device
*adev
,
1245 struct amdgpu_crtc
*amdgpu_crtc
,
1246 u32 lb_size
, u32 num_heads
)
1248 struct drm_display_mode
*mode
= &amdgpu_crtc
->base
.mode
;
1249 struct dce10_wm_params wm_low
, wm_high
;
1252 u32 latency_watermark_a
= 0, latency_watermark_b
= 0;
1255 if (amdgpu_crtc
->base
.enabled
&& num_heads
&& mode
) {
1256 pixel_period
= 1000000 / (u32
)mode
->clock
;
1257 line_time
= min((u32
)mode
->crtc_htotal
* pixel_period
, (u32
)65535);
1259 /* watermark for high clocks */
1260 if (adev
->pm
.dpm_enabled
) {
1262 amdgpu_dpm_get_mclk(adev
, false) * 10;
1264 amdgpu_dpm_get_sclk(adev
, false) * 10;
1266 wm_high
.yclk
= adev
->pm
.current_mclk
* 10;
1267 wm_high
.sclk
= adev
->pm
.current_sclk
* 10;
1270 wm_high
.disp_clk
= mode
->clock
;
1271 wm_high
.src_width
= mode
->crtc_hdisplay
;
1272 wm_high
.active_time
= mode
->crtc_hdisplay
* pixel_period
;
1273 wm_high
.blank_time
= line_time
- wm_high
.active_time
;
1274 wm_high
.interlaced
= false;
1275 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1276 wm_high
.interlaced
= true;
1277 wm_high
.vsc
= amdgpu_crtc
->vsc
;
1279 if (amdgpu_crtc
->rmx_type
!= RMX_OFF
)
1281 wm_high
.bytes_per_pixel
= 4; /* XXX: get this from fb config */
1282 wm_high
.lb_size
= lb_size
;
1283 wm_high
.dram_channels
= cik_get_number_of_dram_channels(adev
);
1284 wm_high
.num_heads
= num_heads
;
1286 /* set for high clocks */
1287 latency_watermark_a
= min(dce_v11_0_latency_watermark(&wm_high
), (u32
)65535);
1289 /* possibly force display priority to high */
1290 /* should really do this at mode validation time... */
1291 if (!dce_v11_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high
) ||
1292 !dce_v11_0_average_bandwidth_vs_available_bandwidth(&wm_high
) ||
1293 !dce_v11_0_check_latency_hiding(&wm_high
) ||
1294 (adev
->mode_info
.disp_priority
== 2)) {
1295 DRM_DEBUG_KMS("force priority to high\n");
1298 /* watermark for low clocks */
1299 if (adev
->pm
.dpm_enabled
) {
1301 amdgpu_dpm_get_mclk(adev
, true) * 10;
1303 amdgpu_dpm_get_sclk(adev
, true) * 10;
1305 wm_low
.yclk
= adev
->pm
.current_mclk
* 10;
1306 wm_low
.sclk
= adev
->pm
.current_sclk
* 10;
1309 wm_low
.disp_clk
= mode
->clock
;
1310 wm_low
.src_width
= mode
->crtc_hdisplay
;
1311 wm_low
.active_time
= mode
->crtc_hdisplay
* pixel_period
;
1312 wm_low
.blank_time
= line_time
- wm_low
.active_time
;
1313 wm_low
.interlaced
= false;
1314 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1315 wm_low
.interlaced
= true;
1316 wm_low
.vsc
= amdgpu_crtc
->vsc
;
1318 if (amdgpu_crtc
->rmx_type
!= RMX_OFF
)
1320 wm_low
.bytes_per_pixel
= 4; /* XXX: get this from fb config */
1321 wm_low
.lb_size
= lb_size
;
1322 wm_low
.dram_channels
= cik_get_number_of_dram_channels(adev
);
1323 wm_low
.num_heads
= num_heads
;
1325 /* set for low clocks */
1326 latency_watermark_b
= min(dce_v11_0_latency_watermark(&wm_low
), (u32
)65535);
1328 /* possibly force display priority to high */
1329 /* should really do this at mode validation time... */
1330 if (!dce_v11_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low
) ||
1331 !dce_v11_0_average_bandwidth_vs_available_bandwidth(&wm_low
) ||
1332 !dce_v11_0_check_latency_hiding(&wm_low
) ||
1333 (adev
->mode_info
.disp_priority
== 2)) {
1334 DRM_DEBUG_KMS("force priority to high\n");
1339 wm_mask
= RREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
);
1340 tmp
= REG_SET_FIELD(wm_mask
, DPG_WATERMARK_MASK_CONTROL
, URGENCY_WATERMARK_MASK
, 1);
1341 WREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
1342 tmp
= RREG32(mmDPG_PIPE_URGENCY_CONTROL
+ amdgpu_crtc
->crtc_offset
);
1343 tmp
= REG_SET_FIELD(tmp
, DPG_PIPE_URGENCY_CONTROL
, URGENCY_LOW_WATERMARK
, latency_watermark_a
);
1344 tmp
= REG_SET_FIELD(tmp
, DPG_PIPE_URGENCY_CONTROL
, URGENCY_HIGH_WATERMARK
, line_time
);
1345 WREG32(mmDPG_PIPE_URGENCY_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
1347 tmp
= REG_SET_FIELD(wm_mask
, DPG_WATERMARK_MASK_CONTROL
, URGENCY_WATERMARK_MASK
, 2);
1348 WREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
1349 tmp
= RREG32(mmDPG_PIPE_URGENCY_CONTROL
+ amdgpu_crtc
->crtc_offset
);
1350 tmp
= REG_SET_FIELD(tmp
, DPG_PIPE_URGENCY_CONTROL
, URGENCY_LOW_WATERMARK
, latency_watermark_b
);
1351 tmp
= REG_SET_FIELD(tmp
, DPG_PIPE_URGENCY_CONTROL
, URGENCY_HIGH_WATERMARK
, line_time
);
1352 WREG32(mmDPG_PIPE_URGENCY_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
1353 /* restore original selection */
1354 WREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
, wm_mask
);
1356 /* save values for DPM */
1357 amdgpu_crtc
->line_time
= line_time
;
1358 amdgpu_crtc
->wm_high
= latency_watermark_a
;
1359 amdgpu_crtc
->wm_low
= latency_watermark_b
;
1363 * dce_v11_0_bandwidth_update - program display watermarks
1365 * @adev: amdgpu_device pointer
1367 * Calculate and program the display watermarks and line
1368 * buffer allocation (CIK).
1370 static void dce_v11_0_bandwidth_update(struct amdgpu_device
*adev
)
1372 struct drm_display_mode
*mode
= NULL
;
1373 u32 num_heads
= 0, lb_size
;
1376 amdgpu_update_display_priority(adev
);
1378 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
1379 if (adev
->mode_info
.crtcs
[i
]->base
.enabled
)
1382 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
1383 mode
= &adev
->mode_info
.crtcs
[i
]->base
.mode
;
1384 lb_size
= dce_v11_0_line_buffer_adjust(adev
, adev
->mode_info
.crtcs
[i
], mode
);
1385 dce_v11_0_program_watermarks(adev
, adev
->mode_info
.crtcs
[i
],
1386 lb_size
, num_heads
);
1390 static void dce_v11_0_audio_get_connected_pins(struct amdgpu_device
*adev
)
1395 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
1396 offset
= adev
->mode_info
.audio
.pin
[i
].offset
;
1397 tmp
= RREG32_AUDIO_ENDPT(offset
,
1398 ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT
);
1400 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY_MASK
) >>
1401 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY__SHIFT
) == 1)
1402 adev
->mode_info
.audio
.pin
[i
].connected
= false;
1404 adev
->mode_info
.audio
.pin
[i
].connected
= true;
1408 static struct amdgpu_audio_pin
*dce_v11_0_audio_get_pin(struct amdgpu_device
*adev
)
1412 dce_v11_0_audio_get_connected_pins(adev
);
1414 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
1415 if (adev
->mode_info
.audio
.pin
[i
].connected
)
1416 return &adev
->mode_info
.audio
.pin
[i
];
1418 DRM_ERROR("No connected audio pins found!\n");
1422 static void dce_v11_0_afmt_audio_select_pin(struct drm_encoder
*encoder
)
1424 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
1425 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1426 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1429 if (!dig
|| !dig
->afmt
|| !dig
->afmt
->pin
)
1432 tmp
= RREG32(mmAFMT_AUDIO_SRC_CONTROL
+ dig
->afmt
->offset
);
1433 tmp
= REG_SET_FIELD(tmp
, AFMT_AUDIO_SRC_CONTROL
, AFMT_AUDIO_SRC_SELECT
, dig
->afmt
->pin
->id
);
1434 WREG32(mmAFMT_AUDIO_SRC_CONTROL
+ dig
->afmt
->offset
, tmp
);
1437 static void dce_v11_0_audio_write_latency_fields(struct drm_encoder
*encoder
,
1438 struct drm_display_mode
*mode
)
1440 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
1441 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1442 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1443 struct drm_connector
*connector
;
1444 struct amdgpu_connector
*amdgpu_connector
= NULL
;
1448 if (!dig
|| !dig
->afmt
|| !dig
->afmt
->pin
)
1451 list_for_each_entry(connector
, &encoder
->dev
->mode_config
.connector_list
, head
) {
1452 if (connector
->encoder
== encoder
) {
1453 amdgpu_connector
= to_amdgpu_connector(connector
);
1458 if (!amdgpu_connector
) {
1459 DRM_ERROR("Couldn't find encoder's connector\n");
1463 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1465 if (connector
->latency_present
[interlace
]) {
1466 tmp
= REG_SET_FIELD(0, AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC
,
1467 VIDEO_LIPSYNC
, connector
->video_latency
[interlace
]);
1468 tmp
= REG_SET_FIELD(0, AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC
,
1469 AUDIO_LIPSYNC
, connector
->audio_latency
[interlace
]);
1471 tmp
= REG_SET_FIELD(0, AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC
,
1473 tmp
= REG_SET_FIELD(0, AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC
,
1476 WREG32_AUDIO_ENDPT(dig
->afmt
->pin
->offset
,
1477 ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC
, tmp
);
1480 static void dce_v11_0_audio_write_speaker_allocation(struct drm_encoder
*encoder
)
1482 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
1483 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1484 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1485 struct drm_connector
*connector
;
1486 struct amdgpu_connector
*amdgpu_connector
= NULL
;
1491 if (!dig
|| !dig
->afmt
|| !dig
->afmt
->pin
)
1494 list_for_each_entry(connector
, &encoder
->dev
->mode_config
.connector_list
, head
) {
1495 if (connector
->encoder
== encoder
) {
1496 amdgpu_connector
= to_amdgpu_connector(connector
);
1501 if (!amdgpu_connector
) {
1502 DRM_ERROR("Couldn't find encoder's connector\n");
1506 sad_count
= drm_edid_to_speaker_allocation(amdgpu_connector_edid(connector
), &sadb
);
1507 if (sad_count
< 0) {
1508 DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count
);
1512 /* program the speaker allocation */
1513 tmp
= RREG32_AUDIO_ENDPT(dig
->afmt
->pin
->offset
,
1514 ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER
);
1515 tmp
= REG_SET_FIELD(tmp
, AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER
,
1518 tmp
= REG_SET_FIELD(tmp
, AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER
,
1519 HDMI_CONNECTION
, 1);
1521 tmp
= REG_SET_FIELD(tmp
, AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER
,
1522 SPEAKER_ALLOCATION
, sadb
[0]);
1524 tmp
= REG_SET_FIELD(tmp
, AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER
,
1525 SPEAKER_ALLOCATION
, 5); /* stereo */
1526 WREG32_AUDIO_ENDPT(dig
->afmt
->pin
->offset
,
1527 ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER
, tmp
);
1532 static void dce_v11_0_audio_write_sad_regs(struct drm_encoder
*encoder
)
1534 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
1535 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1536 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1537 struct drm_connector
*connector
;
1538 struct amdgpu_connector
*amdgpu_connector
= NULL
;
1539 struct cea_sad
*sads
;
1542 static const u16 eld_reg_to_type
[][2] = {
1543 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0
, HDMI_AUDIO_CODING_TYPE_PCM
},
1544 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR1
, HDMI_AUDIO_CODING_TYPE_AC3
},
1545 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR2
, HDMI_AUDIO_CODING_TYPE_MPEG1
},
1546 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR3
, HDMI_AUDIO_CODING_TYPE_MP3
},
1547 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR4
, HDMI_AUDIO_CODING_TYPE_MPEG2
},
1548 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR5
, HDMI_AUDIO_CODING_TYPE_AAC_LC
},
1549 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR6
, HDMI_AUDIO_CODING_TYPE_DTS
},
1550 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR7
, HDMI_AUDIO_CODING_TYPE_ATRAC
},
1551 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR9
, HDMI_AUDIO_CODING_TYPE_EAC3
},
1552 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR10
, HDMI_AUDIO_CODING_TYPE_DTS_HD
},
1553 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR11
, HDMI_AUDIO_CODING_TYPE_MLP
},
1554 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR13
, HDMI_AUDIO_CODING_TYPE_WMA_PRO
},
1557 if (!dig
|| !dig
->afmt
|| !dig
->afmt
->pin
)
1560 list_for_each_entry(connector
, &encoder
->dev
->mode_config
.connector_list
, head
) {
1561 if (connector
->encoder
== encoder
) {
1562 amdgpu_connector
= to_amdgpu_connector(connector
);
1567 if (!amdgpu_connector
) {
1568 DRM_ERROR("Couldn't find encoder's connector\n");
1572 sad_count
= drm_edid_to_sad(amdgpu_connector_edid(connector
), &sads
);
1573 if (sad_count
<= 0) {
1574 DRM_ERROR("Couldn't read SADs: %d\n", sad_count
);
1579 for (i
= 0; i
< ARRAY_SIZE(eld_reg_to_type
); i
++) {
1581 u8 stereo_freqs
= 0;
1582 int max_channels
= -1;
1585 for (j
= 0; j
< sad_count
; j
++) {
1586 struct cea_sad
*sad
= &sads
[j
];
1588 if (sad
->format
== eld_reg_to_type
[i
][1]) {
1589 if (sad
->channels
> max_channels
) {
1590 tmp
= REG_SET_FIELD(tmp
, AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0
,
1591 MAX_CHANNELS
, sad
->channels
);
1592 tmp
= REG_SET_FIELD(tmp
, AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0
,
1593 DESCRIPTOR_BYTE_2
, sad
->byte2
);
1594 tmp
= REG_SET_FIELD(tmp
, AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0
,
1595 SUPPORTED_FREQUENCIES
, sad
->freq
);
1596 max_channels
= sad
->channels
;
1599 if (sad
->format
== HDMI_AUDIO_CODING_TYPE_PCM
)
1600 stereo_freqs
|= sad
->freq
;
1606 tmp
= REG_SET_FIELD(tmp
, AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0
,
1607 SUPPORTED_FREQUENCIES_STEREO
, stereo_freqs
);
1608 WREG32_AUDIO_ENDPT(dig
->afmt
->pin
->offset
, eld_reg_to_type
[i
][0], tmp
);
1614 static void dce_v11_0_audio_enable(struct amdgpu_device
*adev
,
1615 struct amdgpu_audio_pin
*pin
,
1621 WREG32_AUDIO_ENDPT(pin
->offset
, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL
,
1622 enable
? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK
: 0);
1625 static const u32 pin_offsets
[] =
1627 AUD0_REGISTER_OFFSET
,
1628 AUD1_REGISTER_OFFSET
,
1629 AUD2_REGISTER_OFFSET
,
1630 AUD3_REGISTER_OFFSET
,
1631 AUD4_REGISTER_OFFSET
,
1632 AUD5_REGISTER_OFFSET
,
1633 AUD6_REGISTER_OFFSET
,
1636 static int dce_v11_0_audio_init(struct amdgpu_device
*adev
)
1643 adev
->mode_info
.audio
.enabled
= true;
1645 adev
->mode_info
.audio
.num_pins
= 7;
1647 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
1648 adev
->mode_info
.audio
.pin
[i
].channels
= -1;
1649 adev
->mode_info
.audio
.pin
[i
].rate
= -1;
1650 adev
->mode_info
.audio
.pin
[i
].bits_per_sample
= -1;
1651 adev
->mode_info
.audio
.pin
[i
].status_bits
= 0;
1652 adev
->mode_info
.audio
.pin
[i
].category_code
= 0;
1653 adev
->mode_info
.audio
.pin
[i
].connected
= false;
1654 adev
->mode_info
.audio
.pin
[i
].offset
= pin_offsets
[i
];
1655 adev
->mode_info
.audio
.pin
[i
].id
= i
;
1656 /* disable audio. it will be set up later */
1657 /* XXX remove once we switch to ip funcs */
1658 dce_v11_0_audio_enable(adev
, &adev
->mode_info
.audio
.pin
[i
], false);
1664 static void dce_v11_0_audio_fini(struct amdgpu_device
*adev
)
1668 if (!adev
->mode_info
.audio
.enabled
)
1671 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++)
1672 dce_v11_0_audio_enable(adev
, &adev
->mode_info
.audio
.pin
[i
], false);
1674 adev
->mode_info
.audio
.enabled
= false;
1678 * update the N and CTS parameters for a given pixel clock rate
1680 static void dce_v11_0_afmt_update_ACR(struct drm_encoder
*encoder
, uint32_t clock
)
1682 struct drm_device
*dev
= encoder
->dev
;
1683 struct amdgpu_device
*adev
= dev
->dev_private
;
1684 struct amdgpu_afmt_acr acr
= amdgpu_afmt_acr(clock
);
1685 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1686 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1689 tmp
= RREG32(mmHDMI_ACR_32_0
+ dig
->afmt
->offset
);
1690 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_32_0
, HDMI_ACR_CTS_32
, acr
.cts_32khz
);
1691 WREG32(mmHDMI_ACR_32_0
+ dig
->afmt
->offset
, tmp
);
1692 tmp
= RREG32(mmHDMI_ACR_32_1
+ dig
->afmt
->offset
);
1693 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_32_1
, HDMI_ACR_N_32
, acr
.n_32khz
);
1694 WREG32(mmHDMI_ACR_32_1
+ dig
->afmt
->offset
, tmp
);
1696 tmp
= RREG32(mmHDMI_ACR_44_0
+ dig
->afmt
->offset
);
1697 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_44_0
, HDMI_ACR_CTS_44
, acr
.cts_44_1khz
);
1698 WREG32(mmHDMI_ACR_44_0
+ dig
->afmt
->offset
, tmp
);
1699 tmp
= RREG32(mmHDMI_ACR_44_1
+ dig
->afmt
->offset
);
1700 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_44_1
, HDMI_ACR_N_44
, acr
.n_44_1khz
);
1701 WREG32(mmHDMI_ACR_44_1
+ dig
->afmt
->offset
, tmp
);
1703 tmp
= RREG32(mmHDMI_ACR_48_0
+ dig
->afmt
->offset
);
1704 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_48_0
, HDMI_ACR_CTS_48
, acr
.cts_48khz
);
1705 WREG32(mmHDMI_ACR_48_0
+ dig
->afmt
->offset
, tmp
);
1706 tmp
= RREG32(mmHDMI_ACR_48_1
+ dig
->afmt
->offset
);
1707 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_48_1
, HDMI_ACR_N_48
, acr
.n_48khz
);
1708 WREG32(mmHDMI_ACR_48_1
+ dig
->afmt
->offset
, tmp
);
1713 * build a HDMI Video Info Frame
1715 static void dce_v11_0_afmt_update_avi_infoframe(struct drm_encoder
*encoder
,
1716 void *buffer
, size_t size
)
1718 struct drm_device
*dev
= encoder
->dev
;
1719 struct amdgpu_device
*adev
= dev
->dev_private
;
1720 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1721 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1722 uint8_t *frame
= buffer
+ 3;
1723 uint8_t *header
= buffer
;
1725 WREG32(mmAFMT_AVI_INFO0
+ dig
->afmt
->offset
,
1726 frame
[0x0] | (frame
[0x1] << 8) | (frame
[0x2] << 16) | (frame
[0x3] << 24));
1727 WREG32(mmAFMT_AVI_INFO1
+ dig
->afmt
->offset
,
1728 frame
[0x4] | (frame
[0x5] << 8) | (frame
[0x6] << 16) | (frame
[0x7] << 24));
1729 WREG32(mmAFMT_AVI_INFO2
+ dig
->afmt
->offset
,
1730 frame
[0x8] | (frame
[0x9] << 8) | (frame
[0xA] << 16) | (frame
[0xB] << 24));
1731 WREG32(mmAFMT_AVI_INFO3
+ dig
->afmt
->offset
,
1732 frame
[0xC] | (frame
[0xD] << 8) | (header
[1] << 24));
1735 static void dce_v11_0_audio_set_dto(struct drm_encoder
*encoder
, u32 clock
)
1737 struct drm_device
*dev
= encoder
->dev
;
1738 struct amdgpu_device
*adev
= dev
->dev_private
;
1739 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1740 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1741 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(encoder
->crtc
);
1742 u32 dto_phase
= 24 * 1000;
1743 u32 dto_modulo
= clock
;
1746 if (!dig
|| !dig
->afmt
)
1749 /* XXX two dtos; generally use dto0 for hdmi */
1750 /* Express [24MHz / target pixel clock] as an exact rational
1751 * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
1752 * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
1754 tmp
= RREG32(mmDCCG_AUDIO_DTO_SOURCE
);
1755 tmp
= REG_SET_FIELD(tmp
, DCCG_AUDIO_DTO_SOURCE
, DCCG_AUDIO_DTO0_SOURCE_SEL
,
1756 amdgpu_crtc
->crtc_id
);
1757 WREG32(mmDCCG_AUDIO_DTO_SOURCE
, tmp
);
1758 WREG32(mmDCCG_AUDIO_DTO0_PHASE
, dto_phase
);
1759 WREG32(mmDCCG_AUDIO_DTO0_MODULE
, dto_modulo
);
1763 * update the info frames with the data from the current display mode
1765 static void dce_v11_0_afmt_setmode(struct drm_encoder
*encoder
,
1766 struct drm_display_mode
*mode
)
1768 struct drm_device
*dev
= encoder
->dev
;
1769 struct amdgpu_device
*adev
= dev
->dev_private
;
1770 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1771 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1772 struct drm_connector
*connector
= amdgpu_get_connector_for_encoder(encoder
);
1773 u8 buffer
[HDMI_INFOFRAME_HEADER_SIZE
+ HDMI_AVI_INFOFRAME_SIZE
];
1774 struct hdmi_avi_infoframe frame
;
1779 if (!dig
|| !dig
->afmt
)
1782 /* Silent, r600_hdmi_enable will raise WARN for us */
1783 if (!dig
->afmt
->enabled
)
1786 /* hdmi deep color mode general control packets setup, if bpc > 8 */
1787 if (encoder
->crtc
) {
1788 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(encoder
->crtc
);
1789 bpc
= amdgpu_crtc
->bpc
;
1792 /* disable audio prior to setting up hw */
1793 dig
->afmt
->pin
= dce_v11_0_audio_get_pin(adev
);
1794 dce_v11_0_audio_enable(adev
, dig
->afmt
->pin
, false);
1796 dce_v11_0_audio_set_dto(encoder
, mode
->clock
);
1798 tmp
= RREG32(mmHDMI_VBI_PACKET_CONTROL
+ dig
->afmt
->offset
);
1799 tmp
= REG_SET_FIELD(tmp
, HDMI_VBI_PACKET_CONTROL
, HDMI_NULL_SEND
, 1);
1800 WREG32(mmHDMI_VBI_PACKET_CONTROL
+ dig
->afmt
->offset
, tmp
); /* send null packets when required */
1802 WREG32(mmAFMT_AUDIO_CRC_CONTROL
+ dig
->afmt
->offset
, 0x1000);
1804 tmp
= RREG32(mmHDMI_CONTROL
+ dig
->afmt
->offset
);
1811 tmp
= REG_SET_FIELD(tmp
, HDMI_CONTROL
, HDMI_DEEP_COLOR_ENABLE
, 0);
1812 tmp
= REG_SET_FIELD(tmp
, HDMI_CONTROL
, HDMI_DEEP_COLOR_DEPTH
, 0);
1813 DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n",
1814 connector
->name
, bpc
);
1817 tmp
= REG_SET_FIELD(tmp
, HDMI_CONTROL
, HDMI_DEEP_COLOR_ENABLE
, 1);
1818 tmp
= REG_SET_FIELD(tmp
, HDMI_CONTROL
, HDMI_DEEP_COLOR_DEPTH
, 1);
1819 DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n",
1823 tmp
= REG_SET_FIELD(tmp
, HDMI_CONTROL
, HDMI_DEEP_COLOR_ENABLE
, 1);
1824 tmp
= REG_SET_FIELD(tmp
, HDMI_CONTROL
, HDMI_DEEP_COLOR_DEPTH
, 2);
1825 DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n",
1829 WREG32(mmHDMI_CONTROL
+ dig
->afmt
->offset
, tmp
);
1831 tmp
= RREG32(mmHDMI_VBI_PACKET_CONTROL
+ dig
->afmt
->offset
);
1832 tmp
= REG_SET_FIELD(tmp
, HDMI_VBI_PACKET_CONTROL
, HDMI_NULL_SEND
, 1); /* send null packets when required */
1833 tmp
= REG_SET_FIELD(tmp
, HDMI_VBI_PACKET_CONTROL
, HDMI_GC_SEND
, 1); /* send general control packets */
1834 tmp
= REG_SET_FIELD(tmp
, HDMI_VBI_PACKET_CONTROL
, HDMI_GC_CONT
, 1); /* send general control packets every frame */
1835 WREG32(mmHDMI_VBI_PACKET_CONTROL
+ dig
->afmt
->offset
, tmp
);
1837 tmp
= RREG32(mmHDMI_INFOFRAME_CONTROL0
+ dig
->afmt
->offset
);
1838 /* enable audio info frames (frames won't be set until audio is enabled) */
1839 tmp
= REG_SET_FIELD(tmp
, HDMI_INFOFRAME_CONTROL0
, HDMI_AUDIO_INFO_SEND
, 1);
1840 /* required for audio info values to be updated */
1841 tmp
= REG_SET_FIELD(tmp
, HDMI_INFOFRAME_CONTROL0
, HDMI_AUDIO_INFO_CONT
, 1);
1842 WREG32(mmHDMI_INFOFRAME_CONTROL0
+ dig
->afmt
->offset
, tmp
);
1844 tmp
= RREG32(mmAFMT_INFOFRAME_CONTROL0
+ dig
->afmt
->offset
);
1845 /* required for audio info values to be updated */
1846 tmp
= REG_SET_FIELD(tmp
, AFMT_INFOFRAME_CONTROL0
, AFMT_AUDIO_INFO_UPDATE
, 1);
1847 WREG32(mmAFMT_INFOFRAME_CONTROL0
+ dig
->afmt
->offset
, tmp
);
1849 tmp
= RREG32(mmHDMI_INFOFRAME_CONTROL1
+ dig
->afmt
->offset
);
1850 /* anything other than 0 */
1851 tmp
= REG_SET_FIELD(tmp
, HDMI_INFOFRAME_CONTROL1
, HDMI_AUDIO_INFO_LINE
, 2);
1852 WREG32(mmHDMI_INFOFRAME_CONTROL1
+ dig
->afmt
->offset
, tmp
);
1854 WREG32(mmHDMI_GC
+ dig
->afmt
->offset
, 0); /* unset HDMI_GC_AVMUTE */
1856 tmp
= RREG32(mmHDMI_AUDIO_PACKET_CONTROL
+ dig
->afmt
->offset
);
1857 /* set the default audio delay */
1858 tmp
= REG_SET_FIELD(tmp
, HDMI_AUDIO_PACKET_CONTROL
, HDMI_AUDIO_DELAY_EN
, 1);
1859 /* should be suffient for all audio modes and small enough for all hblanks */
1860 tmp
= REG_SET_FIELD(tmp
, HDMI_AUDIO_PACKET_CONTROL
, HDMI_AUDIO_PACKETS_PER_LINE
, 3);
1861 WREG32(mmHDMI_AUDIO_PACKET_CONTROL
+ dig
->afmt
->offset
, tmp
);
1863 tmp
= RREG32(mmAFMT_AUDIO_PACKET_CONTROL
+ dig
->afmt
->offset
);
1864 /* allow 60958 channel status fields to be updated */
1865 tmp
= REG_SET_FIELD(tmp
, AFMT_AUDIO_PACKET_CONTROL
, AFMT_60958_CS_UPDATE
, 1);
1866 WREG32(mmAFMT_AUDIO_PACKET_CONTROL
+ dig
->afmt
->offset
, tmp
);
1868 tmp
= RREG32(mmHDMI_ACR_PACKET_CONTROL
+ dig
->afmt
->offset
);
1870 /* clear SW CTS value */
1871 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_PACKET_CONTROL
, HDMI_ACR_SOURCE
, 0);
1873 /* select SW CTS value */
1874 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_PACKET_CONTROL
, HDMI_ACR_SOURCE
, 1);
1875 /* allow hw to sent ACR packets when required */
1876 tmp
= REG_SET_FIELD(tmp
, HDMI_ACR_PACKET_CONTROL
, HDMI_ACR_AUTO_SEND
, 1);
1877 WREG32(mmHDMI_ACR_PACKET_CONTROL
+ dig
->afmt
->offset
, tmp
);
1879 dce_v11_0_afmt_update_ACR(encoder
, mode
->clock
);
1881 tmp
= RREG32(mmAFMT_60958_0
+ dig
->afmt
->offset
);
1882 tmp
= REG_SET_FIELD(tmp
, AFMT_60958_0
, AFMT_60958_CS_CHANNEL_NUMBER_L
, 1);
1883 WREG32(mmAFMT_60958_0
+ dig
->afmt
->offset
, tmp
);
1885 tmp
= RREG32(mmAFMT_60958_1
+ dig
->afmt
->offset
);
1886 tmp
= REG_SET_FIELD(tmp
, AFMT_60958_1
, AFMT_60958_CS_CHANNEL_NUMBER_R
, 2);
1887 WREG32(mmAFMT_60958_1
+ dig
->afmt
->offset
, tmp
);
1889 tmp
= RREG32(mmAFMT_60958_2
+ dig
->afmt
->offset
);
1890 tmp
= REG_SET_FIELD(tmp
, AFMT_60958_2
, AFMT_60958_CS_CHANNEL_NUMBER_2
, 3);
1891 tmp
= REG_SET_FIELD(tmp
, AFMT_60958_2
, AFMT_60958_CS_CHANNEL_NUMBER_3
, 4);
1892 tmp
= REG_SET_FIELD(tmp
, AFMT_60958_2
, AFMT_60958_CS_CHANNEL_NUMBER_4
, 5);
1893 tmp
= REG_SET_FIELD(tmp
, AFMT_60958_2
, AFMT_60958_CS_CHANNEL_NUMBER_5
, 6);
1894 tmp
= REG_SET_FIELD(tmp
, AFMT_60958_2
, AFMT_60958_CS_CHANNEL_NUMBER_6
, 7);
1895 tmp
= REG_SET_FIELD(tmp
, AFMT_60958_2
, AFMT_60958_CS_CHANNEL_NUMBER_7
, 8);
1896 WREG32(mmAFMT_60958_2
+ dig
->afmt
->offset
, tmp
);
1898 dce_v11_0_audio_write_speaker_allocation(encoder
);
1900 WREG32(mmAFMT_AUDIO_PACKET_CONTROL2
+ dig
->afmt
->offset
,
1901 (0xff << AFMT_AUDIO_PACKET_CONTROL2__AFMT_AUDIO_CHANNEL_ENABLE__SHIFT
));
1903 dce_v11_0_afmt_audio_select_pin(encoder
);
1904 dce_v11_0_audio_write_sad_regs(encoder
);
1905 dce_v11_0_audio_write_latency_fields(encoder
, mode
);
1907 err
= drm_hdmi_avi_infoframe_from_display_mode(&frame
, mode
);
1909 DRM_ERROR("failed to setup AVI infoframe: %zd\n", err
);
1913 err
= hdmi_avi_infoframe_pack(&frame
, buffer
, sizeof(buffer
));
1915 DRM_ERROR("failed to pack AVI infoframe: %zd\n", err
);
1919 dce_v11_0_afmt_update_avi_infoframe(encoder
, buffer
, sizeof(buffer
));
1921 tmp
= RREG32(mmHDMI_INFOFRAME_CONTROL0
+ dig
->afmt
->offset
);
1922 /* enable AVI info frames */
1923 tmp
= REG_SET_FIELD(tmp
, HDMI_INFOFRAME_CONTROL0
, HDMI_AVI_INFO_SEND
, 1);
1924 /* required for audio info values to be updated */
1925 tmp
= REG_SET_FIELD(tmp
, HDMI_INFOFRAME_CONTROL0
, HDMI_AVI_INFO_CONT
, 1);
1926 WREG32(mmHDMI_INFOFRAME_CONTROL0
+ dig
->afmt
->offset
, tmp
);
1928 tmp
= RREG32(mmHDMI_INFOFRAME_CONTROL1
+ dig
->afmt
->offset
);
1929 tmp
= REG_SET_FIELD(tmp
, HDMI_INFOFRAME_CONTROL1
, HDMI_AVI_INFO_LINE
, 2);
1930 WREG32(mmHDMI_INFOFRAME_CONTROL1
+ dig
->afmt
->offset
, tmp
);
1932 tmp
= RREG32(mmAFMT_AUDIO_PACKET_CONTROL
+ dig
->afmt
->offset
);
1933 /* send audio packets */
1934 tmp
= REG_SET_FIELD(tmp
, AFMT_AUDIO_PACKET_CONTROL
, AFMT_AUDIO_SAMPLE_SEND
, 1);
1935 WREG32(mmAFMT_AUDIO_PACKET_CONTROL
+ dig
->afmt
->offset
, tmp
);
1937 WREG32(mmAFMT_RAMP_CONTROL0
+ dig
->afmt
->offset
, 0x00FFFFFF);
1938 WREG32(mmAFMT_RAMP_CONTROL1
+ dig
->afmt
->offset
, 0x007FFFFF);
1939 WREG32(mmAFMT_RAMP_CONTROL2
+ dig
->afmt
->offset
, 0x00000001);
1940 WREG32(mmAFMT_RAMP_CONTROL3
+ dig
->afmt
->offset
, 0x00000001);
1942 /* enable audio after to setting up hw */
1943 dce_v11_0_audio_enable(adev
, dig
->afmt
->pin
, true);
1946 static void dce_v11_0_afmt_enable(struct drm_encoder
*encoder
, bool enable
)
1948 struct drm_device
*dev
= encoder
->dev
;
1949 struct amdgpu_device
*adev
= dev
->dev_private
;
1950 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1951 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1953 if (!dig
|| !dig
->afmt
)
1956 /* Silent, r600_hdmi_enable will raise WARN for us */
1957 if (enable
&& dig
->afmt
->enabled
)
1959 if (!enable
&& !dig
->afmt
->enabled
)
1962 if (!enable
&& dig
->afmt
->pin
) {
1963 dce_v11_0_audio_enable(adev
, dig
->afmt
->pin
, false);
1964 dig
->afmt
->pin
= NULL
;
1967 dig
->afmt
->enabled
= enable
;
1969 DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
1970 enable
? "En" : "Dis", dig
->afmt
->offset
, amdgpu_encoder
->encoder_id
);
1973 static void dce_v11_0_afmt_init(struct amdgpu_device
*adev
)
1977 for (i
= 0; i
< adev
->mode_info
.num_dig
; i
++)
1978 adev
->mode_info
.afmt
[i
] = NULL
;
1980 /* DCE11 has audio blocks tied to DIG encoders */
1981 for (i
= 0; i
< adev
->mode_info
.num_dig
; i
++) {
1982 adev
->mode_info
.afmt
[i
] = kzalloc(sizeof(struct amdgpu_afmt
), GFP_KERNEL
);
1983 if (adev
->mode_info
.afmt
[i
]) {
1984 adev
->mode_info
.afmt
[i
]->offset
= dig_offsets
[i
];
1985 adev
->mode_info
.afmt
[i
]->id
= i
;
1990 static void dce_v11_0_afmt_fini(struct amdgpu_device
*adev
)
1994 for (i
= 0; i
< adev
->mode_info
.num_dig
; i
++) {
1995 kfree(adev
->mode_info
.afmt
[i
]);
1996 adev
->mode_info
.afmt
[i
] = NULL
;
2000 static const u32 vga_control_regs
[6] =
2010 static void dce_v11_0_vga_enable(struct drm_crtc
*crtc
, bool enable
)
2012 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2013 struct drm_device
*dev
= crtc
->dev
;
2014 struct amdgpu_device
*adev
= dev
->dev_private
;
2017 vga_control
= RREG32(vga_control_regs
[amdgpu_crtc
->crtc_id
]) & ~1;
2019 WREG32(vga_control_regs
[amdgpu_crtc
->crtc_id
], vga_control
| 1);
2021 WREG32(vga_control_regs
[amdgpu_crtc
->crtc_id
], vga_control
);
2024 static void dce_v11_0_grph_enable(struct drm_crtc
*crtc
, bool enable
)
2026 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2027 struct drm_device
*dev
= crtc
->dev
;
2028 struct amdgpu_device
*adev
= dev
->dev_private
;
2031 WREG32(mmGRPH_ENABLE
+ amdgpu_crtc
->crtc_offset
, 1);
2033 WREG32(mmGRPH_ENABLE
+ amdgpu_crtc
->crtc_offset
, 0);
2036 static int dce_v11_0_crtc_do_set_base(struct drm_crtc
*crtc
,
2037 struct drm_framebuffer
*fb
,
2038 int x
, int y
, int atomic
)
2040 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2041 struct drm_device
*dev
= crtc
->dev
;
2042 struct amdgpu_device
*adev
= dev
->dev_private
;
2043 struct amdgpu_framebuffer
*amdgpu_fb
;
2044 struct drm_framebuffer
*target_fb
;
2045 struct drm_gem_object
*obj
;
2046 struct amdgpu_bo
*rbo
;
2047 uint64_t fb_location
, tiling_flags
;
2048 uint32_t fb_format
, fb_pitch_pixels
;
2049 u32 fb_swap
= REG_SET_FIELD(0, GRPH_SWAP_CNTL
, GRPH_ENDIAN_SWAP
, ENDIAN_NONE
);
2051 u32 tmp
, viewport_w
, viewport_h
;
2053 bool bypass_lut
= false;
2056 if (!atomic
&& !crtc
->primary
->fb
) {
2057 DRM_DEBUG_KMS("No FB bound\n");
2062 amdgpu_fb
= to_amdgpu_framebuffer(fb
);
2066 amdgpu_fb
= to_amdgpu_framebuffer(crtc
->primary
->fb
);
2067 target_fb
= crtc
->primary
->fb
;
2070 /* If atomic, assume fb object is pinned & idle & fenced and
2071 * just update base pointers
2073 obj
= amdgpu_fb
->obj
;
2074 rbo
= gem_to_amdgpu_bo(obj
);
2075 r
= amdgpu_bo_reserve(rbo
, false);
2076 if (unlikely(r
!= 0))
2080 fb_location
= amdgpu_bo_gpu_offset(rbo
);
2082 r
= amdgpu_bo_pin(rbo
, AMDGPU_GEM_DOMAIN_VRAM
, &fb_location
);
2083 if (unlikely(r
!= 0)) {
2084 amdgpu_bo_unreserve(rbo
);
2089 amdgpu_bo_get_tiling_flags(rbo
, &tiling_flags
);
2090 amdgpu_bo_unreserve(rbo
);
2092 pipe_config
= AMDGPU_TILING_GET(tiling_flags
, PIPE_CONFIG
);
2094 switch (target_fb
->pixel_format
) {
2096 fb_format
= REG_SET_FIELD(0, GRPH_CONTROL
, GRPH_DEPTH
, 0);
2097 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_FORMAT
, 0);
2099 case DRM_FORMAT_XRGB4444
:
2100 case DRM_FORMAT_ARGB4444
:
2101 fb_format
= REG_SET_FIELD(0, GRPH_CONTROL
, GRPH_DEPTH
, 1);
2102 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_FORMAT
, 2);
2104 fb_swap
= REG_SET_FIELD(fb_swap
, GRPH_SWAP_CNTL
, GRPH_ENDIAN_SWAP
,
2108 case DRM_FORMAT_XRGB1555
:
2109 case DRM_FORMAT_ARGB1555
:
2110 fb_format
= REG_SET_FIELD(0, GRPH_CONTROL
, GRPH_DEPTH
, 1);
2111 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_FORMAT
, 0);
2113 fb_swap
= REG_SET_FIELD(fb_swap
, GRPH_SWAP_CNTL
, GRPH_ENDIAN_SWAP
,
2117 case DRM_FORMAT_BGRX5551
:
2118 case DRM_FORMAT_BGRA5551
:
2119 fb_format
= REG_SET_FIELD(0, GRPH_CONTROL
, GRPH_DEPTH
, 1);
2120 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_FORMAT
, 5);
2122 fb_swap
= REG_SET_FIELD(fb_swap
, GRPH_SWAP_CNTL
, GRPH_ENDIAN_SWAP
,
2126 case DRM_FORMAT_RGB565
:
2127 fb_format
= REG_SET_FIELD(0, GRPH_CONTROL
, GRPH_DEPTH
, 1);
2128 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_FORMAT
, 1);
2130 fb_swap
= REG_SET_FIELD(fb_swap
, GRPH_SWAP_CNTL
, GRPH_ENDIAN_SWAP
,
2134 case DRM_FORMAT_XRGB8888
:
2135 case DRM_FORMAT_ARGB8888
:
2136 fb_format
= REG_SET_FIELD(0, GRPH_CONTROL
, GRPH_DEPTH
, 2);
2137 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_FORMAT
, 0);
2139 fb_swap
= REG_SET_FIELD(fb_swap
, GRPH_SWAP_CNTL
, GRPH_ENDIAN_SWAP
,
2143 case DRM_FORMAT_XRGB2101010
:
2144 case DRM_FORMAT_ARGB2101010
:
2145 fb_format
= REG_SET_FIELD(0, GRPH_CONTROL
, GRPH_DEPTH
, 2);
2146 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_FORMAT
, 1);
2148 fb_swap
= REG_SET_FIELD(fb_swap
, GRPH_SWAP_CNTL
, GRPH_ENDIAN_SWAP
,
2151 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
2154 case DRM_FORMAT_BGRX1010102
:
2155 case DRM_FORMAT_BGRA1010102
:
2156 fb_format
= REG_SET_FIELD(0, GRPH_CONTROL
, GRPH_DEPTH
, 2);
2157 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_FORMAT
, 4);
2159 fb_swap
= REG_SET_FIELD(fb_swap
, GRPH_SWAP_CNTL
, GRPH_ENDIAN_SWAP
,
2162 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
2166 DRM_ERROR("Unsupported screen format %s\n",
2167 drm_get_format_name(target_fb
->pixel_format
));
2171 if (AMDGPU_TILING_GET(tiling_flags
, ARRAY_MODE
) == ARRAY_2D_TILED_THIN1
) {
2172 unsigned bankw
, bankh
, mtaspect
, tile_split
, num_banks
;
2174 bankw
= AMDGPU_TILING_GET(tiling_flags
, BANK_WIDTH
);
2175 bankh
= AMDGPU_TILING_GET(tiling_flags
, BANK_HEIGHT
);
2176 mtaspect
= AMDGPU_TILING_GET(tiling_flags
, MACRO_TILE_ASPECT
);
2177 tile_split
= AMDGPU_TILING_GET(tiling_flags
, TILE_SPLIT
);
2178 num_banks
= AMDGPU_TILING_GET(tiling_flags
, NUM_BANKS
);
2180 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_NUM_BANKS
, num_banks
);
2181 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_ARRAY_MODE
,
2182 ARRAY_2D_TILED_THIN1
);
2183 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_TILE_SPLIT
,
2185 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_BANK_WIDTH
, bankw
);
2186 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_BANK_HEIGHT
, bankh
);
2187 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_MACRO_TILE_ASPECT
,
2189 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_MICRO_TILE_MODE
,
2190 ADDR_SURF_MICRO_TILING_DISPLAY
);
2191 } else if (AMDGPU_TILING_GET(tiling_flags
, ARRAY_MODE
) == ARRAY_1D_TILED_THIN1
) {
2192 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_ARRAY_MODE
,
2193 ARRAY_1D_TILED_THIN1
);
2196 fb_format
= REG_SET_FIELD(fb_format
, GRPH_CONTROL
, GRPH_PIPE_CONFIG
,
2199 dce_v11_0_vga_enable(crtc
, false);
2201 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
2202 upper_32_bits(fb_location
));
2203 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
2204 upper_32_bits(fb_location
));
2205 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
2206 (u32
)fb_location
& GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK
);
2207 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
2208 (u32
) fb_location
& GRPH_SECONDARY_SURFACE_ADDRESS__GRPH_SECONDARY_SURFACE_ADDRESS_MASK
);
2209 WREG32(mmGRPH_CONTROL
+ amdgpu_crtc
->crtc_offset
, fb_format
);
2210 WREG32(mmGRPH_SWAP_CNTL
+ amdgpu_crtc
->crtc_offset
, fb_swap
);
2213 * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
2214 * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
2215 * retain the full precision throughout the pipeline.
2217 tmp
= RREG32(mmGRPH_LUT_10BIT_BYPASS
+ amdgpu_crtc
->crtc_offset
);
2219 tmp
= REG_SET_FIELD(tmp
, GRPH_LUT_10BIT_BYPASS
, GRPH_LUT_10BIT_BYPASS_EN
, 1);
2221 tmp
= REG_SET_FIELD(tmp
, GRPH_LUT_10BIT_BYPASS
, GRPH_LUT_10BIT_BYPASS_EN
, 0);
2222 WREG32(mmGRPH_LUT_10BIT_BYPASS
+ amdgpu_crtc
->crtc_offset
, tmp
);
2225 DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
2227 WREG32(mmGRPH_SURFACE_OFFSET_X
+ amdgpu_crtc
->crtc_offset
, 0);
2228 WREG32(mmGRPH_SURFACE_OFFSET_Y
+ amdgpu_crtc
->crtc_offset
, 0);
2229 WREG32(mmGRPH_X_START
+ amdgpu_crtc
->crtc_offset
, 0);
2230 WREG32(mmGRPH_Y_START
+ amdgpu_crtc
->crtc_offset
, 0);
2231 WREG32(mmGRPH_X_END
+ amdgpu_crtc
->crtc_offset
, target_fb
->width
);
2232 WREG32(mmGRPH_Y_END
+ amdgpu_crtc
->crtc_offset
, target_fb
->height
);
2234 fb_pitch_pixels
= target_fb
->pitches
[0] / (target_fb
->bits_per_pixel
/ 8);
2235 WREG32(mmGRPH_PITCH
+ amdgpu_crtc
->crtc_offset
, fb_pitch_pixels
);
2237 dce_v11_0_grph_enable(crtc
, true);
2239 WREG32(mmLB_DESKTOP_HEIGHT
+ amdgpu_crtc
->crtc_offset
,
2244 WREG32(mmVIEWPORT_START
+ amdgpu_crtc
->crtc_offset
,
2246 viewport_w
= crtc
->mode
.hdisplay
;
2247 viewport_h
= (crtc
->mode
.vdisplay
+ 1) & ~1;
2248 WREG32(mmVIEWPORT_SIZE
+ amdgpu_crtc
->crtc_offset
,
2249 (viewport_w
<< 16) | viewport_h
);
2251 /* pageflip setup */
2252 /* make sure flip is at vb rather than hb */
2253 tmp
= RREG32(mmGRPH_FLIP_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2254 tmp
= REG_SET_FIELD(tmp
, GRPH_FLIP_CONTROL
,
2255 GRPH_SURFACE_UPDATE_H_RETRACE_EN
, 0);
2256 WREG32(mmGRPH_FLIP_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2258 /* set pageflip to happen only at start of vblank interval (front porch) */
2259 WREG32(mmCRTC_MASTER_UPDATE_MODE
+ amdgpu_crtc
->crtc_offset
, 3);
2261 if (!atomic
&& fb
&& fb
!= crtc
->primary
->fb
) {
2262 amdgpu_fb
= to_amdgpu_framebuffer(fb
);
2263 rbo
= gem_to_amdgpu_bo(amdgpu_fb
->obj
);
2264 r
= amdgpu_bo_reserve(rbo
, false);
2265 if (unlikely(r
!= 0))
2267 amdgpu_bo_unpin(rbo
);
2268 amdgpu_bo_unreserve(rbo
);
2271 /* Bytes per pixel may have changed */
2272 dce_v11_0_bandwidth_update(adev
);
2277 static void dce_v11_0_set_interleave(struct drm_crtc
*crtc
,
2278 struct drm_display_mode
*mode
)
2280 struct drm_device
*dev
= crtc
->dev
;
2281 struct amdgpu_device
*adev
= dev
->dev_private
;
2282 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2285 tmp
= RREG32(mmLB_DATA_FORMAT
+ amdgpu_crtc
->crtc_offset
);
2286 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
2287 tmp
= REG_SET_FIELD(tmp
, LB_DATA_FORMAT
, INTERLEAVE_EN
, 1);
2289 tmp
= REG_SET_FIELD(tmp
, LB_DATA_FORMAT
, INTERLEAVE_EN
, 0);
2290 WREG32(mmLB_DATA_FORMAT
+ amdgpu_crtc
->crtc_offset
, tmp
);
2293 static void dce_v11_0_crtc_load_lut(struct drm_crtc
*crtc
)
2295 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2296 struct drm_device
*dev
= crtc
->dev
;
2297 struct amdgpu_device
*adev
= dev
->dev_private
;
2301 DRM_DEBUG_KMS("%d\n", amdgpu_crtc
->crtc_id
);
2303 tmp
= RREG32(mmINPUT_CSC_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2304 tmp
= REG_SET_FIELD(tmp
, INPUT_CSC_CONTROL
, INPUT_CSC_GRPH_MODE
, 0);
2305 WREG32(mmINPUT_CSC_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2307 tmp
= RREG32(mmPRESCALE_GRPH_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2308 tmp
= REG_SET_FIELD(tmp
, PRESCALE_GRPH_CONTROL
, GRPH_PRESCALE_BYPASS
, 1);
2309 WREG32(mmPRESCALE_GRPH_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2311 tmp
= RREG32(mmINPUT_GAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2312 tmp
= REG_SET_FIELD(tmp
, INPUT_GAMMA_CONTROL
, GRPH_INPUT_GAMMA_MODE
, 0);
2313 WREG32(mmINPUT_GAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2315 WREG32(mmDC_LUT_CONTROL
+ amdgpu_crtc
->crtc_offset
, 0);
2317 WREG32(mmDC_LUT_BLACK_OFFSET_BLUE
+ amdgpu_crtc
->crtc_offset
, 0);
2318 WREG32(mmDC_LUT_BLACK_OFFSET_GREEN
+ amdgpu_crtc
->crtc_offset
, 0);
2319 WREG32(mmDC_LUT_BLACK_OFFSET_RED
+ amdgpu_crtc
->crtc_offset
, 0);
2321 WREG32(mmDC_LUT_WHITE_OFFSET_BLUE
+ amdgpu_crtc
->crtc_offset
, 0xffff);
2322 WREG32(mmDC_LUT_WHITE_OFFSET_GREEN
+ amdgpu_crtc
->crtc_offset
, 0xffff);
2323 WREG32(mmDC_LUT_WHITE_OFFSET_RED
+ amdgpu_crtc
->crtc_offset
, 0xffff);
2325 WREG32(mmDC_LUT_RW_MODE
+ amdgpu_crtc
->crtc_offset
, 0);
2326 WREG32(mmDC_LUT_WRITE_EN_MASK
+ amdgpu_crtc
->crtc_offset
, 0x00000007);
2328 WREG32(mmDC_LUT_RW_INDEX
+ amdgpu_crtc
->crtc_offset
, 0);
2329 for (i
= 0; i
< 256; i
++) {
2330 WREG32(mmDC_LUT_30_COLOR
+ amdgpu_crtc
->crtc_offset
,
2331 (amdgpu_crtc
->lut_r
[i
] << 20) |
2332 (amdgpu_crtc
->lut_g
[i
] << 10) |
2333 (amdgpu_crtc
->lut_b
[i
] << 0));
2336 tmp
= RREG32(mmDEGAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2337 tmp
= REG_SET_FIELD(tmp
, DEGAMMA_CONTROL
, GRPH_DEGAMMA_MODE
, 0);
2338 tmp
= REG_SET_FIELD(tmp
, DEGAMMA_CONTROL
, CURSOR_DEGAMMA_MODE
, 0);
2339 tmp
= REG_SET_FIELD(tmp
, DEGAMMA_CONTROL
, CURSOR2_DEGAMMA_MODE
, 0);
2340 WREG32(mmDEGAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2342 tmp
= RREG32(mmGAMUT_REMAP_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2343 tmp
= REG_SET_FIELD(tmp
, GAMUT_REMAP_CONTROL
, GRPH_GAMUT_REMAP_MODE
, 0);
2344 WREG32(mmGAMUT_REMAP_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2346 tmp
= RREG32(mmREGAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2347 tmp
= REG_SET_FIELD(tmp
, REGAMMA_CONTROL
, GRPH_REGAMMA_MODE
, 0);
2348 WREG32(mmREGAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2350 tmp
= RREG32(mmOUTPUT_CSC_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2351 tmp
= REG_SET_FIELD(tmp
, OUTPUT_CSC_CONTROL
, OUTPUT_CSC_GRPH_MODE
, 0);
2352 WREG32(mmOUTPUT_CSC_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2354 /* XXX match this to the depth of the crtc fmt block, move to modeset? */
2355 WREG32(mmDENORM_CONTROL
+ amdgpu_crtc
->crtc_offset
, 0);
2356 /* XXX this only needs to be programmed once per crtc at startup,
2357 * not sure where the best place for it is
2359 tmp
= RREG32(mmALPHA_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2360 tmp
= REG_SET_FIELD(tmp
, ALPHA_CONTROL
, CURSOR_ALPHA_BLND_ENA
, 1);
2361 WREG32(mmALPHA_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2364 static int dce_v11_0_pick_dig_encoder(struct drm_encoder
*encoder
)
2366 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
2367 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
2369 switch (amdgpu_encoder
->encoder_id
) {
2370 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
2376 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
2382 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
2388 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3
:
2392 DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder
->encoder_id
);
2398 * dce_v11_0_pick_pll - Allocate a PPLL for use by the crtc.
2402 * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
2403 * a single PPLL can be used for all DP crtcs/encoders. For non-DP
2404 * monitors a dedicated PPLL must be used. If a particular board has
2405 * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
2406 * as there is no need to program the PLL itself. If we are not able to
2407 * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
2408 * avoid messing up an existing monitor.
2410 * Asic specific PLL information
2414 * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP)
2416 * - PPLL0, PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC
2419 static u32
dce_v11_0_pick_pll(struct drm_crtc
*crtc
)
2421 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2422 struct drm_device
*dev
= crtc
->dev
;
2423 struct amdgpu_device
*adev
= dev
->dev_private
;
2427 if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc
->encoder
))) {
2428 if (adev
->clock
.dp_extclk
)
2429 /* skip PPLL programming if using ext clock */
2430 return ATOM_PPLL_INVALID
;
2432 /* use the same PPLL for all DP monitors */
2433 pll
= amdgpu_pll_get_shared_dp_ppll(crtc
);
2434 if (pll
!= ATOM_PPLL_INVALID
)
2438 /* use the same PPLL for all monitors with the same clock */
2439 pll
= amdgpu_pll_get_shared_nondp_ppll(crtc
);
2440 if (pll
!= ATOM_PPLL_INVALID
)
2444 /* XXX need to determine what plls are available on each DCE11 part */
2445 pll_in_use
= amdgpu_pll_get_use_mask(crtc
);
2446 if (adev
->asic_type
== CHIP_CARRIZO
) {
2447 if (!(pll_in_use
& (1 << ATOM_PPLL1
)))
2449 if (!(pll_in_use
& (1 << ATOM_PPLL0
)))
2451 DRM_ERROR("unable to allocate a PPLL\n");
2452 return ATOM_PPLL_INVALID
;
2454 if (!(pll_in_use
& (1 << ATOM_PPLL2
)))
2456 if (!(pll_in_use
& (1 << ATOM_PPLL1
)))
2458 if (!(pll_in_use
& (1 << ATOM_PPLL0
)))
2460 DRM_ERROR("unable to allocate a PPLL\n");
2461 return ATOM_PPLL_INVALID
;
2463 return ATOM_PPLL_INVALID
;
2466 static void dce_v11_0_lock_cursor(struct drm_crtc
*crtc
, bool lock
)
2468 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2469 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2472 cur_lock
= RREG32(mmCUR_UPDATE
+ amdgpu_crtc
->crtc_offset
);
2474 cur_lock
= REG_SET_FIELD(cur_lock
, CUR_UPDATE
, CURSOR_UPDATE_LOCK
, 1);
2476 cur_lock
= REG_SET_FIELD(cur_lock
, CUR_UPDATE
, CURSOR_UPDATE_LOCK
, 0);
2477 WREG32(mmCUR_UPDATE
+ amdgpu_crtc
->crtc_offset
, cur_lock
);
2480 static void dce_v11_0_hide_cursor(struct drm_crtc
*crtc
)
2482 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2483 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2486 tmp
= RREG32_IDX(mmCUR_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2487 tmp
= REG_SET_FIELD(tmp
, CUR_CONTROL
, CURSOR_EN
, 0);
2488 WREG32_IDX(mmCUR_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2491 static void dce_v11_0_show_cursor(struct drm_crtc
*crtc
)
2493 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2494 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2497 tmp
= RREG32_IDX(mmCUR_CONTROL
+ amdgpu_crtc
->crtc_offset
);
2498 tmp
= REG_SET_FIELD(tmp
, CUR_CONTROL
, CURSOR_EN
, 1);
2499 tmp
= REG_SET_FIELD(tmp
, CUR_CONTROL
, CURSOR_MODE
, 2);
2500 WREG32_IDX(mmCUR_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
2503 static void dce_v11_0_set_cursor(struct drm_crtc
*crtc
, struct drm_gem_object
*obj
,
2506 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2507 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2509 WREG32(mmCUR_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
2510 upper_32_bits(gpu_addr
));
2511 WREG32(mmCUR_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
2512 lower_32_bits(gpu_addr
));
2515 static int dce_v11_0_crtc_cursor_move(struct drm_crtc
*crtc
,
2518 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2519 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2520 int xorigin
= 0, yorigin
= 0;
2522 /* avivo cursor are offset into the total surface */
2525 DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x
, y
, crtc
->x
, crtc
->y
);
2528 xorigin
= min(-x
, amdgpu_crtc
->max_cursor_width
- 1);
2532 yorigin
= min(-y
, amdgpu_crtc
->max_cursor_height
- 1);
2536 dce_v11_0_lock_cursor(crtc
, true);
2537 WREG32(mmCUR_POSITION
+ amdgpu_crtc
->crtc_offset
, (x
<< 16) | y
);
2538 WREG32(mmCUR_HOT_SPOT
+ amdgpu_crtc
->crtc_offset
, (xorigin
<< 16) | yorigin
);
2539 WREG32(mmCUR_SIZE
+ amdgpu_crtc
->crtc_offset
,
2540 ((amdgpu_crtc
->cursor_width
- 1) << 16) | (amdgpu_crtc
->cursor_height
- 1));
2541 dce_v11_0_lock_cursor(crtc
, false);
2546 static int dce_v11_0_crtc_cursor_set(struct drm_crtc
*crtc
,
2547 struct drm_file
*file_priv
,
2552 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2553 struct drm_gem_object
*obj
;
2554 struct amdgpu_bo
*robj
;
2559 /* turn off cursor */
2560 dce_v11_0_hide_cursor(crtc
);
2565 if ((width
> amdgpu_crtc
->max_cursor_width
) ||
2566 (height
> amdgpu_crtc
->max_cursor_height
)) {
2567 DRM_ERROR("bad cursor width or height %d x %d\n", width
, height
);
2571 obj
= drm_gem_object_lookup(crtc
->dev
, file_priv
, handle
);
2573 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle
, amdgpu_crtc
->crtc_id
);
2577 robj
= gem_to_amdgpu_bo(obj
);
2578 ret
= amdgpu_bo_reserve(robj
, false);
2579 if (unlikely(ret
!= 0))
2581 ret
= amdgpu_bo_pin_restricted(robj
, AMDGPU_GEM_DOMAIN_VRAM
,
2583 amdgpu_bo_unreserve(robj
);
2587 amdgpu_crtc
->cursor_width
= width
;
2588 amdgpu_crtc
->cursor_height
= height
;
2590 dce_v11_0_lock_cursor(crtc
, true);
2591 dce_v11_0_set_cursor(crtc
, obj
, gpu_addr
);
2592 dce_v11_0_show_cursor(crtc
);
2593 dce_v11_0_lock_cursor(crtc
, false);
2596 if (amdgpu_crtc
->cursor_bo
) {
2597 robj
= gem_to_amdgpu_bo(amdgpu_crtc
->cursor_bo
);
2598 ret
= amdgpu_bo_reserve(robj
, false);
2599 if (likely(ret
== 0)) {
2600 amdgpu_bo_unpin(robj
);
2601 amdgpu_bo_unreserve(robj
);
2603 drm_gem_object_unreference_unlocked(amdgpu_crtc
->cursor_bo
);
2606 amdgpu_crtc
->cursor_bo
= obj
;
2609 drm_gem_object_unreference_unlocked(obj
);
2614 static void dce_v11_0_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
2615 u16
*blue
, uint32_t start
, uint32_t size
)
2617 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2618 int end
= (start
+ size
> 256) ? 256 : start
+ size
, i
;
2620 /* userspace palettes are always correct as is */
2621 for (i
= start
; i
< end
; i
++) {
2622 amdgpu_crtc
->lut_r
[i
] = red
[i
] >> 6;
2623 amdgpu_crtc
->lut_g
[i
] = green
[i
] >> 6;
2624 amdgpu_crtc
->lut_b
[i
] = blue
[i
] >> 6;
2626 dce_v11_0_crtc_load_lut(crtc
);
2629 static void dce_v11_0_crtc_destroy(struct drm_crtc
*crtc
)
2631 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2633 drm_crtc_cleanup(crtc
);
2634 destroy_workqueue(amdgpu_crtc
->pflip_queue
);
2638 static const struct drm_crtc_funcs dce_v11_0_crtc_funcs
= {
2639 .cursor_set
= dce_v11_0_crtc_cursor_set
,
2640 .cursor_move
= dce_v11_0_crtc_cursor_move
,
2641 .gamma_set
= dce_v11_0_crtc_gamma_set
,
2642 .set_config
= amdgpu_crtc_set_config
,
2643 .destroy
= dce_v11_0_crtc_destroy
,
2644 .page_flip
= amdgpu_crtc_page_flip
,
2647 static void dce_v11_0_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
2649 struct drm_device
*dev
= crtc
->dev
;
2650 struct amdgpu_device
*adev
= dev
->dev_private
;
2651 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2655 case DRM_MODE_DPMS_ON
:
2656 amdgpu_crtc
->enabled
= true;
2657 amdgpu_atombios_crtc_enable(crtc
, ATOM_ENABLE
);
2658 dce_v11_0_vga_enable(crtc
, true);
2659 amdgpu_atombios_crtc_blank(crtc
, ATOM_DISABLE
);
2660 dce_v11_0_vga_enable(crtc
, false);
2661 /* Make sure VBLANK and PFLIP interrupts are still enabled */
2662 type
= amdgpu_crtc_idx_to_irq_type(adev
, amdgpu_crtc
->crtc_id
);
2663 amdgpu_irq_update(adev
, &adev
->crtc_irq
, type
);
2664 amdgpu_irq_update(adev
, &adev
->pageflip_irq
, type
);
2665 drm_vblank_post_modeset(dev
, amdgpu_crtc
->crtc_id
);
2666 dce_v11_0_crtc_load_lut(crtc
);
2668 case DRM_MODE_DPMS_STANDBY
:
2669 case DRM_MODE_DPMS_SUSPEND
:
2670 case DRM_MODE_DPMS_OFF
:
2671 drm_vblank_pre_modeset(dev
, amdgpu_crtc
->crtc_id
);
2672 if (amdgpu_crtc
->enabled
) {
2673 dce_v11_0_vga_enable(crtc
, true);
2674 amdgpu_atombios_crtc_blank(crtc
, ATOM_ENABLE
);
2675 dce_v11_0_vga_enable(crtc
, false);
2677 amdgpu_atombios_crtc_enable(crtc
, ATOM_DISABLE
);
2678 amdgpu_crtc
->enabled
= false;
2681 /* adjust pm to dpms */
2682 amdgpu_pm_compute_clocks(adev
);
2685 static void dce_v11_0_crtc_prepare(struct drm_crtc
*crtc
)
2687 /* disable crtc pair power gating before programming */
2688 amdgpu_atombios_crtc_powergate(crtc
, ATOM_DISABLE
);
2689 amdgpu_atombios_crtc_lock(crtc
, ATOM_ENABLE
);
2690 dce_v11_0_crtc_dpms(crtc
, DRM_MODE_DPMS_OFF
);
2693 static void dce_v11_0_crtc_commit(struct drm_crtc
*crtc
)
2695 dce_v11_0_crtc_dpms(crtc
, DRM_MODE_DPMS_ON
);
2696 amdgpu_atombios_crtc_lock(crtc
, ATOM_DISABLE
);
2699 static void dce_v11_0_crtc_disable(struct drm_crtc
*crtc
)
2701 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2702 struct drm_device
*dev
= crtc
->dev
;
2703 struct amdgpu_device
*adev
= dev
->dev_private
;
2704 struct amdgpu_atom_ss ss
;
2707 dce_v11_0_crtc_dpms(crtc
, DRM_MODE_DPMS_OFF
);
2708 if (crtc
->primary
->fb
) {
2710 struct amdgpu_framebuffer
*amdgpu_fb
;
2711 struct amdgpu_bo
*rbo
;
2713 amdgpu_fb
= to_amdgpu_framebuffer(crtc
->primary
->fb
);
2714 rbo
= gem_to_amdgpu_bo(amdgpu_fb
->obj
);
2715 r
= amdgpu_bo_reserve(rbo
, false);
2717 DRM_ERROR("failed to reserve rbo before unpin\n");
2719 amdgpu_bo_unpin(rbo
);
2720 amdgpu_bo_unreserve(rbo
);
2723 /* disable the GRPH */
2724 dce_v11_0_grph_enable(crtc
, false);
2726 amdgpu_atombios_crtc_powergate(crtc
, ATOM_ENABLE
);
2728 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
2729 if (adev
->mode_info
.crtcs
[i
] &&
2730 adev
->mode_info
.crtcs
[i
]->enabled
&&
2731 i
!= amdgpu_crtc
->crtc_id
&&
2732 amdgpu_crtc
->pll_id
== adev
->mode_info
.crtcs
[i
]->pll_id
) {
2733 /* one other crtc is using this pll don't turn
2740 switch (amdgpu_crtc
->pll_id
) {
2744 /* disable the ppll */
2745 amdgpu_atombios_crtc_program_pll(crtc
, amdgpu_crtc
->crtc_id
, amdgpu_crtc
->pll_id
,
2746 0, 0, ATOM_DISABLE
, 0, 0, 0, 0, 0, false, &ss
);
2752 amdgpu_crtc
->pll_id
= ATOM_PPLL_INVALID
;
2753 amdgpu_crtc
->adjusted_clock
= 0;
2754 amdgpu_crtc
->encoder
= NULL
;
2755 amdgpu_crtc
->connector
= NULL
;
2758 static int dce_v11_0_crtc_mode_set(struct drm_crtc
*crtc
,
2759 struct drm_display_mode
*mode
,
2760 struct drm_display_mode
*adjusted_mode
,
2761 int x
, int y
, struct drm_framebuffer
*old_fb
)
2763 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2765 if (!amdgpu_crtc
->adjusted_clock
)
2768 amdgpu_atombios_crtc_set_pll(crtc
, adjusted_mode
);
2769 amdgpu_atombios_crtc_set_dtd_timing(crtc
, adjusted_mode
);
2770 dce_v11_0_crtc_do_set_base(crtc
, old_fb
, x
, y
, 0);
2771 amdgpu_atombios_crtc_overscan_setup(crtc
, mode
, adjusted_mode
);
2772 amdgpu_atombios_crtc_scaler_setup(crtc
);
2773 /* update the hw version fpr dpm */
2774 amdgpu_crtc
->hw_mode
= *adjusted_mode
;
2779 static bool dce_v11_0_crtc_mode_fixup(struct drm_crtc
*crtc
,
2780 const struct drm_display_mode
*mode
,
2781 struct drm_display_mode
*adjusted_mode
)
2783 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2784 struct drm_device
*dev
= crtc
->dev
;
2785 struct drm_encoder
*encoder
;
2787 /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
2788 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
2789 if (encoder
->crtc
== crtc
) {
2790 amdgpu_crtc
->encoder
= encoder
;
2791 amdgpu_crtc
->connector
= amdgpu_get_connector_for_encoder(encoder
);
2795 if ((amdgpu_crtc
->encoder
== NULL
) || (amdgpu_crtc
->connector
== NULL
)) {
2796 amdgpu_crtc
->encoder
= NULL
;
2797 amdgpu_crtc
->connector
= NULL
;
2800 if (!amdgpu_crtc_scaling_mode_fixup(crtc
, mode
, adjusted_mode
))
2802 if (amdgpu_atombios_crtc_prepare_pll(crtc
, adjusted_mode
))
2805 amdgpu_crtc
->pll_id
= dce_v11_0_pick_pll(crtc
);
2806 /* if we can't get a PPLL for a non-DP encoder, fail */
2807 if ((amdgpu_crtc
->pll_id
== ATOM_PPLL_INVALID
) &&
2808 !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc
->encoder
)))
2814 static int dce_v11_0_crtc_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2815 struct drm_framebuffer
*old_fb
)
2817 return dce_v11_0_crtc_do_set_base(crtc
, old_fb
, x
, y
, 0);
2820 static int dce_v11_0_crtc_set_base_atomic(struct drm_crtc
*crtc
,
2821 struct drm_framebuffer
*fb
,
2822 int x
, int y
, enum mode_set_atomic state
)
2824 return dce_v11_0_crtc_do_set_base(crtc
, fb
, x
, y
, 1);
2827 static const struct drm_crtc_helper_funcs dce_v11_0_crtc_helper_funcs
= {
2828 .dpms
= dce_v11_0_crtc_dpms
,
2829 .mode_fixup
= dce_v11_0_crtc_mode_fixup
,
2830 .mode_set
= dce_v11_0_crtc_mode_set
,
2831 .mode_set_base
= dce_v11_0_crtc_set_base
,
2832 .mode_set_base_atomic
= dce_v11_0_crtc_set_base_atomic
,
2833 .prepare
= dce_v11_0_crtc_prepare
,
2834 .commit
= dce_v11_0_crtc_commit
,
2835 .load_lut
= dce_v11_0_crtc_load_lut
,
2836 .disable
= dce_v11_0_crtc_disable
,
2839 static int dce_v11_0_crtc_init(struct amdgpu_device
*adev
, int index
)
2841 struct amdgpu_crtc
*amdgpu_crtc
;
2844 amdgpu_crtc
= kzalloc(sizeof(struct amdgpu_crtc
) +
2845 (AMDGPUFB_CONN_LIMIT
* sizeof(struct drm_connector
*)), GFP_KERNEL
);
2846 if (amdgpu_crtc
== NULL
)
2849 drm_crtc_init(adev
->ddev
, &amdgpu_crtc
->base
, &dce_v11_0_crtc_funcs
);
2851 drm_mode_crtc_set_gamma_size(&amdgpu_crtc
->base
, 256);
2852 amdgpu_crtc
->crtc_id
= index
;
2853 amdgpu_crtc
->pflip_queue
= create_singlethread_workqueue("amdgpu-pageflip-queue");
2854 adev
->mode_info
.crtcs
[index
] = amdgpu_crtc
;
2856 amdgpu_crtc
->max_cursor_width
= 128;
2857 amdgpu_crtc
->max_cursor_height
= 128;
2858 adev
->ddev
->mode_config
.cursor_width
= amdgpu_crtc
->max_cursor_width
;
2859 adev
->ddev
->mode_config
.cursor_height
= amdgpu_crtc
->max_cursor_height
;
2861 for (i
= 0; i
< 256; i
++) {
2862 amdgpu_crtc
->lut_r
[i
] = i
<< 2;
2863 amdgpu_crtc
->lut_g
[i
] = i
<< 2;
2864 amdgpu_crtc
->lut_b
[i
] = i
<< 2;
2867 switch (amdgpu_crtc
->crtc_id
) {
2870 amdgpu_crtc
->crtc_offset
= CRTC0_REGISTER_OFFSET
;
2873 amdgpu_crtc
->crtc_offset
= CRTC1_REGISTER_OFFSET
;
2876 amdgpu_crtc
->crtc_offset
= CRTC2_REGISTER_OFFSET
;
2879 amdgpu_crtc
->crtc_offset
= CRTC3_REGISTER_OFFSET
;
2882 amdgpu_crtc
->crtc_offset
= CRTC4_REGISTER_OFFSET
;
2885 amdgpu_crtc
->crtc_offset
= CRTC5_REGISTER_OFFSET
;
2889 amdgpu_crtc
->pll_id
= ATOM_PPLL_INVALID
;
2890 amdgpu_crtc
->adjusted_clock
= 0;
2891 amdgpu_crtc
->encoder
= NULL
;
2892 amdgpu_crtc
->connector
= NULL
;
2893 drm_crtc_helper_add(&amdgpu_crtc
->base
, &dce_v11_0_crtc_helper_funcs
);
2898 static int dce_v11_0_early_init(void *handle
)
2900 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2902 adev
->audio_endpt_rreg
= &dce_v11_0_audio_endpt_rreg
;
2903 adev
->audio_endpt_wreg
= &dce_v11_0_audio_endpt_wreg
;
2905 dce_v11_0_set_display_funcs(adev
);
2906 dce_v11_0_set_irq_funcs(adev
);
2908 switch (adev
->asic_type
) {
2910 adev
->mode_info
.num_crtc
= 3;
2911 adev
->mode_info
.num_hpd
= 6;
2912 adev
->mode_info
.num_dig
= 9;
2915 /* FIXME: not supported yet */
2922 static int dce_v11_0_sw_init(void *handle
)
2925 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2927 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
2928 r
= amdgpu_irq_add_id(adev
, i
+ 1, &adev
->crtc_irq
);
2933 for (i
= 8; i
< 20; i
+= 2) {
2934 r
= amdgpu_irq_add_id(adev
, i
, &adev
->pageflip_irq
);
2940 r
= amdgpu_irq_add_id(adev
, 42, &adev
->hpd_irq
);
2944 adev
->mode_info
.mode_config_initialized
= true;
2946 adev
->ddev
->mode_config
.funcs
= &amdgpu_mode_funcs
;
2948 adev
->ddev
->mode_config
.max_width
= 16384;
2949 adev
->ddev
->mode_config
.max_height
= 16384;
2951 adev
->ddev
->mode_config
.preferred_depth
= 24;
2952 adev
->ddev
->mode_config
.prefer_shadow
= 1;
2954 adev
->ddev
->mode_config
.fb_base
= adev
->mc
.aper_base
;
2956 r
= amdgpu_modeset_create_props(adev
);
2960 adev
->ddev
->mode_config
.max_width
= 16384;
2961 adev
->ddev
->mode_config
.max_height
= 16384;
2963 /* allocate crtcs */
2964 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
2965 r
= dce_v11_0_crtc_init(adev
, i
);
2970 if (amdgpu_atombios_get_connector_info_from_object_table(adev
))
2971 amdgpu_print_display_setup(adev
->ddev
);
2976 dce_v11_0_afmt_init(adev
);
2978 r
= dce_v11_0_audio_init(adev
);
2982 drm_kms_helper_poll_init(adev
->ddev
);
2987 static int dce_v11_0_sw_fini(void *handle
)
2989 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2991 kfree(adev
->mode_info
.bios_hardcoded_edid
);
2993 drm_kms_helper_poll_fini(adev
->ddev
);
2995 dce_v11_0_audio_fini(adev
);
2997 dce_v11_0_afmt_fini(adev
);
2999 adev
->mode_info
.mode_config_initialized
= false;
3004 static int dce_v11_0_hw_init(void *handle
)
3007 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
3009 dce_v11_0_init_golden_registers(adev
);
3011 /* init dig PHYs, disp eng pll */
3012 amdgpu_atombios_encoder_init_dig(adev
);
3013 amdgpu_atombios_crtc_set_disp_eng_pll(adev
, adev
->clock
.default_dispclk
);
3015 /* initialize hpd */
3016 dce_v11_0_hpd_init(adev
);
3018 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
3019 dce_v11_0_audio_enable(adev
, &adev
->mode_info
.audio
.pin
[i
], false);
3022 dce_v11_0_pageflip_interrupt_init(adev
);
3027 static int dce_v11_0_hw_fini(void *handle
)
3030 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
3032 dce_v11_0_hpd_fini(adev
);
3034 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
3035 dce_v11_0_audio_enable(adev
, &adev
->mode_info
.audio
.pin
[i
], false);
3038 dce_v11_0_pageflip_interrupt_fini(adev
);
3043 static int dce_v11_0_suspend(void *handle
)
3045 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
3047 amdgpu_atombios_scratch_regs_save(adev
);
3049 dce_v11_0_hpd_fini(adev
);
3051 dce_v11_0_pageflip_interrupt_fini(adev
);
3056 static int dce_v11_0_resume(void *handle
)
3058 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
3060 dce_v11_0_init_golden_registers(adev
);
3062 amdgpu_atombios_scratch_regs_restore(adev
);
3064 /* init dig PHYs, disp eng pll */
3065 amdgpu_atombios_crtc_powergate_init(adev
);
3066 amdgpu_atombios_encoder_init_dig(adev
);
3067 amdgpu_atombios_crtc_set_disp_eng_pll(adev
, adev
->clock
.default_dispclk
);
3068 /* turn on the BL */
3069 if (adev
->mode_info
.bl_encoder
) {
3070 u8 bl_level
= amdgpu_display_backlight_get_level(adev
,
3071 adev
->mode_info
.bl_encoder
);
3072 amdgpu_display_backlight_set_level(adev
, adev
->mode_info
.bl_encoder
,
3076 /* initialize hpd */
3077 dce_v11_0_hpd_init(adev
);
3079 dce_v11_0_pageflip_interrupt_init(adev
);
3084 static bool dce_v11_0_is_idle(void *handle
)
3089 static int dce_v11_0_wait_for_idle(void *handle
)
3094 static void dce_v11_0_print_status(void *handle
)
3096 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
3098 dev_info(adev
->dev
, "DCE 10.x registers\n");
3102 static int dce_v11_0_soft_reset(void *handle
)
3104 u32 srbm_soft_reset
= 0, tmp
;
3105 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
3107 if (dce_v11_0_is_display_hung(adev
))
3108 srbm_soft_reset
|= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK
;
3110 if (srbm_soft_reset
) {
3111 dce_v11_0_print_status((void *)adev
);
3113 tmp
= RREG32(mmSRBM_SOFT_RESET
);
3114 tmp
|= srbm_soft_reset
;
3115 dev_info(adev
->dev
, "SRBM_SOFT_RESET=0x%08X\n", tmp
);
3116 WREG32(mmSRBM_SOFT_RESET
, tmp
);
3117 tmp
= RREG32(mmSRBM_SOFT_RESET
);
3121 tmp
&= ~srbm_soft_reset
;
3122 WREG32(mmSRBM_SOFT_RESET
, tmp
);
3123 tmp
= RREG32(mmSRBM_SOFT_RESET
);
3125 /* Wait a little for things to settle down */
3127 dce_v11_0_print_status((void *)adev
);
3132 static void dce_v11_0_set_crtc_vblank_interrupt_state(struct amdgpu_device
*adev
,
3134 enum amdgpu_interrupt_state state
)
3136 u32 lb_interrupt_mask
;
3138 if (crtc
>= adev
->mode_info
.num_crtc
) {
3139 DRM_DEBUG("invalid crtc %d\n", crtc
);
3144 case AMDGPU_IRQ_STATE_DISABLE
:
3145 lb_interrupt_mask
= RREG32(mmLB_INTERRUPT_MASK
+ crtc_offsets
[crtc
]);
3146 lb_interrupt_mask
= REG_SET_FIELD(lb_interrupt_mask
, LB_INTERRUPT_MASK
,
3147 VBLANK_INTERRUPT_MASK
, 0);
3148 WREG32(mmLB_INTERRUPT_MASK
+ crtc_offsets
[crtc
], lb_interrupt_mask
);
3150 case AMDGPU_IRQ_STATE_ENABLE
:
3151 lb_interrupt_mask
= RREG32(mmLB_INTERRUPT_MASK
+ crtc_offsets
[crtc
]);
3152 lb_interrupt_mask
= REG_SET_FIELD(lb_interrupt_mask
, LB_INTERRUPT_MASK
,
3153 VBLANK_INTERRUPT_MASK
, 1);
3154 WREG32(mmLB_INTERRUPT_MASK
+ crtc_offsets
[crtc
], lb_interrupt_mask
);
3161 static void dce_v11_0_set_crtc_vline_interrupt_state(struct amdgpu_device
*adev
,
3163 enum amdgpu_interrupt_state state
)
3165 u32 lb_interrupt_mask
;
3167 if (crtc
>= adev
->mode_info
.num_crtc
) {
3168 DRM_DEBUG("invalid crtc %d\n", crtc
);
3173 case AMDGPU_IRQ_STATE_DISABLE
:
3174 lb_interrupt_mask
= RREG32(mmLB_INTERRUPT_MASK
+ crtc_offsets
[crtc
]);
3175 lb_interrupt_mask
= REG_SET_FIELD(lb_interrupt_mask
, LB_INTERRUPT_MASK
,
3176 VLINE_INTERRUPT_MASK
, 0);
3177 WREG32(mmLB_INTERRUPT_MASK
+ crtc_offsets
[crtc
], lb_interrupt_mask
);
3179 case AMDGPU_IRQ_STATE_ENABLE
:
3180 lb_interrupt_mask
= RREG32(mmLB_INTERRUPT_MASK
+ crtc_offsets
[crtc
]);
3181 lb_interrupt_mask
= REG_SET_FIELD(lb_interrupt_mask
, LB_INTERRUPT_MASK
,
3182 VLINE_INTERRUPT_MASK
, 1);
3183 WREG32(mmLB_INTERRUPT_MASK
+ crtc_offsets
[crtc
], lb_interrupt_mask
);
3190 static int dce_v11_0_set_hpd_irq_state(struct amdgpu_device
*adev
,
3191 struct amdgpu_irq_src
*source
,
3193 enum amdgpu_interrupt_state state
)
3197 if (hpd
>= adev
->mode_info
.num_hpd
) {
3198 DRM_DEBUG("invalid hdp %d\n", hpd
);
3203 case AMDGPU_IRQ_STATE_DISABLE
:
3204 tmp
= RREG32(mmDC_HPD_INT_CONTROL
+ hpd_offsets
[hpd
]);
3205 tmp
= REG_SET_FIELD(tmp
, DC_HPD_INT_CONTROL
, DC_HPD_INT_EN
, 0);
3206 WREG32(mmDC_HPD_INT_CONTROL
+ hpd_offsets
[hpd
], tmp
);
3208 case AMDGPU_IRQ_STATE_ENABLE
:
3209 tmp
= RREG32(mmDC_HPD_INT_CONTROL
+ hpd_offsets
[hpd
]);
3210 tmp
= REG_SET_FIELD(tmp
, DC_HPD_INT_CONTROL
, DC_HPD_INT_EN
, 1);
3211 WREG32(mmDC_HPD_INT_CONTROL
+ hpd_offsets
[hpd
], tmp
);
3220 static int dce_v11_0_set_crtc_irq_state(struct amdgpu_device
*adev
,
3221 struct amdgpu_irq_src
*source
,
3223 enum amdgpu_interrupt_state state
)
3226 case AMDGPU_CRTC_IRQ_VBLANK1
:
3227 dce_v11_0_set_crtc_vblank_interrupt_state(adev
, 0, state
);
3229 case AMDGPU_CRTC_IRQ_VBLANK2
:
3230 dce_v11_0_set_crtc_vblank_interrupt_state(adev
, 1, state
);
3232 case AMDGPU_CRTC_IRQ_VBLANK3
:
3233 dce_v11_0_set_crtc_vblank_interrupt_state(adev
, 2, state
);
3235 case AMDGPU_CRTC_IRQ_VBLANK4
:
3236 dce_v11_0_set_crtc_vblank_interrupt_state(adev
, 3, state
);
3238 case AMDGPU_CRTC_IRQ_VBLANK5
:
3239 dce_v11_0_set_crtc_vblank_interrupt_state(adev
, 4, state
);
3241 case AMDGPU_CRTC_IRQ_VBLANK6
:
3242 dce_v11_0_set_crtc_vblank_interrupt_state(adev
, 5, state
);
3244 case AMDGPU_CRTC_IRQ_VLINE1
:
3245 dce_v11_0_set_crtc_vline_interrupt_state(adev
, 0, state
);
3247 case AMDGPU_CRTC_IRQ_VLINE2
:
3248 dce_v11_0_set_crtc_vline_interrupt_state(adev
, 1, state
);
3250 case AMDGPU_CRTC_IRQ_VLINE3
:
3251 dce_v11_0_set_crtc_vline_interrupt_state(adev
, 2, state
);
3253 case AMDGPU_CRTC_IRQ_VLINE4
:
3254 dce_v11_0_set_crtc_vline_interrupt_state(adev
, 3, state
);
3256 case AMDGPU_CRTC_IRQ_VLINE5
:
3257 dce_v11_0_set_crtc_vline_interrupt_state(adev
, 4, state
);
3259 case AMDGPU_CRTC_IRQ_VLINE6
:
3260 dce_v11_0_set_crtc_vline_interrupt_state(adev
, 5, state
);
3268 static int dce_v11_0_set_pageflip_irq_state(struct amdgpu_device
*adev
,
3269 struct amdgpu_irq_src
*src
,
3271 enum amdgpu_interrupt_state state
)
3274 /* now deal with page flip IRQ */
3276 case AMDGPU_PAGEFLIP_IRQ_D1
:
3277 reg_block
= CRTC0_REGISTER_OFFSET
;
3279 case AMDGPU_PAGEFLIP_IRQ_D2
:
3280 reg_block
= CRTC1_REGISTER_OFFSET
;
3282 case AMDGPU_PAGEFLIP_IRQ_D3
:
3283 reg_block
= CRTC2_REGISTER_OFFSET
;
3285 case AMDGPU_PAGEFLIP_IRQ_D4
:
3286 reg_block
= CRTC3_REGISTER_OFFSET
;
3288 case AMDGPU_PAGEFLIP_IRQ_D5
:
3289 reg_block
= CRTC4_REGISTER_OFFSET
;
3291 case AMDGPU_PAGEFLIP_IRQ_D6
:
3292 reg_block
= CRTC5_REGISTER_OFFSET
;
3295 DRM_ERROR("invalid pageflip crtc %d\n", type
);
3299 reg
= RREG32(mmGRPH_INTERRUPT_CONTROL
+ reg_block
);
3300 if (state
== AMDGPU_IRQ_STATE_DISABLE
)
3301 WREG32(mmGRPH_INTERRUPT_CONTROL
+ reg_block
, reg
& ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK
);
3303 WREG32(mmGRPH_INTERRUPT_CONTROL
+ reg_block
, reg
| GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK
);
3308 static int dce_v11_0_pageflip_irq(struct amdgpu_device
*adev
,
3309 struct amdgpu_irq_src
*source
,
3310 struct amdgpu_iv_entry
*entry
)
3313 unsigned long flags
;
3315 struct amdgpu_crtc
*amdgpu_crtc
;
3316 struct amdgpu_flip_work
*works
;
3318 crtc_id
= (entry
->src_id
- 8) >> 1;
3319 amdgpu_crtc
= adev
->mode_info
.crtcs
[crtc_id
];
3321 /* ack the interrupt */
3323 case AMDGPU_PAGEFLIP_IRQ_D1
:
3324 reg_block
= CRTC0_REGISTER_OFFSET
;
3326 case AMDGPU_PAGEFLIP_IRQ_D2
:
3327 reg_block
= CRTC1_REGISTER_OFFSET
;
3329 case AMDGPU_PAGEFLIP_IRQ_D3
:
3330 reg_block
= CRTC2_REGISTER_OFFSET
;
3332 case AMDGPU_PAGEFLIP_IRQ_D4
:
3333 reg_block
= CRTC3_REGISTER_OFFSET
;
3335 case AMDGPU_PAGEFLIP_IRQ_D5
:
3336 reg_block
= CRTC4_REGISTER_OFFSET
;
3338 case AMDGPU_PAGEFLIP_IRQ_D6
:
3339 reg_block
= CRTC5_REGISTER_OFFSET
;
3342 DRM_ERROR("invalid pageflip crtc %d\n", crtc_id
);
3346 if (RREG32(mmGRPH_INTERRUPT_STATUS
+ reg_block
) & GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK
)
3347 WREG32(mmGRPH_INTERRUPT_STATUS
+ reg_block
, GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK
);
3349 /* IRQ could occur when in initial stage */
3350 if(amdgpu_crtc
== NULL
)
3353 spin_lock_irqsave(&adev
->ddev
->event_lock
, flags
);
3354 works
= amdgpu_crtc
->pflip_works
;
3355 if (amdgpu_crtc
->pflip_status
!= AMDGPU_FLIP_SUBMITTED
){
3356 DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
3357 "AMDGPU_FLIP_SUBMITTED(%d)\n",
3358 amdgpu_crtc
->pflip_status
,
3359 AMDGPU_FLIP_SUBMITTED
);
3360 spin_unlock_irqrestore(&adev
->ddev
->event_lock
, flags
);
3364 /* page flip completed. clean up */
3365 amdgpu_crtc
->pflip_status
= AMDGPU_FLIP_NONE
;
3366 amdgpu_crtc
->pflip_works
= NULL
;
3368 /* wakeup usersapce */
3370 drm_send_vblank_event(adev
->ddev
, crtc_id
, works
->event
);
3372 spin_unlock_irqrestore(&adev
->ddev
->event_lock
, flags
);
3374 drm_vblank_put(adev
->ddev
, amdgpu_crtc
->crtc_id
);
3375 queue_work(amdgpu_crtc
->pflip_queue
, &works
->unpin_work
);
3380 static void dce_v11_0_hpd_int_ack(struct amdgpu_device
*adev
,
3385 if (hpd
>= adev
->mode_info
.num_hpd
) {
3386 DRM_DEBUG("invalid hdp %d\n", hpd
);
3390 tmp
= RREG32(mmDC_HPD_INT_CONTROL
+ hpd_offsets
[hpd
]);
3391 tmp
= REG_SET_FIELD(tmp
, DC_HPD_INT_CONTROL
, DC_HPD_INT_ACK
, 1);
3392 WREG32(mmDC_HPD_INT_CONTROL
+ hpd_offsets
[hpd
], tmp
);
3395 static void dce_v11_0_crtc_vblank_int_ack(struct amdgpu_device
*adev
,
3400 if (crtc
>= adev
->mode_info
.num_crtc
) {
3401 DRM_DEBUG("invalid crtc %d\n", crtc
);
3405 tmp
= RREG32(mmLB_VBLANK_STATUS
+ crtc_offsets
[crtc
]);
3406 tmp
= REG_SET_FIELD(tmp
, LB_VBLANK_STATUS
, VBLANK_ACK
, 1);
3407 WREG32(mmLB_VBLANK_STATUS
+ crtc_offsets
[crtc
], tmp
);
3410 static void dce_v11_0_crtc_vline_int_ack(struct amdgpu_device
*adev
,
3415 if (crtc
>= adev
->mode_info
.num_crtc
) {
3416 DRM_DEBUG("invalid crtc %d\n", crtc
);
3420 tmp
= RREG32(mmLB_VLINE_STATUS
+ crtc_offsets
[crtc
]);
3421 tmp
= REG_SET_FIELD(tmp
, LB_VLINE_STATUS
, VLINE_ACK
, 1);
3422 WREG32(mmLB_VLINE_STATUS
+ crtc_offsets
[crtc
], tmp
);
3425 static int dce_v11_0_crtc_irq(struct amdgpu_device
*adev
,
3426 struct amdgpu_irq_src
*source
,
3427 struct amdgpu_iv_entry
*entry
)
3429 unsigned crtc
= entry
->src_id
- 1;
3430 uint32_t disp_int
= RREG32(interrupt_status_offsets
[crtc
].reg
);
3431 unsigned irq_type
= amdgpu_crtc_idx_to_irq_type(adev
, crtc
);
3433 switch (entry
->src_data
) {
3434 case 0: /* vblank */
3435 if (disp_int
& interrupt_status_offsets
[crtc
].vblank
)
3436 dce_v11_0_crtc_vblank_int_ack(adev
, crtc
);
3438 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
3440 if (amdgpu_irq_enabled(adev
, source
, irq_type
)) {
3441 drm_handle_vblank(adev
->ddev
, crtc
);
3443 DRM_DEBUG("IH: D%d vblank\n", crtc
+ 1);
3447 if (disp_int
& interrupt_status_offsets
[crtc
].vline
)
3448 dce_v11_0_crtc_vline_int_ack(adev
, crtc
);
3450 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
3452 DRM_DEBUG("IH: D%d vline\n", crtc
+ 1);
3456 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry
->src_id
, entry
->src_data
);
3463 static int dce_v11_0_hpd_irq(struct amdgpu_device
*adev
,
3464 struct amdgpu_irq_src
*source
,
3465 struct amdgpu_iv_entry
*entry
)
3467 uint32_t disp_int
, mask
;
3470 if (entry
->src_data
>= adev
->mode_info
.num_hpd
) {
3471 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry
->src_id
, entry
->src_data
);
3475 hpd
= entry
->src_data
;
3476 disp_int
= RREG32(interrupt_status_offsets
[hpd
].reg
);
3477 mask
= interrupt_status_offsets
[hpd
].hpd
;
3479 if (disp_int
& mask
) {
3480 dce_v11_0_hpd_int_ack(adev
, hpd
);
3481 schedule_work(&adev
->hotplug_work
);
3482 DRM_DEBUG("IH: HPD%d\n", hpd
+ 1);
3488 static int dce_v11_0_set_clockgating_state(void *handle
,
3489 enum amd_clockgating_state state
)
3494 static int dce_v11_0_set_powergating_state(void *handle
,
3495 enum amd_powergating_state state
)
3500 const struct amd_ip_funcs dce_v11_0_ip_funcs
= {
3501 .early_init
= dce_v11_0_early_init
,
3503 .sw_init
= dce_v11_0_sw_init
,
3504 .sw_fini
= dce_v11_0_sw_fini
,
3505 .hw_init
= dce_v11_0_hw_init
,
3506 .hw_fini
= dce_v11_0_hw_fini
,
3507 .suspend
= dce_v11_0_suspend
,
3508 .resume
= dce_v11_0_resume
,
3509 .is_idle
= dce_v11_0_is_idle
,
3510 .wait_for_idle
= dce_v11_0_wait_for_idle
,
3511 .soft_reset
= dce_v11_0_soft_reset
,
3512 .print_status
= dce_v11_0_print_status
,
3513 .set_clockgating_state
= dce_v11_0_set_clockgating_state
,
3514 .set_powergating_state
= dce_v11_0_set_powergating_state
,
3518 dce_v11_0_encoder_mode_set(struct drm_encoder
*encoder
,
3519 struct drm_display_mode
*mode
,
3520 struct drm_display_mode
*adjusted_mode
)
3522 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3524 amdgpu_encoder
->pixel_clock
= adjusted_mode
->clock
;
3526 /* need to call this here rather than in prepare() since we need some crtc info */
3527 amdgpu_atombios_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
3529 /* set scaler clears this on some chips */
3530 dce_v11_0_set_interleave(encoder
->crtc
, mode
);
3532 if (amdgpu_atombios_encoder_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
) {
3533 dce_v11_0_afmt_enable(encoder
, true);
3534 dce_v11_0_afmt_setmode(encoder
, adjusted_mode
);
3538 static void dce_v11_0_encoder_prepare(struct drm_encoder
*encoder
)
3540 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
3541 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3542 struct drm_connector
*connector
= amdgpu_get_connector_for_encoder(encoder
);
3544 if ((amdgpu_encoder
->active_device
&
3545 (ATOM_DEVICE_DFP_SUPPORT
| ATOM_DEVICE_LCD_SUPPORT
)) ||
3546 (amdgpu_encoder_get_dp_bridge_encoder_id(encoder
) !=
3547 ENCODER_OBJECT_ID_NONE
)) {
3548 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
3550 dig
->dig_encoder
= dce_v11_0_pick_dig_encoder(encoder
);
3551 if (amdgpu_encoder
->active_device
& ATOM_DEVICE_DFP_SUPPORT
)
3552 dig
->afmt
= adev
->mode_info
.afmt
[dig
->dig_encoder
];
3556 amdgpu_atombios_scratch_regs_lock(adev
, true);
3559 struct amdgpu_connector
*amdgpu_connector
= to_amdgpu_connector(connector
);
3561 /* select the clock/data port if it uses a router */
3562 if (amdgpu_connector
->router
.cd_valid
)
3563 amdgpu_i2c_router_select_cd_port(amdgpu_connector
);
3565 /* turn eDP panel on for mode set */
3566 if (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)
3567 amdgpu_atombios_encoder_set_edp_panel_power(connector
,
3568 ATOM_TRANSMITTER_ACTION_POWER_ON
);
3571 /* this is needed for the pll/ss setup to work correctly in some cases */
3572 amdgpu_atombios_encoder_set_crtc_source(encoder
);
3573 /* set up the FMT blocks */
3574 dce_v11_0_program_fmt(encoder
);
3577 static void dce_v11_0_encoder_commit(struct drm_encoder
*encoder
)
3579 struct drm_device
*dev
= encoder
->dev
;
3580 struct amdgpu_device
*adev
= dev
->dev_private
;
3582 /* need to call this here as we need the crtc set up */
3583 amdgpu_atombios_encoder_dpms(encoder
, DRM_MODE_DPMS_ON
);
3584 amdgpu_atombios_scratch_regs_lock(adev
, false);
3587 static void dce_v11_0_encoder_disable(struct drm_encoder
*encoder
)
3589 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3590 struct amdgpu_encoder_atom_dig
*dig
;
3592 amdgpu_atombios_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
3594 if (amdgpu_atombios_encoder_is_digital(encoder
)) {
3595 if (amdgpu_atombios_encoder_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
)
3596 dce_v11_0_afmt_enable(encoder
, false);
3597 dig
= amdgpu_encoder
->enc_priv
;
3598 dig
->dig_encoder
= -1;
3600 amdgpu_encoder
->active_device
= 0;
3603 /* these are handled by the primary encoders */
3604 static void dce_v11_0_ext_prepare(struct drm_encoder
*encoder
)
3609 static void dce_v11_0_ext_commit(struct drm_encoder
*encoder
)
3615 dce_v11_0_ext_mode_set(struct drm_encoder
*encoder
,
3616 struct drm_display_mode
*mode
,
3617 struct drm_display_mode
*adjusted_mode
)
3622 static void dce_v11_0_ext_disable(struct drm_encoder
*encoder
)
3628 dce_v11_0_ext_dpms(struct drm_encoder
*encoder
, int mode
)
3633 static bool dce_v11_0_ext_mode_fixup(struct drm_encoder
*encoder
,
3634 const struct drm_display_mode
*mode
,
3635 struct drm_display_mode
*adjusted_mode
)
3640 static const struct drm_encoder_helper_funcs dce_v11_0_ext_helper_funcs
= {
3641 .dpms
= dce_v11_0_ext_dpms
,
3642 .mode_fixup
= dce_v11_0_ext_mode_fixup
,
3643 .prepare
= dce_v11_0_ext_prepare
,
3644 .mode_set
= dce_v11_0_ext_mode_set
,
3645 .commit
= dce_v11_0_ext_commit
,
3646 .disable
= dce_v11_0_ext_disable
,
3647 /* no detect for TMDS/LVDS yet */
3650 static const struct drm_encoder_helper_funcs dce_v11_0_dig_helper_funcs
= {
3651 .dpms
= amdgpu_atombios_encoder_dpms
,
3652 .mode_fixup
= amdgpu_atombios_encoder_mode_fixup
,
3653 .prepare
= dce_v11_0_encoder_prepare
,
3654 .mode_set
= dce_v11_0_encoder_mode_set
,
3655 .commit
= dce_v11_0_encoder_commit
,
3656 .disable
= dce_v11_0_encoder_disable
,
3657 .detect
= amdgpu_atombios_encoder_dig_detect
,
3660 static const struct drm_encoder_helper_funcs dce_v11_0_dac_helper_funcs
= {
3661 .dpms
= amdgpu_atombios_encoder_dpms
,
3662 .mode_fixup
= amdgpu_atombios_encoder_mode_fixup
,
3663 .prepare
= dce_v11_0_encoder_prepare
,
3664 .mode_set
= dce_v11_0_encoder_mode_set
,
3665 .commit
= dce_v11_0_encoder_commit
,
3666 .detect
= amdgpu_atombios_encoder_dac_detect
,
3669 static void dce_v11_0_encoder_destroy(struct drm_encoder
*encoder
)
3671 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3672 if (amdgpu_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
3673 amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder
);
3674 kfree(amdgpu_encoder
->enc_priv
);
3675 drm_encoder_cleanup(encoder
);
3676 kfree(amdgpu_encoder
);
3679 static const struct drm_encoder_funcs dce_v11_0_encoder_funcs
= {
3680 .destroy
= dce_v11_0_encoder_destroy
,
3683 static void dce_v11_0_encoder_add(struct amdgpu_device
*adev
,
3684 uint32_t encoder_enum
,
3685 uint32_t supported_device
,
3688 struct drm_device
*dev
= adev
->ddev
;
3689 struct drm_encoder
*encoder
;
3690 struct amdgpu_encoder
*amdgpu_encoder
;
3692 /* see if we already added it */
3693 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
3694 amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3695 if (amdgpu_encoder
->encoder_enum
== encoder_enum
) {
3696 amdgpu_encoder
->devices
|= supported_device
;
3703 amdgpu_encoder
= kzalloc(sizeof(struct amdgpu_encoder
), GFP_KERNEL
);
3704 if (!amdgpu_encoder
)
3707 encoder
= &amdgpu_encoder
->base
;
3708 switch (adev
->mode_info
.num_crtc
) {
3710 encoder
->possible_crtcs
= 0x1;
3714 encoder
->possible_crtcs
= 0x3;
3717 encoder
->possible_crtcs
= 0xf;
3720 encoder
->possible_crtcs
= 0x3f;
3724 amdgpu_encoder
->enc_priv
= NULL
;
3726 amdgpu_encoder
->encoder_enum
= encoder_enum
;
3727 amdgpu_encoder
->encoder_id
= (encoder_enum
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
3728 amdgpu_encoder
->devices
= supported_device
;
3729 amdgpu_encoder
->rmx_type
= RMX_OFF
;
3730 amdgpu_encoder
->underscan_type
= UNDERSCAN_OFF
;
3731 amdgpu_encoder
->is_ext_encoder
= false;
3732 amdgpu_encoder
->caps
= caps
;
3734 switch (amdgpu_encoder
->encoder_id
) {
3735 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
3736 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
3737 drm_encoder_init(dev
, encoder
, &dce_v11_0_encoder_funcs
,
3738 DRM_MODE_ENCODER_DAC
);
3739 drm_encoder_helper_add(encoder
, &dce_v11_0_dac_helper_funcs
);
3741 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
3742 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
3743 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
3744 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
3745 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3
:
3746 if (amdgpu_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
3747 amdgpu_encoder
->rmx_type
= RMX_FULL
;
3748 drm_encoder_init(dev
, encoder
, &dce_v11_0_encoder_funcs
,
3749 DRM_MODE_ENCODER_LVDS
);
3750 amdgpu_encoder
->enc_priv
= amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder
);
3751 } else if (amdgpu_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
)) {
3752 drm_encoder_init(dev
, encoder
, &dce_v11_0_encoder_funcs
,
3753 DRM_MODE_ENCODER_DAC
);
3754 amdgpu_encoder
->enc_priv
= amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder
);
3756 drm_encoder_init(dev
, encoder
, &dce_v11_0_encoder_funcs
,
3757 DRM_MODE_ENCODER_TMDS
);
3758 amdgpu_encoder
->enc_priv
= amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder
);
3760 drm_encoder_helper_add(encoder
, &dce_v11_0_dig_helper_funcs
);
3762 case ENCODER_OBJECT_ID_SI170B
:
3763 case ENCODER_OBJECT_ID_CH7303
:
3764 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA
:
3765 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB
:
3766 case ENCODER_OBJECT_ID_TITFP513
:
3767 case ENCODER_OBJECT_ID_VT1623
:
3768 case ENCODER_OBJECT_ID_HDMI_SI1930
:
3769 case ENCODER_OBJECT_ID_TRAVIS
:
3770 case ENCODER_OBJECT_ID_NUTMEG
:
3771 /* these are handled by the primary encoders */
3772 amdgpu_encoder
->is_ext_encoder
= true;
3773 if (amdgpu_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
3774 drm_encoder_init(dev
, encoder
, &dce_v11_0_encoder_funcs
,
3775 DRM_MODE_ENCODER_LVDS
);
3776 else if (amdgpu_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
))
3777 drm_encoder_init(dev
, encoder
, &dce_v11_0_encoder_funcs
,
3778 DRM_MODE_ENCODER_DAC
);
3780 drm_encoder_init(dev
, encoder
, &dce_v11_0_encoder_funcs
,
3781 DRM_MODE_ENCODER_TMDS
);
3782 drm_encoder_helper_add(encoder
, &dce_v11_0_ext_helper_funcs
);
3787 static const struct amdgpu_display_funcs dce_v11_0_display_funcs
= {
3788 .set_vga_render_state
= &dce_v11_0_set_vga_render_state
,
3789 .bandwidth_update
= &dce_v11_0_bandwidth_update
,
3790 .vblank_get_counter
= &dce_v11_0_vblank_get_counter
,
3791 .vblank_wait
= &dce_v11_0_vblank_wait
,
3792 .is_display_hung
= &dce_v11_0_is_display_hung
,
3793 .backlight_set_level
= &amdgpu_atombios_encoder_set_backlight_level
,
3794 .backlight_get_level
= &amdgpu_atombios_encoder_get_backlight_level
,
3795 .hpd_sense
= &dce_v11_0_hpd_sense
,
3796 .hpd_set_polarity
= &dce_v11_0_hpd_set_polarity
,
3797 .hpd_get_gpio_reg
= &dce_v11_0_hpd_get_gpio_reg
,
3798 .page_flip
= &dce_v11_0_page_flip
,
3799 .page_flip_get_scanoutpos
= &dce_v11_0_crtc_get_scanoutpos
,
3800 .add_encoder
= &dce_v11_0_encoder_add
,
3801 .add_connector
= &amdgpu_connector_add
,
3802 .stop_mc_access
= &dce_v11_0_stop_mc_access
,
3803 .resume_mc_access
= &dce_v11_0_resume_mc_access
,
3806 static void dce_v11_0_set_display_funcs(struct amdgpu_device
*adev
)
3808 if (adev
->mode_info
.funcs
== NULL
)
3809 adev
->mode_info
.funcs
= &dce_v11_0_display_funcs
;
3812 static const struct amdgpu_irq_src_funcs dce_v11_0_crtc_irq_funcs
= {
3813 .set
= dce_v11_0_set_crtc_irq_state
,
3814 .process
= dce_v11_0_crtc_irq
,
3817 static const struct amdgpu_irq_src_funcs dce_v11_0_pageflip_irq_funcs
= {
3818 .set
= dce_v11_0_set_pageflip_irq_state
,
3819 .process
= dce_v11_0_pageflip_irq
,
3822 static const struct amdgpu_irq_src_funcs dce_v11_0_hpd_irq_funcs
= {
3823 .set
= dce_v11_0_set_hpd_irq_state
,
3824 .process
= dce_v11_0_hpd_irq
,
3827 static void dce_v11_0_set_irq_funcs(struct amdgpu_device
*adev
)
3829 adev
->crtc_irq
.num_types
= AMDGPU_CRTC_IRQ_LAST
;
3830 adev
->crtc_irq
.funcs
= &dce_v11_0_crtc_irq_funcs
;
3832 adev
->pageflip_irq
.num_types
= AMDGPU_PAGEFLIP_IRQ_LAST
;
3833 adev
->pageflip_irq
.funcs
= &dce_v11_0_pageflip_irq_funcs
;
3835 adev
->hpd_irq
.num_types
= AMDGPU_HPD_LAST
;
3836 adev
->hpd_irq
.funcs
= &dce_v11_0_hpd_irq_funcs
;