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"
36 #include "dce/dce_8_0_d.h"
37 #include "dce/dce_8_0_sh_mask.h"
39 #include "gca/gfx_7_2_enum.h"
41 #include "gmc/gmc_7_1_d.h"
42 #include "gmc/gmc_7_1_sh_mask.h"
44 #include "oss/oss_2_0_d.h"
45 #include "oss/oss_2_0_sh_mask.h"
47 static void dce_v8_0_set_display_funcs(struct amdgpu_device
*adev
);
48 static void dce_v8_0_set_irq_funcs(struct amdgpu_device
*adev
);
50 static const u32 crtc_offsets
[6] =
52 CRTC0_REGISTER_OFFSET
,
53 CRTC1_REGISTER_OFFSET
,
54 CRTC2_REGISTER_OFFSET
,
55 CRTC3_REGISTER_OFFSET
,
56 CRTC4_REGISTER_OFFSET
,
60 static const u32 hpd_offsets
[] =
70 static const uint32_t dig_offsets
[] = {
71 CRTC0_REGISTER_OFFSET
,
72 CRTC1_REGISTER_OFFSET
,
73 CRTC2_REGISTER_OFFSET
,
74 CRTC3_REGISTER_OFFSET
,
75 CRTC4_REGISTER_OFFSET
,
76 CRTC5_REGISTER_OFFSET
,
77 (0x13830 - 0x7030) >> 2,
86 } interrupt_status_offsets
[6] = { {
87 .reg
= mmDISP_INTERRUPT_STATUS
,
88 .vblank
= DISP_INTERRUPT_STATUS__LB_D1_VBLANK_INTERRUPT_MASK
,
89 .vline
= DISP_INTERRUPT_STATUS__LB_D1_VLINE_INTERRUPT_MASK
,
90 .hpd
= DISP_INTERRUPT_STATUS__DC_HPD1_INTERRUPT_MASK
92 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE
,
93 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VBLANK_INTERRUPT_MASK
,
94 .vline
= DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VLINE_INTERRUPT_MASK
,
95 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE__DC_HPD2_INTERRUPT_MASK
97 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE2
,
98 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VBLANK_INTERRUPT_MASK
,
99 .vline
= DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VLINE_INTERRUPT_MASK
,
100 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE2__DC_HPD3_INTERRUPT_MASK
102 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE3
,
103 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VBLANK_INTERRUPT_MASK
,
104 .vline
= DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VLINE_INTERRUPT_MASK
,
105 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE3__DC_HPD4_INTERRUPT_MASK
107 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE4
,
108 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VBLANK_INTERRUPT_MASK
,
109 .vline
= DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VLINE_INTERRUPT_MASK
,
110 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE4__DC_HPD5_INTERRUPT_MASK
112 .reg
= mmDISP_INTERRUPT_STATUS_CONTINUE5
,
113 .vblank
= DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VBLANK_INTERRUPT_MASK
,
114 .vline
= DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VLINE_INTERRUPT_MASK
,
115 .hpd
= DISP_INTERRUPT_STATUS_CONTINUE5__DC_HPD6_INTERRUPT_MASK
118 static u32
dce_v8_0_audio_endpt_rreg(struct amdgpu_device
*adev
,
119 u32 block_offset
, u32 reg
)
124 spin_lock_irqsave(&adev
->audio_endpt_idx_lock
, flags
);
125 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX
+ block_offset
, reg
);
126 r
= RREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA
+ block_offset
);
127 spin_unlock_irqrestore(&adev
->audio_endpt_idx_lock
, flags
);
132 static void dce_v8_0_audio_endpt_wreg(struct amdgpu_device
*adev
,
133 u32 block_offset
, u32 reg
, u32 v
)
137 spin_lock_irqsave(&adev
->audio_endpt_idx_lock
, flags
);
138 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX
+ block_offset
, reg
);
139 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA
+ block_offset
, v
);
140 spin_unlock_irqrestore(&adev
->audio_endpt_idx_lock
, flags
);
143 static u32
dce_v8_0_vblank_get_counter(struct amdgpu_device
*adev
, int crtc
)
145 if (crtc
>= adev
->mode_info
.num_crtc
)
148 return RREG32(mmCRTC_STATUS_FRAME_COUNT
+ crtc_offsets
[crtc
]);
151 static void dce_v8_0_pageflip_interrupt_init(struct amdgpu_device
*adev
)
155 /* Enable pflip interrupts */
156 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++)
157 amdgpu_irq_get(adev
, &adev
->pageflip_irq
, i
);
160 static void dce_v8_0_pageflip_interrupt_fini(struct amdgpu_device
*adev
)
164 /* Disable pflip interrupts */
165 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++)
166 amdgpu_irq_put(adev
, &adev
->pageflip_irq
, i
);
170 * dce_v8_0_page_flip - pageflip callback.
172 * @adev: amdgpu_device pointer
173 * @crtc_id: crtc to cleanup pageflip on
174 * @crtc_base: new address of the crtc (GPU MC address)
176 * Triggers the actual pageflip by updating the primary
177 * surface base address.
179 static void dce_v8_0_page_flip(struct amdgpu_device
*adev
,
180 int crtc_id
, u64 crtc_base
, bool async
)
182 struct amdgpu_crtc
*amdgpu_crtc
= adev
->mode_info
.crtcs
[crtc_id
];
184 /* flip at hsync for async, default is vsync */
185 WREG32(mmGRPH_FLIP_CONTROL
+ amdgpu_crtc
->crtc_offset
, async
?
186 GRPH_FLIP_CONTROL__GRPH_SURFACE_UPDATE_H_RETRACE_EN_MASK
: 0);
187 /* update the primary scanout addresses */
188 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
189 upper_32_bits(crtc_base
));
190 /* writing to the low address triggers the update */
191 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
192 lower_32_bits(crtc_base
));
194 RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
);
197 static int dce_v8_0_crtc_get_scanoutpos(struct amdgpu_device
*adev
, int crtc
,
198 u32
*vbl
, u32
*position
)
200 if ((crtc
< 0) || (crtc
>= adev
->mode_info
.num_crtc
))
203 *vbl
= RREG32(mmCRTC_V_BLANK_START_END
+ crtc_offsets
[crtc
]);
204 *position
= RREG32(mmCRTC_STATUS_POSITION
+ crtc_offsets
[crtc
]);
210 * dce_v8_0_hpd_sense - hpd sense callback.
212 * @adev: amdgpu_device pointer
213 * @hpd: hpd (hotplug detect) pin
215 * Checks if a digital monitor is connected (evergreen+).
216 * Returns true if connected, false if not connected.
218 static bool dce_v8_0_hpd_sense(struct amdgpu_device
*adev
,
219 enum amdgpu_hpd_id hpd
)
221 bool connected
= false;
223 if (hpd
>= adev
->mode_info
.num_hpd
)
226 if (RREG32(mmDC_HPD1_INT_STATUS
+ hpd_offsets
[hpd
]) &
227 DC_HPD1_INT_STATUS__DC_HPD1_SENSE_MASK
)
234 * dce_v8_0_hpd_set_polarity - hpd set polarity callback.
236 * @adev: amdgpu_device pointer
237 * @hpd: hpd (hotplug detect) pin
239 * Set the polarity of the hpd pin (evergreen+).
241 static void dce_v8_0_hpd_set_polarity(struct amdgpu_device
*adev
,
242 enum amdgpu_hpd_id hpd
)
245 bool connected
= dce_v8_0_hpd_sense(adev
, hpd
);
247 if (hpd
>= adev
->mode_info
.num_hpd
)
250 tmp
= RREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[hpd
]);
252 tmp
&= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK
;
254 tmp
|= DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK
;
255 WREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[hpd
], tmp
);
259 * dce_v8_0_hpd_init - hpd setup callback.
261 * @adev: amdgpu_device pointer
263 * Setup the hpd pins used by the card (evergreen+).
264 * Enable the pin, set the polarity, and enable the hpd interrupts.
266 static void dce_v8_0_hpd_init(struct amdgpu_device
*adev
)
268 struct drm_device
*dev
= adev
->ddev
;
269 struct drm_connector
*connector
;
272 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
273 struct amdgpu_connector
*amdgpu_connector
= to_amdgpu_connector(connector
);
275 if (amdgpu_connector
->hpd
.hpd
>= adev
->mode_info
.num_hpd
)
278 tmp
= RREG32(mmDC_HPD1_CONTROL
+ hpd_offsets
[amdgpu_connector
->hpd
.hpd
]);
279 tmp
|= DC_HPD1_CONTROL__DC_HPD1_EN_MASK
;
280 WREG32(mmDC_HPD1_CONTROL
+ hpd_offsets
[amdgpu_connector
->hpd
.hpd
], tmp
);
282 if (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
||
283 connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
) {
284 /* don't try to enable hpd on eDP or LVDS avoid breaking the
285 * aux dp channel on imac and help (but not completely fix)
286 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
287 * also avoid interrupt storms during dpms.
289 tmp
= RREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[amdgpu_connector
->hpd
.hpd
]);
290 tmp
&= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK
;
291 WREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[amdgpu_connector
->hpd
.hpd
], tmp
);
295 dce_v8_0_hpd_set_polarity(adev
, amdgpu_connector
->hpd
.hpd
);
296 amdgpu_irq_get(adev
, &adev
->hpd_irq
, amdgpu_connector
->hpd
.hpd
);
301 * dce_v8_0_hpd_fini - hpd tear down callback.
303 * @adev: amdgpu_device pointer
305 * Tear down the hpd pins used by the card (evergreen+).
306 * Disable the hpd interrupts.
308 static void dce_v8_0_hpd_fini(struct amdgpu_device
*adev
)
310 struct drm_device
*dev
= adev
->ddev
;
311 struct drm_connector
*connector
;
314 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
315 struct amdgpu_connector
*amdgpu_connector
= to_amdgpu_connector(connector
);
317 if (amdgpu_connector
->hpd
.hpd
>= adev
->mode_info
.num_hpd
)
320 tmp
= RREG32(mmDC_HPD1_CONTROL
+ hpd_offsets
[amdgpu_connector
->hpd
.hpd
]);
321 tmp
&= ~DC_HPD1_CONTROL__DC_HPD1_EN_MASK
;
322 WREG32(mmDC_HPD1_CONTROL
+ hpd_offsets
[amdgpu_connector
->hpd
.hpd
], 0);
324 amdgpu_irq_put(adev
, &adev
->hpd_irq
, amdgpu_connector
->hpd
.hpd
);
328 static u32
dce_v8_0_hpd_get_gpio_reg(struct amdgpu_device
*adev
)
330 return mmDC_GPIO_HPD_A
;
333 static bool dce_v8_0_is_display_hung(struct amdgpu_device
*adev
)
339 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
340 if (RREG32(mmCRTC_CONTROL
+ crtc_offsets
[i
]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK
) {
341 crtc_status
[i
] = RREG32(mmCRTC_STATUS_HV_COUNT
+ crtc_offsets
[i
]);
342 crtc_hung
|= (1 << i
);
346 for (j
= 0; j
< 10; j
++) {
347 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
348 if (crtc_hung
& (1 << i
)) {
349 tmp
= RREG32(mmCRTC_STATUS_HV_COUNT
+ crtc_offsets
[i
]);
350 if (tmp
!= crtc_status
[i
])
351 crtc_hung
&= ~(1 << i
);
362 static void dce_v8_0_set_vga_render_state(struct amdgpu_device
*adev
,
367 /* Lockout access through VGA aperture*/
368 tmp
= RREG32(mmVGA_HDP_CONTROL
);
370 tmp
= REG_SET_FIELD(tmp
, VGA_HDP_CONTROL
, VGA_MEMORY_DISABLE
, 0);
372 tmp
= REG_SET_FIELD(tmp
, VGA_HDP_CONTROL
, VGA_MEMORY_DISABLE
, 1);
373 WREG32(mmVGA_HDP_CONTROL
, tmp
);
375 /* disable VGA render */
376 tmp
= RREG32(mmVGA_RENDER_CONTROL
);
378 tmp
= REG_SET_FIELD(tmp
, VGA_RENDER_CONTROL
, VGA_VSTATUS_CNTL
, 1);
380 tmp
= REG_SET_FIELD(tmp
, VGA_RENDER_CONTROL
, VGA_VSTATUS_CNTL
, 0);
381 WREG32(mmVGA_RENDER_CONTROL
, tmp
);
384 static int dce_v8_0_get_num_crtc(struct amdgpu_device
*adev
)
388 switch (adev
->asic_type
) {
406 void dce_v8_0_disable_dce(struct amdgpu_device
*adev
)
408 /*Disable VGA render and enabled crtc, if has DCE engine*/
409 if (amdgpu_atombios_has_dce_engine_info(adev
)) {
413 dce_v8_0_set_vga_render_state(adev
, false);
416 for (i
= 0; i
< dce_v8_0_get_num_crtc(adev
); i
++) {
417 crtc_enabled
= REG_GET_FIELD(RREG32(mmCRTC_CONTROL
+ crtc_offsets
[i
]),
418 CRTC_CONTROL
, CRTC_MASTER_EN
);
420 WREG32(mmCRTC_UPDATE_LOCK
+ crtc_offsets
[i
], 1);
421 tmp
= RREG32(mmCRTC_CONTROL
+ crtc_offsets
[i
]);
422 tmp
= REG_SET_FIELD(tmp
, CRTC_CONTROL
, CRTC_MASTER_EN
, 0);
423 WREG32(mmCRTC_CONTROL
+ crtc_offsets
[i
], tmp
);
424 WREG32(mmCRTC_UPDATE_LOCK
+ crtc_offsets
[i
], 0);
430 static void dce_v8_0_program_fmt(struct drm_encoder
*encoder
)
432 struct drm_device
*dev
= encoder
->dev
;
433 struct amdgpu_device
*adev
= dev
->dev_private
;
434 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
435 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(encoder
->crtc
);
436 struct drm_connector
*connector
= amdgpu_get_connector_for_encoder(encoder
);
439 enum amdgpu_connector_dither dither
= AMDGPU_FMT_DITHER_DISABLE
;
442 struct amdgpu_connector
*amdgpu_connector
= to_amdgpu_connector(connector
);
443 bpc
= amdgpu_connector_get_monitor_bpc(connector
);
444 dither
= amdgpu_connector
->dither
;
447 /* LVDS/eDP FMT is set up by atom */
448 if (amdgpu_encoder
->devices
& ATOM_DEVICE_LCD_SUPPORT
)
451 /* not needed for analog */
452 if ((amdgpu_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
) ||
453 (amdgpu_encoder
->encoder_id
== ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
))
461 if (dither
== AMDGPU_FMT_DITHER_ENABLE
)
462 /* XXX sort out optimal dither settings */
463 tmp
|= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK
|
464 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK
|
465 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK
|
466 (0 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT
));
468 tmp
|= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK
|
469 (0 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT
));
472 if (dither
== AMDGPU_FMT_DITHER_ENABLE
)
473 /* XXX sort out optimal dither settings */
474 tmp
|= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK
|
475 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK
|
476 FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK
|
477 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK
|
478 (1 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT
));
480 tmp
|= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK
|
481 (1 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT
));
484 if (dither
== AMDGPU_FMT_DITHER_ENABLE
)
485 /* XXX sort out optimal dither settings */
486 tmp
|= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK
|
487 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK
|
488 FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK
|
489 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK
|
490 (2 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT
));
492 tmp
|= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK
|
493 (2 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT
));
500 WREG32(mmFMT_BIT_DEPTH_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
504 /* display watermark setup */
506 * dce_v8_0_line_buffer_adjust - Set up the line buffer
508 * @adev: amdgpu_device pointer
509 * @amdgpu_crtc: the selected display controller
510 * @mode: the current display mode on the selected display
513 * Setup up the line buffer allocation for
514 * the selected display controller (CIK).
515 * Returns the line buffer size in pixels.
517 static u32
dce_v8_0_line_buffer_adjust(struct amdgpu_device
*adev
,
518 struct amdgpu_crtc
*amdgpu_crtc
,
519 struct drm_display_mode
*mode
)
521 u32 tmp
, buffer_alloc
, i
;
522 u32 pipe_offset
= amdgpu_crtc
->crtc_id
* 0x8;
525 * There are 6 line buffers, one for each display controllers.
526 * There are 3 partitions per LB. Select the number of partitions
527 * to enable based on the display width. For display widths larger
528 * than 4096, you need use to use 2 display controllers and combine
529 * them using the stereo blender.
531 if (amdgpu_crtc
->base
.enabled
&& mode
) {
532 if (mode
->crtc_hdisplay
< 1920) {
535 } else if (mode
->crtc_hdisplay
< 2560) {
538 } else if (mode
->crtc_hdisplay
< 4096) {
540 buffer_alloc
= (adev
->flags
& AMD_IS_APU
) ? 2 : 4;
542 DRM_DEBUG_KMS("Mode too big for LB!\n");
544 buffer_alloc
= (adev
->flags
& AMD_IS_APU
) ? 2 : 4;
551 WREG32(mmLB_MEMORY_CTRL
+ amdgpu_crtc
->crtc_offset
,
552 (tmp
<< LB_MEMORY_CTRL__LB_MEMORY_CONFIG__SHIFT
) |
553 (0x6B0 << LB_MEMORY_CTRL__LB_MEMORY_SIZE__SHIFT
));
555 WREG32(mmPIPE0_DMIF_BUFFER_CONTROL
+ pipe_offset
,
556 (buffer_alloc
<< PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATED__SHIFT
));
557 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
558 if (RREG32(mmPIPE0_DMIF_BUFFER_CONTROL
+ pipe_offset
) &
559 PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATION_COMPLETED_MASK
)
564 if (amdgpu_crtc
->base
.enabled
&& mode
) {
576 /* controller not enabled, so no lb used */
581 * cik_get_number_of_dram_channels - get the number of dram channels
583 * @adev: amdgpu_device pointer
585 * Look up the number of video ram channels (CIK).
586 * Used for display watermark bandwidth calculations
587 * Returns the number of dram channels
589 static u32
cik_get_number_of_dram_channels(struct amdgpu_device
*adev
)
591 u32 tmp
= RREG32(mmMC_SHARED_CHMAP
);
593 switch ((tmp
& MC_SHARED_CHMAP__NOOFCHAN_MASK
) >> MC_SHARED_CHMAP__NOOFCHAN__SHIFT
) {
616 struct dce8_wm_params
{
617 u32 dram_channels
; /* number of dram channels */
618 u32 yclk
; /* bandwidth per dram data pin in kHz */
619 u32 sclk
; /* engine clock in kHz */
620 u32 disp_clk
; /* display clock in kHz */
621 u32 src_width
; /* viewport width */
622 u32 active_time
; /* active display time in ns */
623 u32 blank_time
; /* blank time in ns */
624 bool interlaced
; /* mode is interlaced */
625 fixed20_12 vsc
; /* vertical scale ratio */
626 u32 num_heads
; /* number of active crtcs */
627 u32 bytes_per_pixel
; /* bytes per pixel display + overlay */
628 u32 lb_size
; /* line buffer allocated to pipe */
629 u32 vtaps
; /* vertical scaler taps */
633 * dce_v8_0_dram_bandwidth - get the dram bandwidth
635 * @wm: watermark calculation data
637 * Calculate the raw dram bandwidth (CIK).
638 * Used for display watermark bandwidth calculations
639 * Returns the dram bandwidth in MBytes/s
641 static u32
dce_v8_0_dram_bandwidth(struct dce8_wm_params
*wm
)
643 /* Calculate raw DRAM Bandwidth */
644 fixed20_12 dram_efficiency
; /* 0.7 */
645 fixed20_12 yclk
, dram_channels
, bandwidth
;
648 a
.full
= dfixed_const(1000);
649 yclk
.full
= dfixed_const(wm
->yclk
);
650 yclk
.full
= dfixed_div(yclk
, a
);
651 dram_channels
.full
= dfixed_const(wm
->dram_channels
* 4);
652 a
.full
= dfixed_const(10);
653 dram_efficiency
.full
= dfixed_const(7);
654 dram_efficiency
.full
= dfixed_div(dram_efficiency
, a
);
655 bandwidth
.full
= dfixed_mul(dram_channels
, yclk
);
656 bandwidth
.full
= dfixed_mul(bandwidth
, dram_efficiency
);
658 return dfixed_trunc(bandwidth
);
662 * dce_v8_0_dram_bandwidth_for_display - get the dram bandwidth for display
664 * @wm: watermark calculation data
666 * Calculate the dram bandwidth used for display (CIK).
667 * Used for display watermark bandwidth calculations
668 * Returns the dram bandwidth for display in MBytes/s
670 static u32
dce_v8_0_dram_bandwidth_for_display(struct dce8_wm_params
*wm
)
672 /* Calculate DRAM Bandwidth and the part allocated to display. */
673 fixed20_12 disp_dram_allocation
; /* 0.3 to 0.7 */
674 fixed20_12 yclk
, dram_channels
, bandwidth
;
677 a
.full
= dfixed_const(1000);
678 yclk
.full
= dfixed_const(wm
->yclk
);
679 yclk
.full
= dfixed_div(yclk
, a
);
680 dram_channels
.full
= dfixed_const(wm
->dram_channels
* 4);
681 a
.full
= dfixed_const(10);
682 disp_dram_allocation
.full
= dfixed_const(3); /* XXX worse case value 0.3 */
683 disp_dram_allocation
.full
= dfixed_div(disp_dram_allocation
, a
);
684 bandwidth
.full
= dfixed_mul(dram_channels
, yclk
);
685 bandwidth
.full
= dfixed_mul(bandwidth
, disp_dram_allocation
);
687 return dfixed_trunc(bandwidth
);
691 * dce_v8_0_data_return_bandwidth - get the data return bandwidth
693 * @wm: watermark calculation data
695 * Calculate the data return bandwidth used for display (CIK).
696 * Used for display watermark bandwidth calculations
697 * Returns the data return bandwidth in MBytes/s
699 static u32
dce_v8_0_data_return_bandwidth(struct dce8_wm_params
*wm
)
701 /* Calculate the display Data return Bandwidth */
702 fixed20_12 return_efficiency
; /* 0.8 */
703 fixed20_12 sclk
, bandwidth
;
706 a
.full
= dfixed_const(1000);
707 sclk
.full
= dfixed_const(wm
->sclk
);
708 sclk
.full
= dfixed_div(sclk
, a
);
709 a
.full
= dfixed_const(10);
710 return_efficiency
.full
= dfixed_const(8);
711 return_efficiency
.full
= dfixed_div(return_efficiency
, a
);
712 a
.full
= dfixed_const(32);
713 bandwidth
.full
= dfixed_mul(a
, sclk
);
714 bandwidth
.full
= dfixed_mul(bandwidth
, return_efficiency
);
716 return dfixed_trunc(bandwidth
);
720 * dce_v8_0_dmif_request_bandwidth - get the dmif bandwidth
722 * @wm: watermark calculation data
724 * Calculate the dmif bandwidth used for display (CIK).
725 * Used for display watermark bandwidth calculations
726 * Returns the dmif bandwidth in MBytes/s
728 static u32
dce_v8_0_dmif_request_bandwidth(struct dce8_wm_params
*wm
)
730 /* Calculate the DMIF Request Bandwidth */
731 fixed20_12 disp_clk_request_efficiency
; /* 0.8 */
732 fixed20_12 disp_clk
, bandwidth
;
735 a
.full
= dfixed_const(1000);
736 disp_clk
.full
= dfixed_const(wm
->disp_clk
);
737 disp_clk
.full
= dfixed_div(disp_clk
, a
);
738 a
.full
= dfixed_const(32);
739 b
.full
= dfixed_mul(a
, disp_clk
);
741 a
.full
= dfixed_const(10);
742 disp_clk_request_efficiency
.full
= dfixed_const(8);
743 disp_clk_request_efficiency
.full
= dfixed_div(disp_clk_request_efficiency
, a
);
745 bandwidth
.full
= dfixed_mul(b
, disp_clk_request_efficiency
);
747 return dfixed_trunc(bandwidth
);
751 * dce_v8_0_available_bandwidth - get the min available bandwidth
753 * @wm: watermark calculation data
755 * Calculate the min available bandwidth used for display (CIK).
756 * Used for display watermark bandwidth calculations
757 * Returns the min available bandwidth in MBytes/s
759 static u32
dce_v8_0_available_bandwidth(struct dce8_wm_params
*wm
)
761 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
762 u32 dram_bandwidth
= dce_v8_0_dram_bandwidth(wm
);
763 u32 data_return_bandwidth
= dce_v8_0_data_return_bandwidth(wm
);
764 u32 dmif_req_bandwidth
= dce_v8_0_dmif_request_bandwidth(wm
);
766 return min(dram_bandwidth
, min(data_return_bandwidth
, dmif_req_bandwidth
));
770 * dce_v8_0_average_bandwidth - get the average available bandwidth
772 * @wm: watermark calculation data
774 * Calculate the average available bandwidth used for display (CIK).
775 * Used for display watermark bandwidth calculations
776 * Returns the average available bandwidth in MBytes/s
778 static u32
dce_v8_0_average_bandwidth(struct dce8_wm_params
*wm
)
780 /* Calculate the display mode Average Bandwidth
781 * DisplayMode should contain the source and destination dimensions,
785 fixed20_12 line_time
;
786 fixed20_12 src_width
;
787 fixed20_12 bandwidth
;
790 a
.full
= dfixed_const(1000);
791 line_time
.full
= dfixed_const(wm
->active_time
+ wm
->blank_time
);
792 line_time
.full
= dfixed_div(line_time
, a
);
793 bpp
.full
= dfixed_const(wm
->bytes_per_pixel
);
794 src_width
.full
= dfixed_const(wm
->src_width
);
795 bandwidth
.full
= dfixed_mul(src_width
, bpp
);
796 bandwidth
.full
= dfixed_mul(bandwidth
, wm
->vsc
);
797 bandwidth
.full
= dfixed_div(bandwidth
, line_time
);
799 return dfixed_trunc(bandwidth
);
803 * dce_v8_0_latency_watermark - get the latency watermark
805 * @wm: watermark calculation data
807 * Calculate the latency watermark (CIK).
808 * Used for display watermark bandwidth calculations
809 * Returns the latency watermark in ns
811 static u32
dce_v8_0_latency_watermark(struct dce8_wm_params
*wm
)
813 /* First calculate the latency in ns */
814 u32 mc_latency
= 2000; /* 2000 ns. */
815 u32 available_bandwidth
= dce_v8_0_available_bandwidth(wm
);
816 u32 worst_chunk_return_time
= (512 * 8 * 1000) / available_bandwidth
;
817 u32 cursor_line_pair_return_time
= (128 * 4 * 1000) / available_bandwidth
;
818 u32 dc_latency
= 40000000 / wm
->disp_clk
; /* dc pipe latency */
819 u32 other_heads_data_return_time
= ((wm
->num_heads
+ 1) * worst_chunk_return_time
) +
820 (wm
->num_heads
* cursor_line_pair_return_time
);
821 u32 latency
= mc_latency
+ other_heads_data_return_time
+ dc_latency
;
822 u32 max_src_lines_per_dst_line
, lb_fill_bw
, line_fill_time
;
823 u32 tmp
, dmif_size
= 12288;
826 if (wm
->num_heads
== 0)
829 a
.full
= dfixed_const(2);
830 b
.full
= dfixed_const(1);
831 if ((wm
->vsc
.full
> a
.full
) ||
832 ((wm
->vsc
.full
> b
.full
) && (wm
->vtaps
>= 3)) ||
834 ((wm
->vsc
.full
>= a
.full
) && wm
->interlaced
))
835 max_src_lines_per_dst_line
= 4;
837 max_src_lines_per_dst_line
= 2;
839 a
.full
= dfixed_const(available_bandwidth
);
840 b
.full
= dfixed_const(wm
->num_heads
);
841 a
.full
= dfixed_div(a
, b
);
842 tmp
= div_u64((u64
) dmif_size
* (u64
) wm
->disp_clk
, mc_latency
+ 512);
843 tmp
= min(dfixed_trunc(a
), tmp
);
845 lb_fill_bw
= min(tmp
, wm
->disp_clk
* wm
->bytes_per_pixel
/ 1000);
847 a
.full
= dfixed_const(max_src_lines_per_dst_line
* wm
->src_width
* wm
->bytes_per_pixel
);
848 b
.full
= dfixed_const(1000);
849 c
.full
= dfixed_const(lb_fill_bw
);
850 b
.full
= dfixed_div(c
, b
);
851 a
.full
= dfixed_div(a
, b
);
852 line_fill_time
= dfixed_trunc(a
);
854 if (line_fill_time
< wm
->active_time
)
857 return latency
+ (line_fill_time
- wm
->active_time
);
862 * dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display - check
863 * average and available dram bandwidth
865 * @wm: watermark calculation data
867 * Check if the display average bandwidth fits in the display
868 * dram bandwidth (CIK).
869 * Used for display watermark bandwidth calculations
870 * Returns true if the display fits, false if not.
872 static bool dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params
*wm
)
874 if (dce_v8_0_average_bandwidth(wm
) <=
875 (dce_v8_0_dram_bandwidth_for_display(wm
) / wm
->num_heads
))
882 * dce_v8_0_average_bandwidth_vs_available_bandwidth - check
883 * average and available bandwidth
885 * @wm: watermark calculation data
887 * Check if the display average bandwidth fits in the display
888 * available bandwidth (CIK).
889 * Used for display watermark bandwidth calculations
890 * Returns true if the display fits, false if not.
892 static bool dce_v8_0_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params
*wm
)
894 if (dce_v8_0_average_bandwidth(wm
) <=
895 (dce_v8_0_available_bandwidth(wm
) / wm
->num_heads
))
902 * dce_v8_0_check_latency_hiding - check latency hiding
904 * @wm: watermark calculation data
906 * Check latency hiding (CIK).
907 * Used for display watermark bandwidth calculations
908 * Returns true if the display fits, false if not.
910 static bool dce_v8_0_check_latency_hiding(struct dce8_wm_params
*wm
)
912 u32 lb_partitions
= wm
->lb_size
/ wm
->src_width
;
913 u32 line_time
= wm
->active_time
+ wm
->blank_time
;
914 u32 latency_tolerant_lines
;
918 a
.full
= dfixed_const(1);
919 if (wm
->vsc
.full
> a
.full
)
920 latency_tolerant_lines
= 1;
922 if (lb_partitions
<= (wm
->vtaps
+ 1))
923 latency_tolerant_lines
= 1;
925 latency_tolerant_lines
= 2;
928 latency_hiding
= (latency_tolerant_lines
* line_time
+ wm
->blank_time
);
930 if (dce_v8_0_latency_watermark(wm
) <= latency_hiding
)
937 * dce_v8_0_program_watermarks - program display watermarks
939 * @adev: amdgpu_device pointer
940 * @amdgpu_crtc: the selected display controller
941 * @lb_size: line buffer size
942 * @num_heads: number of display controllers in use
944 * Calculate and program the display watermarks for the
945 * selected display controller (CIK).
947 static void dce_v8_0_program_watermarks(struct amdgpu_device
*adev
,
948 struct amdgpu_crtc
*amdgpu_crtc
,
949 u32 lb_size
, u32 num_heads
)
951 struct drm_display_mode
*mode
= &amdgpu_crtc
->base
.mode
;
952 struct dce8_wm_params wm_low
, wm_high
;
955 u32 latency_watermark_a
= 0, latency_watermark_b
= 0;
956 u32 tmp
, wm_mask
, lb_vblank_lead_lines
= 0;
958 if (amdgpu_crtc
->base
.enabled
&& num_heads
&& mode
) {
959 active_time
= (u32
) div_u64((u64
)mode
->crtc_hdisplay
* 1000000,
961 line_time
= (u32
) div_u64((u64
)mode
->crtc_htotal
* 1000000,
963 line_time
= min(line_time
, (u32
)65535);
965 /* watermark for high clocks */
966 if (adev
->pm
.dpm_enabled
) {
968 amdgpu_dpm_get_mclk(adev
, false) * 10;
970 amdgpu_dpm_get_sclk(adev
, false) * 10;
972 wm_high
.yclk
= adev
->pm
.current_mclk
* 10;
973 wm_high
.sclk
= adev
->pm
.current_sclk
* 10;
976 wm_high
.disp_clk
= mode
->clock
;
977 wm_high
.src_width
= mode
->crtc_hdisplay
;
978 wm_high
.active_time
= active_time
;
979 wm_high
.blank_time
= line_time
- wm_high
.active_time
;
980 wm_high
.interlaced
= false;
981 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
982 wm_high
.interlaced
= true;
983 wm_high
.vsc
= amdgpu_crtc
->vsc
;
985 if (amdgpu_crtc
->rmx_type
!= RMX_OFF
)
987 wm_high
.bytes_per_pixel
= 4; /* XXX: get this from fb config */
988 wm_high
.lb_size
= lb_size
;
989 wm_high
.dram_channels
= cik_get_number_of_dram_channels(adev
);
990 wm_high
.num_heads
= num_heads
;
992 /* set for high clocks */
993 latency_watermark_a
= min(dce_v8_0_latency_watermark(&wm_high
), (u32
)65535);
995 /* possibly force display priority to high */
996 /* should really do this at mode validation time... */
997 if (!dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high
) ||
998 !dce_v8_0_average_bandwidth_vs_available_bandwidth(&wm_high
) ||
999 !dce_v8_0_check_latency_hiding(&wm_high
) ||
1000 (adev
->mode_info
.disp_priority
== 2)) {
1001 DRM_DEBUG_KMS("force priority to high\n");
1004 /* watermark for low clocks */
1005 if (adev
->pm
.dpm_enabled
) {
1007 amdgpu_dpm_get_mclk(adev
, true) * 10;
1009 amdgpu_dpm_get_sclk(adev
, true) * 10;
1011 wm_low
.yclk
= adev
->pm
.current_mclk
* 10;
1012 wm_low
.sclk
= adev
->pm
.current_sclk
* 10;
1015 wm_low
.disp_clk
= mode
->clock
;
1016 wm_low
.src_width
= mode
->crtc_hdisplay
;
1017 wm_low
.active_time
= active_time
;
1018 wm_low
.blank_time
= line_time
- wm_low
.active_time
;
1019 wm_low
.interlaced
= false;
1020 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1021 wm_low
.interlaced
= true;
1022 wm_low
.vsc
= amdgpu_crtc
->vsc
;
1024 if (amdgpu_crtc
->rmx_type
!= RMX_OFF
)
1026 wm_low
.bytes_per_pixel
= 4; /* XXX: get this from fb config */
1027 wm_low
.lb_size
= lb_size
;
1028 wm_low
.dram_channels
= cik_get_number_of_dram_channels(adev
);
1029 wm_low
.num_heads
= num_heads
;
1031 /* set for low clocks */
1032 latency_watermark_b
= min(dce_v8_0_latency_watermark(&wm_low
), (u32
)65535);
1034 /* possibly force display priority to high */
1035 /* should really do this at mode validation time... */
1036 if (!dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low
) ||
1037 !dce_v8_0_average_bandwidth_vs_available_bandwidth(&wm_low
) ||
1038 !dce_v8_0_check_latency_hiding(&wm_low
) ||
1039 (adev
->mode_info
.disp_priority
== 2)) {
1040 DRM_DEBUG_KMS("force priority to high\n");
1042 lb_vblank_lead_lines
= DIV_ROUND_UP(lb_size
, mode
->crtc_hdisplay
);
1046 wm_mask
= RREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
);
1048 tmp
&= ~(3 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT
);
1049 tmp
|= (1 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT
);
1050 WREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
1051 WREG32(mmDPG_PIPE_URGENCY_CONTROL
+ amdgpu_crtc
->crtc_offset
,
1052 ((latency_watermark_a
<< DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT
) |
1053 (line_time
<< DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT
)));
1055 tmp
= RREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
);
1056 tmp
&= ~(3 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT
);
1057 tmp
|= (2 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT
);
1058 WREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
, tmp
);
1059 WREG32(mmDPG_PIPE_URGENCY_CONTROL
+ amdgpu_crtc
->crtc_offset
,
1060 ((latency_watermark_b
<< DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT
) |
1061 (line_time
<< DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT
)));
1062 /* restore original selection */
1063 WREG32(mmDPG_WATERMARK_MASK_CONTROL
+ amdgpu_crtc
->crtc_offset
, wm_mask
);
1065 /* save values for DPM */
1066 amdgpu_crtc
->line_time
= line_time
;
1067 amdgpu_crtc
->wm_high
= latency_watermark_a
;
1068 amdgpu_crtc
->wm_low
= latency_watermark_b
;
1069 /* Save number of lines the linebuffer leads before the scanout */
1070 amdgpu_crtc
->lb_vblank_lead_lines
= lb_vblank_lead_lines
;
1074 * dce_v8_0_bandwidth_update - program display watermarks
1076 * @adev: amdgpu_device pointer
1078 * Calculate and program the display watermarks and line
1079 * buffer allocation (CIK).
1081 static void dce_v8_0_bandwidth_update(struct amdgpu_device
*adev
)
1083 struct drm_display_mode
*mode
= NULL
;
1084 u32 num_heads
= 0, lb_size
;
1087 amdgpu_display_update_priority(adev
);
1089 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
1090 if (adev
->mode_info
.crtcs
[i
]->base
.enabled
)
1093 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
1094 mode
= &adev
->mode_info
.crtcs
[i
]->base
.mode
;
1095 lb_size
= dce_v8_0_line_buffer_adjust(adev
, adev
->mode_info
.crtcs
[i
], mode
);
1096 dce_v8_0_program_watermarks(adev
, adev
->mode_info
.crtcs
[i
],
1097 lb_size
, num_heads
);
1101 static void dce_v8_0_audio_get_connected_pins(struct amdgpu_device
*adev
)
1106 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
1107 offset
= adev
->mode_info
.audio
.pin
[i
].offset
;
1108 tmp
= RREG32_AUDIO_ENDPT(offset
,
1109 ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT
);
1111 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY_MASK
) >>
1112 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY__SHIFT
) == 1)
1113 adev
->mode_info
.audio
.pin
[i
].connected
= false;
1115 adev
->mode_info
.audio
.pin
[i
].connected
= true;
1119 static struct amdgpu_audio_pin
*dce_v8_0_audio_get_pin(struct amdgpu_device
*adev
)
1123 dce_v8_0_audio_get_connected_pins(adev
);
1125 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
1126 if (adev
->mode_info
.audio
.pin
[i
].connected
)
1127 return &adev
->mode_info
.audio
.pin
[i
];
1129 DRM_ERROR("No connected audio pins found!\n");
1133 static void dce_v8_0_afmt_audio_select_pin(struct drm_encoder
*encoder
)
1135 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
1136 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1137 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1140 if (!dig
|| !dig
->afmt
|| !dig
->afmt
->pin
)
1143 offset
= dig
->afmt
->offset
;
1145 WREG32(mmAFMT_AUDIO_SRC_CONTROL
+ offset
,
1146 (dig
->afmt
->pin
->id
<< AFMT_AUDIO_SRC_CONTROL__AFMT_AUDIO_SRC_SELECT__SHIFT
));
1149 static void dce_v8_0_audio_write_latency_fields(struct drm_encoder
*encoder
,
1150 struct drm_display_mode
*mode
)
1152 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
1153 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1154 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1155 struct drm_connector
*connector
;
1156 struct amdgpu_connector
*amdgpu_connector
= NULL
;
1157 u32 tmp
= 0, offset
;
1159 if (!dig
|| !dig
->afmt
|| !dig
->afmt
->pin
)
1162 offset
= dig
->afmt
->pin
->offset
;
1164 list_for_each_entry(connector
, &encoder
->dev
->mode_config
.connector_list
, head
) {
1165 if (connector
->encoder
== encoder
) {
1166 amdgpu_connector
= to_amdgpu_connector(connector
);
1171 if (!amdgpu_connector
) {
1172 DRM_ERROR("Couldn't find encoder's connector\n");
1176 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
1177 if (connector
->latency_present
[1])
1179 (connector
->video_latency
[1] <<
1180 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT
) |
1181 (connector
->audio_latency
[1] <<
1182 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT
);
1186 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT
) |
1188 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT
);
1190 if (connector
->latency_present
[0])
1192 (connector
->video_latency
[0] <<
1193 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT
) |
1194 (connector
->audio_latency
[0] <<
1195 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT
);
1199 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT
) |
1201 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT
);
1204 WREG32_AUDIO_ENDPT(offset
, ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC
, tmp
);
1207 static void dce_v8_0_audio_write_speaker_allocation(struct drm_encoder
*encoder
)
1209 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
1210 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1211 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1212 struct drm_connector
*connector
;
1213 struct amdgpu_connector
*amdgpu_connector
= NULL
;
1218 if (!dig
|| !dig
->afmt
|| !dig
->afmt
->pin
)
1221 offset
= dig
->afmt
->pin
->offset
;
1223 list_for_each_entry(connector
, &encoder
->dev
->mode_config
.connector_list
, head
) {
1224 if (connector
->encoder
== encoder
) {
1225 amdgpu_connector
= to_amdgpu_connector(connector
);
1230 if (!amdgpu_connector
) {
1231 DRM_ERROR("Couldn't find encoder's connector\n");
1235 sad_count
= drm_edid_to_speaker_allocation(amdgpu_connector_edid(connector
), &sadb
);
1236 if (sad_count
< 0) {
1237 DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count
);
1241 /* program the speaker allocation */
1242 tmp
= RREG32_AUDIO_ENDPT(offset
, ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER
);
1243 tmp
&= ~(AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__DP_CONNECTION_MASK
|
1244 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION_MASK
);
1246 tmp
|= AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__HDMI_CONNECTION_MASK
;
1248 tmp
|= (sadb
[0] << AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION__SHIFT
);
1250 tmp
|= (5 << AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION__SHIFT
); /* stereo */
1251 WREG32_AUDIO_ENDPT(offset
, ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER
, tmp
);
1256 static void dce_v8_0_audio_write_sad_regs(struct drm_encoder
*encoder
)
1258 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
1259 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1260 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1262 struct drm_connector
*connector
;
1263 struct amdgpu_connector
*amdgpu_connector
= NULL
;
1264 struct cea_sad
*sads
;
1267 static const u16 eld_reg_to_type
[][2] = {
1268 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0
, HDMI_AUDIO_CODING_TYPE_PCM
},
1269 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR1
, HDMI_AUDIO_CODING_TYPE_AC3
},
1270 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR2
, HDMI_AUDIO_CODING_TYPE_MPEG1
},
1271 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR3
, HDMI_AUDIO_CODING_TYPE_MP3
},
1272 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR4
, HDMI_AUDIO_CODING_TYPE_MPEG2
},
1273 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR5
, HDMI_AUDIO_CODING_TYPE_AAC_LC
},
1274 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR6
, HDMI_AUDIO_CODING_TYPE_DTS
},
1275 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR7
, HDMI_AUDIO_CODING_TYPE_ATRAC
},
1276 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR9
, HDMI_AUDIO_CODING_TYPE_EAC3
},
1277 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR10
, HDMI_AUDIO_CODING_TYPE_DTS_HD
},
1278 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR11
, HDMI_AUDIO_CODING_TYPE_MLP
},
1279 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR13
, HDMI_AUDIO_CODING_TYPE_WMA_PRO
},
1282 if (!dig
|| !dig
->afmt
|| !dig
->afmt
->pin
)
1285 offset
= dig
->afmt
->pin
->offset
;
1287 list_for_each_entry(connector
, &encoder
->dev
->mode_config
.connector_list
, head
) {
1288 if (connector
->encoder
== encoder
) {
1289 amdgpu_connector
= to_amdgpu_connector(connector
);
1294 if (!amdgpu_connector
) {
1295 DRM_ERROR("Couldn't find encoder's connector\n");
1299 sad_count
= drm_edid_to_sad(amdgpu_connector_edid(connector
), &sads
);
1300 if (sad_count
<= 0) {
1301 DRM_ERROR("Couldn't read SADs: %d\n", sad_count
);
1306 for (i
= 0; i
< ARRAY_SIZE(eld_reg_to_type
); i
++) {
1308 u8 stereo_freqs
= 0;
1309 int max_channels
= -1;
1312 for (j
= 0; j
< sad_count
; j
++) {
1313 struct cea_sad
*sad
= &sads
[j
];
1315 if (sad
->format
== eld_reg_to_type
[i
][1]) {
1316 if (sad
->channels
> max_channels
) {
1317 value
= (sad
->channels
<<
1318 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__MAX_CHANNELS__SHIFT
) |
1320 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__DESCRIPTOR_BYTE_2__SHIFT
) |
1322 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES__SHIFT
);
1323 max_channels
= sad
->channels
;
1326 if (sad
->format
== HDMI_AUDIO_CODING_TYPE_PCM
)
1327 stereo_freqs
|= sad
->freq
;
1333 value
|= (stereo_freqs
<<
1334 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES_STEREO__SHIFT
);
1336 WREG32_AUDIO_ENDPT(offset
, eld_reg_to_type
[i
][0], value
);
1342 static void dce_v8_0_audio_enable(struct amdgpu_device
*adev
,
1343 struct amdgpu_audio_pin
*pin
,
1349 WREG32_AUDIO_ENDPT(pin
->offset
, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL
,
1350 enable
? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK
: 0);
1353 static const u32 pin_offsets
[7] =
1364 static int dce_v8_0_audio_init(struct amdgpu_device
*adev
)
1371 adev
->mode_info
.audio
.enabled
= true;
1373 if (adev
->asic_type
== CHIP_KAVERI
) /* KV: 4 streams, 7 endpoints */
1374 adev
->mode_info
.audio
.num_pins
= 7;
1375 else if ((adev
->asic_type
== CHIP_KABINI
) ||
1376 (adev
->asic_type
== CHIP_MULLINS
)) /* KB/ML: 2 streams, 3 endpoints */
1377 adev
->mode_info
.audio
.num_pins
= 3;
1378 else if ((adev
->asic_type
== CHIP_BONAIRE
) ||
1379 (adev
->asic_type
== CHIP_HAWAII
))/* BN/HW: 6 streams, 7 endpoints */
1380 adev
->mode_info
.audio
.num_pins
= 7;
1382 adev
->mode_info
.audio
.num_pins
= 3;
1384 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
1385 adev
->mode_info
.audio
.pin
[i
].channels
= -1;
1386 adev
->mode_info
.audio
.pin
[i
].rate
= -1;
1387 adev
->mode_info
.audio
.pin
[i
].bits_per_sample
= -1;
1388 adev
->mode_info
.audio
.pin
[i
].status_bits
= 0;
1389 adev
->mode_info
.audio
.pin
[i
].category_code
= 0;
1390 adev
->mode_info
.audio
.pin
[i
].connected
= false;
1391 adev
->mode_info
.audio
.pin
[i
].offset
= pin_offsets
[i
];
1392 adev
->mode_info
.audio
.pin
[i
].id
= i
;
1393 /* disable audio. it will be set up later */
1394 /* XXX remove once we switch to ip funcs */
1395 dce_v8_0_audio_enable(adev
, &adev
->mode_info
.audio
.pin
[i
], false);
1401 static void dce_v8_0_audio_fini(struct amdgpu_device
*adev
)
1408 if (!adev
->mode_info
.audio
.enabled
)
1411 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++)
1412 dce_v8_0_audio_enable(adev
, &adev
->mode_info
.audio
.pin
[i
], false);
1414 adev
->mode_info
.audio
.enabled
= false;
1418 * update the N and CTS parameters for a given pixel clock rate
1420 static void dce_v8_0_afmt_update_ACR(struct drm_encoder
*encoder
, uint32_t clock
)
1422 struct drm_device
*dev
= encoder
->dev
;
1423 struct amdgpu_device
*adev
= dev
->dev_private
;
1424 struct amdgpu_afmt_acr acr
= amdgpu_afmt_acr(clock
);
1425 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1426 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1427 uint32_t offset
= dig
->afmt
->offset
;
1429 WREG32(mmHDMI_ACR_32_0
+ offset
, (acr
.cts_32khz
<< HDMI_ACR_32_0__HDMI_ACR_CTS_32__SHIFT
));
1430 WREG32(mmHDMI_ACR_32_1
+ offset
, acr
.n_32khz
);
1432 WREG32(mmHDMI_ACR_44_0
+ offset
, (acr
.cts_44_1khz
<< HDMI_ACR_44_0__HDMI_ACR_CTS_44__SHIFT
));
1433 WREG32(mmHDMI_ACR_44_1
+ offset
, acr
.n_44_1khz
);
1435 WREG32(mmHDMI_ACR_48_0
+ offset
, (acr
.cts_48khz
<< HDMI_ACR_48_0__HDMI_ACR_CTS_48__SHIFT
));
1436 WREG32(mmHDMI_ACR_48_1
+ offset
, acr
.n_48khz
);
1440 * build a HDMI Video Info Frame
1442 static void dce_v8_0_afmt_update_avi_infoframe(struct drm_encoder
*encoder
,
1443 void *buffer
, size_t size
)
1445 struct drm_device
*dev
= encoder
->dev
;
1446 struct amdgpu_device
*adev
= dev
->dev_private
;
1447 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1448 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1449 uint32_t offset
= dig
->afmt
->offset
;
1450 uint8_t *frame
= buffer
+ 3;
1451 uint8_t *header
= buffer
;
1453 WREG32(mmAFMT_AVI_INFO0
+ offset
,
1454 frame
[0x0] | (frame
[0x1] << 8) | (frame
[0x2] << 16) | (frame
[0x3] << 24));
1455 WREG32(mmAFMT_AVI_INFO1
+ offset
,
1456 frame
[0x4] | (frame
[0x5] << 8) | (frame
[0x6] << 16) | (frame
[0x7] << 24));
1457 WREG32(mmAFMT_AVI_INFO2
+ offset
,
1458 frame
[0x8] | (frame
[0x9] << 8) | (frame
[0xA] << 16) | (frame
[0xB] << 24));
1459 WREG32(mmAFMT_AVI_INFO3
+ offset
,
1460 frame
[0xC] | (frame
[0xD] << 8) | (header
[1] << 24));
1463 static void dce_v8_0_audio_set_dto(struct drm_encoder
*encoder
, u32 clock
)
1465 struct drm_device
*dev
= encoder
->dev
;
1466 struct amdgpu_device
*adev
= dev
->dev_private
;
1467 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1468 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1469 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(encoder
->crtc
);
1470 u32 dto_phase
= 24 * 1000;
1471 u32 dto_modulo
= clock
;
1473 if (!dig
|| !dig
->afmt
)
1476 /* XXX two dtos; generally use dto0 for hdmi */
1477 /* Express [24MHz / target pixel clock] as an exact rational
1478 * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
1479 * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
1481 WREG32(mmDCCG_AUDIO_DTO_SOURCE
, (amdgpu_crtc
->crtc_id
<< DCCG_AUDIO_DTO_SOURCE__DCCG_AUDIO_DTO0_SOURCE_SEL__SHIFT
));
1482 WREG32(mmDCCG_AUDIO_DTO0_PHASE
, dto_phase
);
1483 WREG32(mmDCCG_AUDIO_DTO0_MODULE
, dto_modulo
);
1487 * update the info frames with the data from the current display mode
1489 static void dce_v8_0_afmt_setmode(struct drm_encoder
*encoder
,
1490 struct drm_display_mode
*mode
)
1492 struct drm_device
*dev
= encoder
->dev
;
1493 struct amdgpu_device
*adev
= dev
->dev_private
;
1494 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1495 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1496 struct drm_connector
*connector
= amdgpu_get_connector_for_encoder(encoder
);
1497 u8 buffer
[HDMI_INFOFRAME_HEADER_SIZE
+ HDMI_AVI_INFOFRAME_SIZE
];
1498 struct hdmi_avi_infoframe frame
;
1499 uint32_t offset
, val
;
1503 if (!dig
|| !dig
->afmt
)
1506 /* Silent, r600_hdmi_enable will raise WARN for us */
1507 if (!dig
->afmt
->enabled
)
1510 offset
= dig
->afmt
->offset
;
1512 /* hdmi deep color mode general control packets setup, if bpc > 8 */
1513 if (encoder
->crtc
) {
1514 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(encoder
->crtc
);
1515 bpc
= amdgpu_crtc
->bpc
;
1518 /* disable audio prior to setting up hw */
1519 dig
->afmt
->pin
= dce_v8_0_audio_get_pin(adev
);
1520 dce_v8_0_audio_enable(adev
, dig
->afmt
->pin
, false);
1522 dce_v8_0_audio_set_dto(encoder
, mode
->clock
);
1524 WREG32(mmHDMI_VBI_PACKET_CONTROL
+ offset
,
1525 HDMI_VBI_PACKET_CONTROL__HDMI_NULL_SEND_MASK
); /* send null packets when required */
1527 WREG32(mmAFMT_AUDIO_CRC_CONTROL
+ offset
, 0x1000);
1529 val
= RREG32(mmHDMI_CONTROL
+ offset
);
1530 val
&= ~HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK
;
1531 val
&= ~HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH_MASK
;
1539 DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n",
1540 connector
->name
, bpc
);
1543 val
|= HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK
;
1544 val
|= 1 << HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH__SHIFT
;
1545 DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n",
1549 val
|= HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK
;
1550 val
|= 2 << HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH__SHIFT
;
1551 DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n",
1556 WREG32(mmHDMI_CONTROL
+ offset
, val
);
1558 WREG32(mmHDMI_VBI_PACKET_CONTROL
+ offset
,
1559 HDMI_VBI_PACKET_CONTROL__HDMI_NULL_SEND_MASK
| /* send null packets when required */
1560 HDMI_VBI_PACKET_CONTROL__HDMI_GC_SEND_MASK
| /* send general control packets */
1561 HDMI_VBI_PACKET_CONTROL__HDMI_GC_CONT_MASK
); /* send general control packets every frame */
1563 WREG32(mmHDMI_INFOFRAME_CONTROL0
+ offset
,
1564 HDMI_INFOFRAME_CONTROL0__HDMI_AUDIO_INFO_SEND_MASK
| /* enable audio info frames (frames won't be set until audio is enabled) */
1565 HDMI_INFOFRAME_CONTROL0__HDMI_AUDIO_INFO_CONT_MASK
); /* required for audio info values to be updated */
1567 WREG32(mmAFMT_INFOFRAME_CONTROL0
+ offset
,
1568 AFMT_INFOFRAME_CONTROL0__AFMT_AUDIO_INFO_UPDATE_MASK
); /* required for audio info values to be updated */
1570 WREG32(mmHDMI_INFOFRAME_CONTROL1
+ offset
,
1571 (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AUDIO_INFO_LINE__SHIFT
)); /* anything other than 0 */
1573 WREG32(mmHDMI_GC
+ offset
, 0); /* unset HDMI_GC_AVMUTE */
1575 WREG32(mmHDMI_AUDIO_PACKET_CONTROL
+ offset
,
1576 (1 << HDMI_AUDIO_PACKET_CONTROL__HDMI_AUDIO_DELAY_EN__SHIFT
) | /* set the default audio delay */
1577 (3 << HDMI_AUDIO_PACKET_CONTROL__HDMI_AUDIO_PACKETS_PER_LINE__SHIFT
)); /* should be suffient for all audio modes and small enough for all hblanks */
1579 WREG32(mmAFMT_AUDIO_PACKET_CONTROL
+ offset
,
1580 AFMT_AUDIO_PACKET_CONTROL__AFMT_60958_CS_UPDATE_MASK
); /* allow 60958 channel status fields to be updated */
1582 /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
1585 WREG32(mmHDMI_ACR_PACKET_CONTROL
+ offset
,
1586 HDMI_ACR_PACKET_CONTROL__HDMI_ACR_AUTO_SEND_MASK
); /* allow hw to sent ACR packets when required */
1588 WREG32(mmHDMI_ACR_PACKET_CONTROL
+ offset
,
1589 HDMI_ACR_PACKET_CONTROL__HDMI_ACR_SOURCE_MASK
| /* select SW CTS value */
1590 HDMI_ACR_PACKET_CONTROL__HDMI_ACR_AUTO_SEND_MASK
); /* allow hw to sent ACR packets when required */
1592 dce_v8_0_afmt_update_ACR(encoder
, mode
->clock
);
1594 WREG32(mmAFMT_60958_0
+ offset
,
1595 (1 << AFMT_60958_0__AFMT_60958_CS_CHANNEL_NUMBER_L__SHIFT
));
1597 WREG32(mmAFMT_60958_1
+ offset
,
1598 (2 << AFMT_60958_1__AFMT_60958_CS_CHANNEL_NUMBER_R__SHIFT
));
1600 WREG32(mmAFMT_60958_2
+ offset
,
1601 (3 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_2__SHIFT
) |
1602 (4 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_3__SHIFT
) |
1603 (5 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_4__SHIFT
) |
1604 (6 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_5__SHIFT
) |
1605 (7 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_6__SHIFT
) |
1606 (8 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_7__SHIFT
));
1608 dce_v8_0_audio_write_speaker_allocation(encoder
);
1611 WREG32(mmAFMT_AUDIO_PACKET_CONTROL2
+ offset
,
1612 (0xff << AFMT_AUDIO_PACKET_CONTROL2__AFMT_AUDIO_CHANNEL_ENABLE__SHIFT
));
1614 dce_v8_0_afmt_audio_select_pin(encoder
);
1615 dce_v8_0_audio_write_sad_regs(encoder
);
1616 dce_v8_0_audio_write_latency_fields(encoder
, mode
);
1618 err
= drm_hdmi_avi_infoframe_from_display_mode(&frame
, mode
, false);
1620 DRM_ERROR("failed to setup AVI infoframe: %zd\n", err
);
1624 err
= hdmi_avi_infoframe_pack(&frame
, buffer
, sizeof(buffer
));
1626 DRM_ERROR("failed to pack AVI infoframe: %zd\n", err
);
1630 dce_v8_0_afmt_update_avi_infoframe(encoder
, buffer
, sizeof(buffer
));
1632 WREG32_OR(mmHDMI_INFOFRAME_CONTROL0
+ offset
,
1633 HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_SEND_MASK
| /* enable AVI info frames */
1634 HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_CONT_MASK
); /* required for audio info values to be updated */
1636 WREG32_P(mmHDMI_INFOFRAME_CONTROL1
+ offset
,
1637 (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE__SHIFT
), /* anything other than 0 */
1638 ~HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE_MASK
);
1640 WREG32_OR(mmAFMT_AUDIO_PACKET_CONTROL
+ offset
,
1641 AFMT_AUDIO_PACKET_CONTROL__AFMT_AUDIO_SAMPLE_SEND_MASK
); /* send audio packets */
1643 WREG32(mmAFMT_RAMP_CONTROL0
+ offset
, 0x00FFFFFF);
1644 WREG32(mmAFMT_RAMP_CONTROL1
+ offset
, 0x007FFFFF);
1645 WREG32(mmAFMT_RAMP_CONTROL2
+ offset
, 0x00000001);
1646 WREG32(mmAFMT_RAMP_CONTROL3
+ offset
, 0x00000001);
1648 /* enable audio after setting up hw */
1649 dce_v8_0_audio_enable(adev
, dig
->afmt
->pin
, true);
1652 static void dce_v8_0_afmt_enable(struct drm_encoder
*encoder
, bool enable
)
1654 struct drm_device
*dev
= encoder
->dev
;
1655 struct amdgpu_device
*adev
= dev
->dev_private
;
1656 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
1657 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
1659 if (!dig
|| !dig
->afmt
)
1662 /* Silent, r600_hdmi_enable will raise WARN for us */
1663 if (enable
&& dig
->afmt
->enabled
)
1665 if (!enable
&& !dig
->afmt
->enabled
)
1668 if (!enable
&& dig
->afmt
->pin
) {
1669 dce_v8_0_audio_enable(adev
, dig
->afmt
->pin
, false);
1670 dig
->afmt
->pin
= NULL
;
1673 dig
->afmt
->enabled
= enable
;
1675 DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
1676 enable
? "En" : "Dis", dig
->afmt
->offset
, amdgpu_encoder
->encoder_id
);
1679 static int dce_v8_0_afmt_init(struct amdgpu_device
*adev
)
1683 for (i
= 0; i
< adev
->mode_info
.num_dig
; i
++)
1684 adev
->mode_info
.afmt
[i
] = NULL
;
1686 /* DCE8 has audio blocks tied to DIG encoders */
1687 for (i
= 0; i
< adev
->mode_info
.num_dig
; i
++) {
1688 adev
->mode_info
.afmt
[i
] = kzalloc(sizeof(struct amdgpu_afmt
), GFP_KERNEL
);
1689 if (adev
->mode_info
.afmt
[i
]) {
1690 adev
->mode_info
.afmt
[i
]->offset
= dig_offsets
[i
];
1691 adev
->mode_info
.afmt
[i
]->id
= i
;
1694 for (j
= 0; j
< i
; j
++) {
1695 kfree(adev
->mode_info
.afmt
[j
]);
1696 adev
->mode_info
.afmt
[j
] = NULL
;
1704 static void dce_v8_0_afmt_fini(struct amdgpu_device
*adev
)
1708 for (i
= 0; i
< adev
->mode_info
.num_dig
; i
++) {
1709 kfree(adev
->mode_info
.afmt
[i
]);
1710 adev
->mode_info
.afmt
[i
] = NULL
;
1714 static const u32 vga_control_regs
[6] =
1724 static void dce_v8_0_vga_enable(struct drm_crtc
*crtc
, bool enable
)
1726 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
1727 struct drm_device
*dev
= crtc
->dev
;
1728 struct amdgpu_device
*adev
= dev
->dev_private
;
1731 vga_control
= RREG32(vga_control_regs
[amdgpu_crtc
->crtc_id
]) & ~1;
1733 WREG32(vga_control_regs
[amdgpu_crtc
->crtc_id
], vga_control
| 1);
1735 WREG32(vga_control_regs
[amdgpu_crtc
->crtc_id
], vga_control
);
1738 static void dce_v8_0_grph_enable(struct drm_crtc
*crtc
, bool enable
)
1740 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
1741 struct drm_device
*dev
= crtc
->dev
;
1742 struct amdgpu_device
*adev
= dev
->dev_private
;
1745 WREG32(mmGRPH_ENABLE
+ amdgpu_crtc
->crtc_offset
, 1);
1747 WREG32(mmGRPH_ENABLE
+ amdgpu_crtc
->crtc_offset
, 0);
1750 static int dce_v8_0_crtc_do_set_base(struct drm_crtc
*crtc
,
1751 struct drm_framebuffer
*fb
,
1752 int x
, int y
, int atomic
)
1754 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
1755 struct drm_device
*dev
= crtc
->dev
;
1756 struct amdgpu_device
*adev
= dev
->dev_private
;
1757 struct drm_framebuffer
*target_fb
;
1758 struct drm_gem_object
*obj
;
1759 struct amdgpu_bo
*abo
;
1760 uint64_t fb_location
, tiling_flags
;
1761 uint32_t fb_format
, fb_pitch_pixels
;
1762 u32 fb_swap
= (GRPH_ENDIAN_NONE
<< GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT
);
1764 u32 viewport_w
, viewport_h
;
1766 bool bypass_lut
= false;
1767 struct drm_format_name_buf format_name
;
1770 if (!atomic
&& !crtc
->primary
->fb
) {
1771 DRM_DEBUG_KMS("No FB bound\n");
1778 target_fb
= crtc
->primary
->fb
;
1780 /* If atomic, assume fb object is pinned & idle & fenced and
1781 * just update base pointers
1783 obj
= target_fb
->obj
[0];
1784 abo
= gem_to_amdgpu_bo(obj
);
1785 r
= amdgpu_bo_reserve(abo
, false);
1786 if (unlikely(r
!= 0))
1790 r
= amdgpu_bo_pin(abo
, AMDGPU_GEM_DOMAIN_VRAM
);
1791 if (unlikely(r
!= 0)) {
1792 amdgpu_bo_unreserve(abo
);
1796 fb_location
= amdgpu_bo_gpu_offset(abo
);
1798 amdgpu_bo_get_tiling_flags(abo
, &tiling_flags
);
1799 amdgpu_bo_unreserve(abo
);
1801 pipe_config
= AMDGPU_TILING_GET(tiling_flags
, PIPE_CONFIG
);
1803 switch (target_fb
->format
->format
) {
1805 fb_format
= ((GRPH_DEPTH_8BPP
<< GRPH_CONTROL__GRPH_DEPTH__SHIFT
) |
1806 (GRPH_FORMAT_INDEXED
<< GRPH_CONTROL__GRPH_FORMAT__SHIFT
));
1808 case DRM_FORMAT_XRGB4444
:
1809 case DRM_FORMAT_ARGB4444
:
1810 fb_format
= ((GRPH_DEPTH_16BPP
<< GRPH_CONTROL__GRPH_DEPTH__SHIFT
) |
1811 (GRPH_FORMAT_ARGB4444
<< GRPH_CONTROL__GRPH_FORMAT__SHIFT
));
1813 fb_swap
= (GRPH_ENDIAN_8IN16
<< GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT
);
1816 case DRM_FORMAT_XRGB1555
:
1817 case DRM_FORMAT_ARGB1555
:
1818 fb_format
= ((GRPH_DEPTH_16BPP
<< GRPH_CONTROL__GRPH_DEPTH__SHIFT
) |
1819 (GRPH_FORMAT_ARGB1555
<< GRPH_CONTROL__GRPH_FORMAT__SHIFT
));
1821 fb_swap
= (GRPH_ENDIAN_8IN16
<< GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT
);
1824 case DRM_FORMAT_BGRX5551
:
1825 case DRM_FORMAT_BGRA5551
:
1826 fb_format
= ((GRPH_DEPTH_16BPP
<< GRPH_CONTROL__GRPH_DEPTH__SHIFT
) |
1827 (GRPH_FORMAT_BGRA5551
<< GRPH_CONTROL__GRPH_FORMAT__SHIFT
));
1829 fb_swap
= (GRPH_ENDIAN_8IN16
<< GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT
);
1832 case DRM_FORMAT_RGB565
:
1833 fb_format
= ((GRPH_DEPTH_16BPP
<< GRPH_CONTROL__GRPH_DEPTH__SHIFT
) |
1834 (GRPH_FORMAT_ARGB565
<< GRPH_CONTROL__GRPH_FORMAT__SHIFT
));
1836 fb_swap
= (GRPH_ENDIAN_8IN16
<< GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT
);
1839 case DRM_FORMAT_XRGB8888
:
1840 case DRM_FORMAT_ARGB8888
:
1841 fb_format
= ((GRPH_DEPTH_32BPP
<< GRPH_CONTROL__GRPH_DEPTH__SHIFT
) |
1842 (GRPH_FORMAT_ARGB8888
<< GRPH_CONTROL__GRPH_FORMAT__SHIFT
));
1844 fb_swap
= (GRPH_ENDIAN_8IN32
<< GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT
);
1847 case DRM_FORMAT_XRGB2101010
:
1848 case DRM_FORMAT_ARGB2101010
:
1849 fb_format
= ((GRPH_DEPTH_32BPP
<< GRPH_CONTROL__GRPH_DEPTH__SHIFT
) |
1850 (GRPH_FORMAT_ARGB2101010
<< GRPH_CONTROL__GRPH_FORMAT__SHIFT
));
1852 fb_swap
= (GRPH_ENDIAN_8IN32
<< GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT
);
1854 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
1857 case DRM_FORMAT_BGRX1010102
:
1858 case DRM_FORMAT_BGRA1010102
:
1859 fb_format
= ((GRPH_DEPTH_32BPP
<< GRPH_CONTROL__GRPH_DEPTH__SHIFT
) |
1860 (GRPH_FORMAT_BGRA1010102
<< GRPH_CONTROL__GRPH_FORMAT__SHIFT
));
1862 fb_swap
= (GRPH_ENDIAN_8IN32
<< GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT
);
1864 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
1868 DRM_ERROR("Unsupported screen format %s\n",
1869 drm_get_format_name(target_fb
->format
->format
, &format_name
));
1873 if (AMDGPU_TILING_GET(tiling_flags
, ARRAY_MODE
) == ARRAY_2D_TILED_THIN1
) {
1874 unsigned bankw
, bankh
, mtaspect
, tile_split
, num_banks
;
1876 bankw
= AMDGPU_TILING_GET(tiling_flags
, BANK_WIDTH
);
1877 bankh
= AMDGPU_TILING_GET(tiling_flags
, BANK_HEIGHT
);
1878 mtaspect
= AMDGPU_TILING_GET(tiling_flags
, MACRO_TILE_ASPECT
);
1879 tile_split
= AMDGPU_TILING_GET(tiling_flags
, TILE_SPLIT
);
1880 num_banks
= AMDGPU_TILING_GET(tiling_flags
, NUM_BANKS
);
1882 fb_format
|= (num_banks
<< GRPH_CONTROL__GRPH_NUM_BANKS__SHIFT
);
1883 fb_format
|= (GRPH_ARRAY_2D_TILED_THIN1
<< GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT
);
1884 fb_format
|= (tile_split
<< GRPH_CONTROL__GRPH_TILE_SPLIT__SHIFT
);
1885 fb_format
|= (bankw
<< GRPH_CONTROL__GRPH_BANK_WIDTH__SHIFT
);
1886 fb_format
|= (bankh
<< GRPH_CONTROL__GRPH_BANK_HEIGHT__SHIFT
);
1887 fb_format
|= (mtaspect
<< GRPH_CONTROL__GRPH_MACRO_TILE_ASPECT__SHIFT
);
1888 fb_format
|= (DISPLAY_MICRO_TILING
<< GRPH_CONTROL__GRPH_MICRO_TILE_MODE__SHIFT
);
1889 } else if (AMDGPU_TILING_GET(tiling_flags
, ARRAY_MODE
) == ARRAY_1D_TILED_THIN1
) {
1890 fb_format
|= (GRPH_ARRAY_1D_TILED_THIN1
<< GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT
);
1893 fb_format
|= (pipe_config
<< GRPH_CONTROL__GRPH_PIPE_CONFIG__SHIFT
);
1895 dce_v8_0_vga_enable(crtc
, false);
1897 /* Make sure surface address is updated at vertical blank rather than
1900 WREG32(mmGRPH_FLIP_CONTROL
+ amdgpu_crtc
->crtc_offset
, 0);
1902 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
1903 upper_32_bits(fb_location
));
1904 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
1905 upper_32_bits(fb_location
));
1906 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
1907 (u32
)fb_location
& GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK
);
1908 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
1909 (u32
) fb_location
& GRPH_SECONDARY_SURFACE_ADDRESS__GRPH_SECONDARY_SURFACE_ADDRESS_MASK
);
1910 WREG32(mmGRPH_CONTROL
+ amdgpu_crtc
->crtc_offset
, fb_format
);
1911 WREG32(mmGRPH_SWAP_CNTL
+ amdgpu_crtc
->crtc_offset
, fb_swap
);
1914 * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
1915 * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
1916 * retain the full precision throughout the pipeline.
1918 WREG32_P(mmGRPH_LUT_10BIT_BYPASS_CONTROL
+ amdgpu_crtc
->crtc_offset
,
1919 (bypass_lut
? LUT_10BIT_BYPASS_EN
: 0),
1920 ~LUT_10BIT_BYPASS_EN
);
1923 DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
1925 WREG32(mmGRPH_SURFACE_OFFSET_X
+ amdgpu_crtc
->crtc_offset
, 0);
1926 WREG32(mmGRPH_SURFACE_OFFSET_Y
+ amdgpu_crtc
->crtc_offset
, 0);
1927 WREG32(mmGRPH_X_START
+ amdgpu_crtc
->crtc_offset
, 0);
1928 WREG32(mmGRPH_Y_START
+ amdgpu_crtc
->crtc_offset
, 0);
1929 WREG32(mmGRPH_X_END
+ amdgpu_crtc
->crtc_offset
, target_fb
->width
);
1930 WREG32(mmGRPH_Y_END
+ amdgpu_crtc
->crtc_offset
, target_fb
->height
);
1932 fb_pitch_pixels
= target_fb
->pitches
[0] / target_fb
->format
->cpp
[0];
1933 WREG32(mmGRPH_PITCH
+ amdgpu_crtc
->crtc_offset
, fb_pitch_pixels
);
1935 dce_v8_0_grph_enable(crtc
, true);
1937 WREG32(mmLB_DESKTOP_HEIGHT
+ amdgpu_crtc
->crtc_offset
,
1942 WREG32(mmVIEWPORT_START
+ amdgpu_crtc
->crtc_offset
,
1944 viewport_w
= crtc
->mode
.hdisplay
;
1945 viewport_h
= (crtc
->mode
.vdisplay
+ 1) & ~1;
1946 WREG32(mmVIEWPORT_SIZE
+ amdgpu_crtc
->crtc_offset
,
1947 (viewport_w
<< 16) | viewport_h
);
1949 /* set pageflip to happen anywhere in vblank interval */
1950 WREG32(mmMASTER_UPDATE_MODE
+ amdgpu_crtc
->crtc_offset
, 0);
1952 if (!atomic
&& fb
&& fb
!= crtc
->primary
->fb
) {
1953 abo
= gem_to_amdgpu_bo(fb
->obj
[0]);
1954 r
= amdgpu_bo_reserve(abo
, true);
1955 if (unlikely(r
!= 0))
1957 amdgpu_bo_unpin(abo
);
1958 amdgpu_bo_unreserve(abo
);
1961 /* Bytes per pixel may have changed */
1962 dce_v8_0_bandwidth_update(adev
);
1967 static void dce_v8_0_set_interleave(struct drm_crtc
*crtc
,
1968 struct drm_display_mode
*mode
)
1970 struct drm_device
*dev
= crtc
->dev
;
1971 struct amdgpu_device
*adev
= dev
->dev_private
;
1972 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
1974 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1975 WREG32(mmLB_DATA_FORMAT
+ amdgpu_crtc
->crtc_offset
,
1976 LB_DATA_FORMAT__INTERLEAVE_EN__SHIFT
);
1978 WREG32(mmLB_DATA_FORMAT
+ amdgpu_crtc
->crtc_offset
, 0);
1981 static void dce_v8_0_crtc_load_lut(struct drm_crtc
*crtc
)
1983 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
1984 struct drm_device
*dev
= crtc
->dev
;
1985 struct amdgpu_device
*adev
= dev
->dev_private
;
1989 DRM_DEBUG_KMS("%d\n", amdgpu_crtc
->crtc_id
);
1991 WREG32(mmINPUT_CSC_CONTROL
+ amdgpu_crtc
->crtc_offset
,
1992 ((INPUT_CSC_BYPASS
<< INPUT_CSC_CONTROL__INPUT_CSC_GRPH_MODE__SHIFT
) |
1993 (INPUT_CSC_BYPASS
<< INPUT_CSC_CONTROL__INPUT_CSC_OVL_MODE__SHIFT
)));
1994 WREG32(mmPRESCALE_GRPH_CONTROL
+ amdgpu_crtc
->crtc_offset
,
1995 PRESCALE_GRPH_CONTROL__GRPH_PRESCALE_BYPASS_MASK
);
1996 WREG32(mmPRESCALE_OVL_CONTROL
+ amdgpu_crtc
->crtc_offset
,
1997 PRESCALE_OVL_CONTROL__OVL_PRESCALE_BYPASS_MASK
);
1998 WREG32(mmINPUT_GAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
,
1999 ((INPUT_GAMMA_USE_LUT
<< INPUT_GAMMA_CONTROL__GRPH_INPUT_GAMMA_MODE__SHIFT
) |
2000 (INPUT_GAMMA_USE_LUT
<< INPUT_GAMMA_CONTROL__OVL_INPUT_GAMMA_MODE__SHIFT
)));
2002 WREG32(mmDC_LUT_CONTROL
+ amdgpu_crtc
->crtc_offset
, 0);
2004 WREG32(mmDC_LUT_BLACK_OFFSET_BLUE
+ amdgpu_crtc
->crtc_offset
, 0);
2005 WREG32(mmDC_LUT_BLACK_OFFSET_GREEN
+ amdgpu_crtc
->crtc_offset
, 0);
2006 WREG32(mmDC_LUT_BLACK_OFFSET_RED
+ amdgpu_crtc
->crtc_offset
, 0);
2008 WREG32(mmDC_LUT_WHITE_OFFSET_BLUE
+ amdgpu_crtc
->crtc_offset
, 0xffff);
2009 WREG32(mmDC_LUT_WHITE_OFFSET_GREEN
+ amdgpu_crtc
->crtc_offset
, 0xffff);
2010 WREG32(mmDC_LUT_WHITE_OFFSET_RED
+ amdgpu_crtc
->crtc_offset
, 0xffff);
2012 WREG32(mmDC_LUT_RW_MODE
+ amdgpu_crtc
->crtc_offset
, 0);
2013 WREG32(mmDC_LUT_WRITE_EN_MASK
+ amdgpu_crtc
->crtc_offset
, 0x00000007);
2015 WREG32(mmDC_LUT_RW_INDEX
+ amdgpu_crtc
->crtc_offset
, 0);
2016 r
= crtc
->gamma_store
;
2017 g
= r
+ crtc
->gamma_size
;
2018 b
= g
+ crtc
->gamma_size
;
2019 for (i
= 0; i
< 256; i
++) {
2020 WREG32(mmDC_LUT_30_COLOR
+ amdgpu_crtc
->crtc_offset
,
2021 ((*r
++ & 0xffc0) << 14) |
2022 ((*g
++ & 0xffc0) << 4) |
2026 WREG32(mmDEGAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
,
2027 ((DEGAMMA_BYPASS
<< DEGAMMA_CONTROL__GRPH_DEGAMMA_MODE__SHIFT
) |
2028 (DEGAMMA_BYPASS
<< DEGAMMA_CONTROL__OVL_DEGAMMA_MODE__SHIFT
) |
2029 (DEGAMMA_BYPASS
<< DEGAMMA_CONTROL__CURSOR_DEGAMMA_MODE__SHIFT
)));
2030 WREG32(mmGAMUT_REMAP_CONTROL
+ amdgpu_crtc
->crtc_offset
,
2031 ((GAMUT_REMAP_BYPASS
<< GAMUT_REMAP_CONTROL__GRPH_GAMUT_REMAP_MODE__SHIFT
) |
2032 (GAMUT_REMAP_BYPASS
<< GAMUT_REMAP_CONTROL__OVL_GAMUT_REMAP_MODE__SHIFT
)));
2033 WREG32(mmREGAMMA_CONTROL
+ amdgpu_crtc
->crtc_offset
,
2034 ((REGAMMA_BYPASS
<< REGAMMA_CONTROL__GRPH_REGAMMA_MODE__SHIFT
) |
2035 (REGAMMA_BYPASS
<< REGAMMA_CONTROL__OVL_REGAMMA_MODE__SHIFT
)));
2036 WREG32(mmOUTPUT_CSC_CONTROL
+ amdgpu_crtc
->crtc_offset
,
2037 ((OUTPUT_CSC_BYPASS
<< OUTPUT_CSC_CONTROL__OUTPUT_CSC_GRPH_MODE__SHIFT
) |
2038 (OUTPUT_CSC_BYPASS
<< OUTPUT_CSC_CONTROL__OUTPUT_CSC_OVL_MODE__SHIFT
)));
2039 /* XXX match this to the depth of the crtc fmt block, move to modeset? */
2040 WREG32(0x1a50 + amdgpu_crtc
->crtc_offset
, 0);
2041 /* XXX this only needs to be programmed once per crtc at startup,
2042 * not sure where the best place for it is
2044 WREG32(mmALPHA_CONTROL
+ amdgpu_crtc
->crtc_offset
,
2045 ALPHA_CONTROL__CURSOR_ALPHA_BLND_ENA_MASK
);
2048 static int dce_v8_0_pick_dig_encoder(struct drm_encoder
*encoder
)
2050 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
2051 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
2053 switch (amdgpu_encoder
->encoder_id
) {
2054 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
2060 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
2066 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
2072 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3
:
2076 DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder
->encoder_id
);
2082 * dce_v8_0_pick_pll - Allocate a PPLL for use by the crtc.
2086 * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
2087 * a single PPLL can be used for all DP crtcs/encoders. For non-DP
2088 * monitors a dedicated PPLL must be used. If a particular board has
2089 * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
2090 * as there is no need to program the PLL itself. If we are not able to
2091 * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
2092 * avoid messing up an existing monitor.
2094 * Asic specific PLL information
2098 * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP)
2100 * - PPLL0, PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC
2103 static u32
dce_v8_0_pick_pll(struct drm_crtc
*crtc
)
2105 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2106 struct drm_device
*dev
= crtc
->dev
;
2107 struct amdgpu_device
*adev
= dev
->dev_private
;
2111 if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc
->encoder
))) {
2112 if (adev
->clock
.dp_extclk
)
2113 /* skip PPLL programming if using ext clock */
2114 return ATOM_PPLL_INVALID
;
2116 /* use the same PPLL for all DP monitors */
2117 pll
= amdgpu_pll_get_shared_dp_ppll(crtc
);
2118 if (pll
!= ATOM_PPLL_INVALID
)
2122 /* use the same PPLL for all monitors with the same clock */
2123 pll
= amdgpu_pll_get_shared_nondp_ppll(crtc
);
2124 if (pll
!= ATOM_PPLL_INVALID
)
2127 /* otherwise, pick one of the plls */
2128 if ((adev
->asic_type
== CHIP_KABINI
) ||
2129 (adev
->asic_type
== CHIP_MULLINS
)) {
2130 /* KB/ML has PPLL1 and PPLL2 */
2131 pll_in_use
= amdgpu_pll_get_use_mask(crtc
);
2132 if (!(pll_in_use
& (1 << ATOM_PPLL2
)))
2134 if (!(pll_in_use
& (1 << ATOM_PPLL1
)))
2136 DRM_ERROR("unable to allocate a PPLL\n");
2137 return ATOM_PPLL_INVALID
;
2139 /* CI/KV has PPLL0, PPLL1, and PPLL2 */
2140 pll_in_use
= amdgpu_pll_get_use_mask(crtc
);
2141 if (!(pll_in_use
& (1 << ATOM_PPLL2
)))
2143 if (!(pll_in_use
& (1 << ATOM_PPLL1
)))
2145 if (!(pll_in_use
& (1 << ATOM_PPLL0
)))
2147 DRM_ERROR("unable to allocate a PPLL\n");
2148 return ATOM_PPLL_INVALID
;
2150 return ATOM_PPLL_INVALID
;
2153 static void dce_v8_0_lock_cursor(struct drm_crtc
*crtc
, bool lock
)
2155 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2156 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2159 cur_lock
= RREG32(mmCUR_UPDATE
+ amdgpu_crtc
->crtc_offset
);
2161 cur_lock
|= CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK
;
2163 cur_lock
&= ~CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK
;
2164 WREG32(mmCUR_UPDATE
+ amdgpu_crtc
->crtc_offset
, cur_lock
);
2167 static void dce_v8_0_hide_cursor(struct drm_crtc
*crtc
)
2169 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2170 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2172 WREG32_IDX(mmCUR_CONTROL
+ amdgpu_crtc
->crtc_offset
,
2173 (CURSOR_24_8_PRE_MULT
<< CUR_CONTROL__CURSOR_MODE__SHIFT
) |
2174 (CURSOR_URGENT_1_2
<< CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT
));
2177 static void dce_v8_0_show_cursor(struct drm_crtc
*crtc
)
2179 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2180 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2182 WREG32(mmCUR_SURFACE_ADDRESS_HIGH
+ amdgpu_crtc
->crtc_offset
,
2183 upper_32_bits(amdgpu_crtc
->cursor_addr
));
2184 WREG32(mmCUR_SURFACE_ADDRESS
+ amdgpu_crtc
->crtc_offset
,
2185 lower_32_bits(amdgpu_crtc
->cursor_addr
));
2187 WREG32_IDX(mmCUR_CONTROL
+ amdgpu_crtc
->crtc_offset
,
2188 CUR_CONTROL__CURSOR_EN_MASK
|
2189 (CURSOR_24_8_PRE_MULT
<< CUR_CONTROL__CURSOR_MODE__SHIFT
) |
2190 (CURSOR_URGENT_1_2
<< CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT
));
2193 static int dce_v8_0_cursor_move_locked(struct drm_crtc
*crtc
,
2196 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2197 struct amdgpu_device
*adev
= crtc
->dev
->dev_private
;
2198 int xorigin
= 0, yorigin
= 0;
2200 amdgpu_crtc
->cursor_x
= x
;
2201 amdgpu_crtc
->cursor_y
= y
;
2203 /* avivo cursor are offset into the total surface */
2206 DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x
, y
, crtc
->x
, crtc
->y
);
2209 xorigin
= min(-x
, amdgpu_crtc
->max_cursor_width
- 1);
2213 yorigin
= min(-y
, amdgpu_crtc
->max_cursor_height
- 1);
2217 WREG32(mmCUR_POSITION
+ amdgpu_crtc
->crtc_offset
, (x
<< 16) | y
);
2218 WREG32(mmCUR_HOT_SPOT
+ amdgpu_crtc
->crtc_offset
, (xorigin
<< 16) | yorigin
);
2219 WREG32(mmCUR_SIZE
+ amdgpu_crtc
->crtc_offset
,
2220 ((amdgpu_crtc
->cursor_width
- 1) << 16) | (amdgpu_crtc
->cursor_height
- 1));
2225 static int dce_v8_0_crtc_cursor_move(struct drm_crtc
*crtc
,
2230 dce_v8_0_lock_cursor(crtc
, true);
2231 ret
= dce_v8_0_cursor_move_locked(crtc
, x
, y
);
2232 dce_v8_0_lock_cursor(crtc
, false);
2237 static int dce_v8_0_crtc_cursor_set2(struct drm_crtc
*crtc
,
2238 struct drm_file
*file_priv
,
2245 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2246 struct drm_gem_object
*obj
;
2247 struct amdgpu_bo
*aobj
;
2251 /* turn off cursor */
2252 dce_v8_0_hide_cursor(crtc
);
2257 if ((width
> amdgpu_crtc
->max_cursor_width
) ||
2258 (height
> amdgpu_crtc
->max_cursor_height
)) {
2259 DRM_ERROR("bad cursor width or height %d x %d\n", width
, height
);
2263 obj
= drm_gem_object_lookup(file_priv
, handle
);
2265 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle
, amdgpu_crtc
->crtc_id
);
2269 aobj
= gem_to_amdgpu_bo(obj
);
2270 ret
= amdgpu_bo_reserve(aobj
, false);
2272 drm_gem_object_put_unlocked(obj
);
2276 ret
= amdgpu_bo_pin(aobj
, AMDGPU_GEM_DOMAIN_VRAM
);
2277 amdgpu_bo_unreserve(aobj
);
2279 DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret
);
2280 drm_gem_object_put_unlocked(obj
);
2283 amdgpu_crtc
->cursor_addr
= amdgpu_bo_gpu_offset(aobj
);
2285 dce_v8_0_lock_cursor(crtc
, true);
2287 if (width
!= amdgpu_crtc
->cursor_width
||
2288 height
!= amdgpu_crtc
->cursor_height
||
2289 hot_x
!= amdgpu_crtc
->cursor_hot_x
||
2290 hot_y
!= amdgpu_crtc
->cursor_hot_y
) {
2293 x
= amdgpu_crtc
->cursor_x
+ amdgpu_crtc
->cursor_hot_x
- hot_x
;
2294 y
= amdgpu_crtc
->cursor_y
+ amdgpu_crtc
->cursor_hot_y
- hot_y
;
2296 dce_v8_0_cursor_move_locked(crtc
, x
, y
);
2298 amdgpu_crtc
->cursor_width
= width
;
2299 amdgpu_crtc
->cursor_height
= height
;
2300 amdgpu_crtc
->cursor_hot_x
= hot_x
;
2301 amdgpu_crtc
->cursor_hot_y
= hot_y
;
2304 dce_v8_0_show_cursor(crtc
);
2305 dce_v8_0_lock_cursor(crtc
, false);
2308 if (amdgpu_crtc
->cursor_bo
) {
2309 struct amdgpu_bo
*aobj
= gem_to_amdgpu_bo(amdgpu_crtc
->cursor_bo
);
2310 ret
= amdgpu_bo_reserve(aobj
, true);
2311 if (likely(ret
== 0)) {
2312 amdgpu_bo_unpin(aobj
);
2313 amdgpu_bo_unreserve(aobj
);
2315 drm_gem_object_put_unlocked(amdgpu_crtc
->cursor_bo
);
2318 amdgpu_crtc
->cursor_bo
= obj
;
2322 static void dce_v8_0_cursor_reset(struct drm_crtc
*crtc
)
2324 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2326 if (amdgpu_crtc
->cursor_bo
) {
2327 dce_v8_0_lock_cursor(crtc
, true);
2329 dce_v8_0_cursor_move_locked(crtc
, amdgpu_crtc
->cursor_x
,
2330 amdgpu_crtc
->cursor_y
);
2332 dce_v8_0_show_cursor(crtc
);
2334 dce_v8_0_lock_cursor(crtc
, false);
2338 static int dce_v8_0_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
2339 u16
*blue
, uint32_t size
,
2340 struct drm_modeset_acquire_ctx
*ctx
)
2342 dce_v8_0_crtc_load_lut(crtc
);
2347 static void dce_v8_0_crtc_destroy(struct drm_crtc
*crtc
)
2349 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2351 drm_crtc_cleanup(crtc
);
2355 static const struct drm_crtc_funcs dce_v8_0_crtc_funcs
= {
2356 .cursor_set2
= dce_v8_0_crtc_cursor_set2
,
2357 .cursor_move
= dce_v8_0_crtc_cursor_move
,
2358 .gamma_set
= dce_v8_0_crtc_gamma_set
,
2359 .set_config
= amdgpu_display_crtc_set_config
,
2360 .destroy
= dce_v8_0_crtc_destroy
,
2361 .page_flip_target
= amdgpu_display_crtc_page_flip_target
,
2364 static void dce_v8_0_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
2366 struct drm_device
*dev
= crtc
->dev
;
2367 struct amdgpu_device
*adev
= dev
->dev_private
;
2368 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2372 case DRM_MODE_DPMS_ON
:
2373 amdgpu_crtc
->enabled
= true;
2374 amdgpu_atombios_crtc_enable(crtc
, ATOM_ENABLE
);
2375 dce_v8_0_vga_enable(crtc
, true);
2376 amdgpu_atombios_crtc_blank(crtc
, ATOM_DISABLE
);
2377 dce_v8_0_vga_enable(crtc
, false);
2378 /* Make sure VBLANK and PFLIP interrupts are still enabled */
2379 type
= amdgpu_display_crtc_idx_to_irq_type(adev
,
2380 amdgpu_crtc
->crtc_id
);
2381 amdgpu_irq_update(adev
, &adev
->crtc_irq
, type
);
2382 amdgpu_irq_update(adev
, &adev
->pageflip_irq
, type
);
2383 drm_crtc_vblank_on(crtc
);
2384 dce_v8_0_crtc_load_lut(crtc
);
2386 case DRM_MODE_DPMS_STANDBY
:
2387 case DRM_MODE_DPMS_SUSPEND
:
2388 case DRM_MODE_DPMS_OFF
:
2389 drm_crtc_vblank_off(crtc
);
2390 if (amdgpu_crtc
->enabled
) {
2391 dce_v8_0_vga_enable(crtc
, true);
2392 amdgpu_atombios_crtc_blank(crtc
, ATOM_ENABLE
);
2393 dce_v8_0_vga_enable(crtc
, false);
2395 amdgpu_atombios_crtc_enable(crtc
, ATOM_DISABLE
);
2396 amdgpu_crtc
->enabled
= false;
2399 /* adjust pm to dpms */
2400 amdgpu_pm_compute_clocks(adev
);
2403 static void dce_v8_0_crtc_prepare(struct drm_crtc
*crtc
)
2405 /* disable crtc pair power gating before programming */
2406 amdgpu_atombios_crtc_powergate(crtc
, ATOM_DISABLE
);
2407 amdgpu_atombios_crtc_lock(crtc
, ATOM_ENABLE
);
2408 dce_v8_0_crtc_dpms(crtc
, DRM_MODE_DPMS_OFF
);
2411 static void dce_v8_0_crtc_commit(struct drm_crtc
*crtc
)
2413 dce_v8_0_crtc_dpms(crtc
, DRM_MODE_DPMS_ON
);
2414 amdgpu_atombios_crtc_lock(crtc
, ATOM_DISABLE
);
2417 static void dce_v8_0_crtc_disable(struct drm_crtc
*crtc
)
2419 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2420 struct drm_device
*dev
= crtc
->dev
;
2421 struct amdgpu_device
*adev
= dev
->dev_private
;
2422 struct amdgpu_atom_ss ss
;
2425 dce_v8_0_crtc_dpms(crtc
, DRM_MODE_DPMS_OFF
);
2426 if (crtc
->primary
->fb
) {
2428 struct amdgpu_bo
*abo
;
2430 abo
= gem_to_amdgpu_bo(crtc
->primary
->fb
->obj
[0]);
2431 r
= amdgpu_bo_reserve(abo
, true);
2433 DRM_ERROR("failed to reserve abo before unpin\n");
2435 amdgpu_bo_unpin(abo
);
2436 amdgpu_bo_unreserve(abo
);
2439 /* disable the GRPH */
2440 dce_v8_0_grph_enable(crtc
, false);
2442 amdgpu_atombios_crtc_powergate(crtc
, ATOM_ENABLE
);
2444 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
2445 if (adev
->mode_info
.crtcs
[i
] &&
2446 adev
->mode_info
.crtcs
[i
]->enabled
&&
2447 i
!= amdgpu_crtc
->crtc_id
&&
2448 amdgpu_crtc
->pll_id
== adev
->mode_info
.crtcs
[i
]->pll_id
) {
2449 /* one other crtc is using this pll don't turn
2456 switch (amdgpu_crtc
->pll_id
) {
2459 /* disable the ppll */
2460 amdgpu_atombios_crtc_program_pll(crtc
, amdgpu_crtc
->crtc_id
, amdgpu_crtc
->pll_id
,
2461 0, 0, ATOM_DISABLE
, 0, 0, 0, 0, 0, false, &ss
);
2464 /* disable the ppll */
2465 if ((adev
->asic_type
== CHIP_KAVERI
) ||
2466 (adev
->asic_type
== CHIP_BONAIRE
) ||
2467 (adev
->asic_type
== CHIP_HAWAII
))
2468 amdgpu_atombios_crtc_program_pll(crtc
, amdgpu_crtc
->crtc_id
, amdgpu_crtc
->pll_id
,
2469 0, 0, ATOM_DISABLE
, 0, 0, 0, 0, 0, false, &ss
);
2475 amdgpu_crtc
->pll_id
= ATOM_PPLL_INVALID
;
2476 amdgpu_crtc
->adjusted_clock
= 0;
2477 amdgpu_crtc
->encoder
= NULL
;
2478 amdgpu_crtc
->connector
= NULL
;
2481 static int dce_v8_0_crtc_mode_set(struct drm_crtc
*crtc
,
2482 struct drm_display_mode
*mode
,
2483 struct drm_display_mode
*adjusted_mode
,
2484 int x
, int y
, struct drm_framebuffer
*old_fb
)
2486 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2488 if (!amdgpu_crtc
->adjusted_clock
)
2491 amdgpu_atombios_crtc_set_pll(crtc
, adjusted_mode
);
2492 amdgpu_atombios_crtc_set_dtd_timing(crtc
, adjusted_mode
);
2493 dce_v8_0_crtc_do_set_base(crtc
, old_fb
, x
, y
, 0);
2494 amdgpu_atombios_crtc_overscan_setup(crtc
, mode
, adjusted_mode
);
2495 amdgpu_atombios_crtc_scaler_setup(crtc
);
2496 dce_v8_0_cursor_reset(crtc
);
2497 /* update the hw version fpr dpm */
2498 amdgpu_crtc
->hw_mode
= *adjusted_mode
;
2503 static bool dce_v8_0_crtc_mode_fixup(struct drm_crtc
*crtc
,
2504 const struct drm_display_mode
*mode
,
2505 struct drm_display_mode
*adjusted_mode
)
2507 struct amdgpu_crtc
*amdgpu_crtc
= to_amdgpu_crtc(crtc
);
2508 struct drm_device
*dev
= crtc
->dev
;
2509 struct drm_encoder
*encoder
;
2511 /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
2512 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
2513 if (encoder
->crtc
== crtc
) {
2514 amdgpu_crtc
->encoder
= encoder
;
2515 amdgpu_crtc
->connector
= amdgpu_get_connector_for_encoder(encoder
);
2519 if ((amdgpu_crtc
->encoder
== NULL
) || (amdgpu_crtc
->connector
== NULL
)) {
2520 amdgpu_crtc
->encoder
= NULL
;
2521 amdgpu_crtc
->connector
= NULL
;
2524 if (!amdgpu_display_crtc_scaling_mode_fixup(crtc
, mode
, adjusted_mode
))
2526 if (amdgpu_atombios_crtc_prepare_pll(crtc
, adjusted_mode
))
2529 amdgpu_crtc
->pll_id
= dce_v8_0_pick_pll(crtc
);
2530 /* if we can't get a PPLL for a non-DP encoder, fail */
2531 if ((amdgpu_crtc
->pll_id
== ATOM_PPLL_INVALID
) &&
2532 !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc
->encoder
)))
2538 static int dce_v8_0_crtc_set_base(struct drm_crtc
*crtc
, int x
, int y
,
2539 struct drm_framebuffer
*old_fb
)
2541 return dce_v8_0_crtc_do_set_base(crtc
, old_fb
, x
, y
, 0);
2544 static int dce_v8_0_crtc_set_base_atomic(struct drm_crtc
*crtc
,
2545 struct drm_framebuffer
*fb
,
2546 int x
, int y
, enum mode_set_atomic state
)
2548 return dce_v8_0_crtc_do_set_base(crtc
, fb
, x
, y
, 1);
2551 static const struct drm_crtc_helper_funcs dce_v8_0_crtc_helper_funcs
= {
2552 .dpms
= dce_v8_0_crtc_dpms
,
2553 .mode_fixup
= dce_v8_0_crtc_mode_fixup
,
2554 .mode_set
= dce_v8_0_crtc_mode_set
,
2555 .mode_set_base
= dce_v8_0_crtc_set_base
,
2556 .mode_set_base_atomic
= dce_v8_0_crtc_set_base_atomic
,
2557 .prepare
= dce_v8_0_crtc_prepare
,
2558 .commit
= dce_v8_0_crtc_commit
,
2559 .disable
= dce_v8_0_crtc_disable
,
2562 static int dce_v8_0_crtc_init(struct amdgpu_device
*adev
, int index
)
2564 struct amdgpu_crtc
*amdgpu_crtc
;
2566 amdgpu_crtc
= kzalloc(sizeof(struct amdgpu_crtc
) +
2567 (AMDGPUFB_CONN_LIMIT
* sizeof(struct drm_connector
*)), GFP_KERNEL
);
2568 if (amdgpu_crtc
== NULL
)
2571 drm_crtc_init(adev
->ddev
, &amdgpu_crtc
->base
, &dce_v8_0_crtc_funcs
);
2573 drm_mode_crtc_set_gamma_size(&amdgpu_crtc
->base
, 256);
2574 amdgpu_crtc
->crtc_id
= index
;
2575 adev
->mode_info
.crtcs
[index
] = amdgpu_crtc
;
2577 amdgpu_crtc
->max_cursor_width
= CIK_CURSOR_WIDTH
;
2578 amdgpu_crtc
->max_cursor_height
= CIK_CURSOR_HEIGHT
;
2579 adev
->ddev
->mode_config
.cursor_width
= amdgpu_crtc
->max_cursor_width
;
2580 adev
->ddev
->mode_config
.cursor_height
= amdgpu_crtc
->max_cursor_height
;
2582 amdgpu_crtc
->crtc_offset
= crtc_offsets
[amdgpu_crtc
->crtc_id
];
2584 amdgpu_crtc
->pll_id
= ATOM_PPLL_INVALID
;
2585 amdgpu_crtc
->adjusted_clock
= 0;
2586 amdgpu_crtc
->encoder
= NULL
;
2587 amdgpu_crtc
->connector
= NULL
;
2588 drm_crtc_helper_add(&amdgpu_crtc
->base
, &dce_v8_0_crtc_helper_funcs
);
2593 static int dce_v8_0_early_init(void *handle
)
2595 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2597 adev
->audio_endpt_rreg
= &dce_v8_0_audio_endpt_rreg
;
2598 adev
->audio_endpt_wreg
= &dce_v8_0_audio_endpt_wreg
;
2600 dce_v8_0_set_display_funcs(adev
);
2602 adev
->mode_info
.num_crtc
= dce_v8_0_get_num_crtc(adev
);
2604 switch (adev
->asic_type
) {
2607 adev
->mode_info
.num_hpd
= 6;
2608 adev
->mode_info
.num_dig
= 6;
2611 adev
->mode_info
.num_hpd
= 6;
2612 adev
->mode_info
.num_dig
= 7;
2616 adev
->mode_info
.num_hpd
= 6;
2617 adev
->mode_info
.num_dig
= 6; /* ? */
2620 /* FIXME: not supported yet */
2624 dce_v8_0_set_irq_funcs(adev
);
2629 static int dce_v8_0_sw_init(void *handle
)
2632 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2634 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
2635 r
= amdgpu_irq_add_id(adev
, AMDGPU_IH_CLIENTID_LEGACY
, i
+ 1, &adev
->crtc_irq
);
2640 for (i
= 8; i
< 20; i
+= 2) {
2641 r
= amdgpu_irq_add_id(adev
, AMDGPU_IH_CLIENTID_LEGACY
, i
, &adev
->pageflip_irq
);
2647 r
= amdgpu_irq_add_id(adev
, AMDGPU_IH_CLIENTID_LEGACY
, 42, &adev
->hpd_irq
);
2651 adev
->ddev
->mode_config
.funcs
= &amdgpu_mode_funcs
;
2653 adev
->ddev
->mode_config
.async_page_flip
= true;
2655 adev
->ddev
->mode_config
.max_width
= 16384;
2656 adev
->ddev
->mode_config
.max_height
= 16384;
2658 adev
->ddev
->mode_config
.preferred_depth
= 24;
2659 adev
->ddev
->mode_config
.prefer_shadow
= 1;
2661 adev
->ddev
->mode_config
.fb_base
= adev
->gmc
.aper_base
;
2663 r
= amdgpu_display_modeset_create_props(adev
);
2667 adev
->ddev
->mode_config
.max_width
= 16384;
2668 adev
->ddev
->mode_config
.max_height
= 16384;
2670 /* allocate crtcs */
2671 for (i
= 0; i
< adev
->mode_info
.num_crtc
; i
++) {
2672 r
= dce_v8_0_crtc_init(adev
, i
);
2677 if (amdgpu_atombios_get_connector_info_from_object_table(adev
))
2678 amdgpu_display_print_display_setup(adev
->ddev
);
2683 r
= dce_v8_0_afmt_init(adev
);
2687 r
= dce_v8_0_audio_init(adev
);
2691 drm_kms_helper_poll_init(adev
->ddev
);
2693 adev
->mode_info
.mode_config_initialized
= true;
2697 static int dce_v8_0_sw_fini(void *handle
)
2699 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2701 kfree(adev
->mode_info
.bios_hardcoded_edid
);
2703 drm_kms_helper_poll_fini(adev
->ddev
);
2705 dce_v8_0_audio_fini(adev
);
2707 dce_v8_0_afmt_fini(adev
);
2709 drm_mode_config_cleanup(adev
->ddev
);
2710 adev
->mode_info
.mode_config_initialized
= false;
2715 static int dce_v8_0_hw_init(void *handle
)
2718 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2720 /* disable vga render */
2721 dce_v8_0_set_vga_render_state(adev
, false);
2722 /* init dig PHYs, disp eng pll */
2723 amdgpu_atombios_encoder_init_dig(adev
);
2724 amdgpu_atombios_crtc_set_disp_eng_pll(adev
, adev
->clock
.default_dispclk
);
2726 /* initialize hpd */
2727 dce_v8_0_hpd_init(adev
);
2729 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
2730 dce_v8_0_audio_enable(adev
, &adev
->mode_info
.audio
.pin
[i
], false);
2733 dce_v8_0_pageflip_interrupt_init(adev
);
2738 static int dce_v8_0_hw_fini(void *handle
)
2741 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2743 dce_v8_0_hpd_fini(adev
);
2745 for (i
= 0; i
< adev
->mode_info
.audio
.num_pins
; i
++) {
2746 dce_v8_0_audio_enable(adev
, &adev
->mode_info
.audio
.pin
[i
], false);
2749 dce_v8_0_pageflip_interrupt_fini(adev
);
2754 static int dce_v8_0_suspend(void *handle
)
2756 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2758 adev
->mode_info
.bl_level
=
2759 amdgpu_atombios_encoder_get_backlight_level_from_reg(adev
);
2761 return dce_v8_0_hw_fini(handle
);
2764 static int dce_v8_0_resume(void *handle
)
2766 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2769 amdgpu_atombios_encoder_set_backlight_level_to_reg(adev
,
2770 adev
->mode_info
.bl_level
);
2772 ret
= dce_v8_0_hw_init(handle
);
2774 /* turn on the BL */
2775 if (adev
->mode_info
.bl_encoder
) {
2776 u8 bl_level
= amdgpu_display_backlight_get_level(adev
,
2777 adev
->mode_info
.bl_encoder
);
2778 amdgpu_display_backlight_set_level(adev
, adev
->mode_info
.bl_encoder
,
2785 static bool dce_v8_0_is_idle(void *handle
)
2790 static int dce_v8_0_wait_for_idle(void *handle
)
2795 static int dce_v8_0_soft_reset(void *handle
)
2797 u32 srbm_soft_reset
= 0, tmp
;
2798 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
2800 if (dce_v8_0_is_display_hung(adev
))
2801 srbm_soft_reset
|= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK
;
2803 if (srbm_soft_reset
) {
2804 tmp
= RREG32(mmSRBM_SOFT_RESET
);
2805 tmp
|= srbm_soft_reset
;
2806 dev_info(adev
->dev
, "SRBM_SOFT_RESET=0x%08X\n", tmp
);
2807 WREG32(mmSRBM_SOFT_RESET
, tmp
);
2808 tmp
= RREG32(mmSRBM_SOFT_RESET
);
2812 tmp
&= ~srbm_soft_reset
;
2813 WREG32(mmSRBM_SOFT_RESET
, tmp
);
2814 tmp
= RREG32(mmSRBM_SOFT_RESET
);
2816 /* Wait a little for things to settle down */
2822 static void dce_v8_0_set_crtc_vblank_interrupt_state(struct amdgpu_device
*adev
,
2824 enum amdgpu_interrupt_state state
)
2826 u32 reg_block
, lb_interrupt_mask
;
2828 if (crtc
>= adev
->mode_info
.num_crtc
) {
2829 DRM_DEBUG("invalid crtc %d\n", crtc
);
2835 reg_block
= CRTC0_REGISTER_OFFSET
;
2838 reg_block
= CRTC1_REGISTER_OFFSET
;
2841 reg_block
= CRTC2_REGISTER_OFFSET
;
2844 reg_block
= CRTC3_REGISTER_OFFSET
;
2847 reg_block
= CRTC4_REGISTER_OFFSET
;
2850 reg_block
= CRTC5_REGISTER_OFFSET
;
2853 DRM_DEBUG("invalid crtc %d\n", crtc
);
2858 case AMDGPU_IRQ_STATE_DISABLE
:
2859 lb_interrupt_mask
= RREG32(mmLB_INTERRUPT_MASK
+ reg_block
);
2860 lb_interrupt_mask
&= ~LB_INTERRUPT_MASK__VBLANK_INTERRUPT_MASK_MASK
;
2861 WREG32(mmLB_INTERRUPT_MASK
+ reg_block
, lb_interrupt_mask
);
2863 case AMDGPU_IRQ_STATE_ENABLE
:
2864 lb_interrupt_mask
= RREG32(mmLB_INTERRUPT_MASK
+ reg_block
);
2865 lb_interrupt_mask
|= LB_INTERRUPT_MASK__VBLANK_INTERRUPT_MASK_MASK
;
2866 WREG32(mmLB_INTERRUPT_MASK
+ reg_block
, lb_interrupt_mask
);
2873 static void dce_v8_0_set_crtc_vline_interrupt_state(struct amdgpu_device
*adev
,
2875 enum amdgpu_interrupt_state state
)
2877 u32 reg_block
, lb_interrupt_mask
;
2879 if (crtc
>= adev
->mode_info
.num_crtc
) {
2880 DRM_DEBUG("invalid crtc %d\n", crtc
);
2886 reg_block
= CRTC0_REGISTER_OFFSET
;
2889 reg_block
= CRTC1_REGISTER_OFFSET
;
2892 reg_block
= CRTC2_REGISTER_OFFSET
;
2895 reg_block
= CRTC3_REGISTER_OFFSET
;
2898 reg_block
= CRTC4_REGISTER_OFFSET
;
2901 reg_block
= CRTC5_REGISTER_OFFSET
;
2904 DRM_DEBUG("invalid crtc %d\n", crtc
);
2909 case AMDGPU_IRQ_STATE_DISABLE
:
2910 lb_interrupt_mask
= RREG32(mmLB_INTERRUPT_MASK
+ reg_block
);
2911 lb_interrupt_mask
&= ~LB_INTERRUPT_MASK__VLINE_INTERRUPT_MASK_MASK
;
2912 WREG32(mmLB_INTERRUPT_MASK
+ reg_block
, lb_interrupt_mask
);
2914 case AMDGPU_IRQ_STATE_ENABLE
:
2915 lb_interrupt_mask
= RREG32(mmLB_INTERRUPT_MASK
+ reg_block
);
2916 lb_interrupt_mask
|= LB_INTERRUPT_MASK__VLINE_INTERRUPT_MASK_MASK
;
2917 WREG32(mmLB_INTERRUPT_MASK
+ reg_block
, lb_interrupt_mask
);
2924 static int dce_v8_0_set_hpd_interrupt_state(struct amdgpu_device
*adev
,
2925 struct amdgpu_irq_src
*src
,
2927 enum amdgpu_interrupt_state state
)
2929 u32 dc_hpd_int_cntl
;
2931 if (type
>= adev
->mode_info
.num_hpd
) {
2932 DRM_DEBUG("invalid hdp %d\n", type
);
2937 case AMDGPU_IRQ_STATE_DISABLE
:
2938 dc_hpd_int_cntl
= RREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[type
]);
2939 dc_hpd_int_cntl
&= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK
;
2940 WREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[type
], dc_hpd_int_cntl
);
2942 case AMDGPU_IRQ_STATE_ENABLE
:
2943 dc_hpd_int_cntl
= RREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[type
]);
2944 dc_hpd_int_cntl
|= DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK
;
2945 WREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[type
], dc_hpd_int_cntl
);
2954 static int dce_v8_0_set_crtc_interrupt_state(struct amdgpu_device
*adev
,
2955 struct amdgpu_irq_src
*src
,
2957 enum amdgpu_interrupt_state state
)
2960 case AMDGPU_CRTC_IRQ_VBLANK1
:
2961 dce_v8_0_set_crtc_vblank_interrupt_state(adev
, 0, state
);
2963 case AMDGPU_CRTC_IRQ_VBLANK2
:
2964 dce_v8_0_set_crtc_vblank_interrupt_state(adev
, 1, state
);
2966 case AMDGPU_CRTC_IRQ_VBLANK3
:
2967 dce_v8_0_set_crtc_vblank_interrupt_state(adev
, 2, state
);
2969 case AMDGPU_CRTC_IRQ_VBLANK4
:
2970 dce_v8_0_set_crtc_vblank_interrupt_state(adev
, 3, state
);
2972 case AMDGPU_CRTC_IRQ_VBLANK5
:
2973 dce_v8_0_set_crtc_vblank_interrupt_state(adev
, 4, state
);
2975 case AMDGPU_CRTC_IRQ_VBLANK6
:
2976 dce_v8_0_set_crtc_vblank_interrupt_state(adev
, 5, state
);
2978 case AMDGPU_CRTC_IRQ_VLINE1
:
2979 dce_v8_0_set_crtc_vline_interrupt_state(adev
, 0, state
);
2981 case AMDGPU_CRTC_IRQ_VLINE2
:
2982 dce_v8_0_set_crtc_vline_interrupt_state(adev
, 1, state
);
2984 case AMDGPU_CRTC_IRQ_VLINE3
:
2985 dce_v8_0_set_crtc_vline_interrupt_state(adev
, 2, state
);
2987 case AMDGPU_CRTC_IRQ_VLINE4
:
2988 dce_v8_0_set_crtc_vline_interrupt_state(adev
, 3, state
);
2990 case AMDGPU_CRTC_IRQ_VLINE5
:
2991 dce_v8_0_set_crtc_vline_interrupt_state(adev
, 4, state
);
2993 case AMDGPU_CRTC_IRQ_VLINE6
:
2994 dce_v8_0_set_crtc_vline_interrupt_state(adev
, 5, state
);
3002 static int dce_v8_0_crtc_irq(struct amdgpu_device
*adev
,
3003 struct amdgpu_irq_src
*source
,
3004 struct amdgpu_iv_entry
*entry
)
3006 unsigned crtc
= entry
->src_id
- 1;
3007 uint32_t disp_int
= RREG32(interrupt_status_offsets
[crtc
].reg
);
3008 unsigned int irq_type
= amdgpu_display_crtc_idx_to_irq_type(adev
,
3011 switch (entry
->src_data
[0]) {
3012 case 0: /* vblank */
3013 if (disp_int
& interrupt_status_offsets
[crtc
].vblank
)
3014 WREG32(mmLB_VBLANK_STATUS
+ crtc_offsets
[crtc
], LB_VBLANK_STATUS__VBLANK_ACK_MASK
);
3016 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
3018 if (amdgpu_irq_enabled(adev
, source
, irq_type
)) {
3019 drm_handle_vblank(adev
->ddev
, crtc
);
3021 DRM_DEBUG("IH: D%d vblank\n", crtc
+ 1);
3024 if (disp_int
& interrupt_status_offsets
[crtc
].vline
)
3025 WREG32(mmLB_VLINE_STATUS
+ crtc_offsets
[crtc
], LB_VLINE_STATUS__VLINE_ACK_MASK
);
3027 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
3029 DRM_DEBUG("IH: D%d vline\n", crtc
+ 1);
3032 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry
->src_id
, entry
->src_data
[0]);
3039 static int dce_v8_0_set_pageflip_interrupt_state(struct amdgpu_device
*adev
,
3040 struct amdgpu_irq_src
*src
,
3042 enum amdgpu_interrupt_state state
)
3046 if (type
>= adev
->mode_info
.num_crtc
) {
3047 DRM_ERROR("invalid pageflip crtc %d\n", type
);
3051 reg
= RREG32(mmGRPH_INTERRUPT_CONTROL
+ crtc_offsets
[type
]);
3052 if (state
== AMDGPU_IRQ_STATE_DISABLE
)
3053 WREG32(mmGRPH_INTERRUPT_CONTROL
+ crtc_offsets
[type
],
3054 reg
& ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK
);
3056 WREG32(mmGRPH_INTERRUPT_CONTROL
+ crtc_offsets
[type
],
3057 reg
| GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK
);
3062 static int dce_v8_0_pageflip_irq(struct amdgpu_device
*adev
,
3063 struct amdgpu_irq_src
*source
,
3064 struct amdgpu_iv_entry
*entry
)
3066 unsigned long flags
;
3068 struct amdgpu_crtc
*amdgpu_crtc
;
3069 struct amdgpu_flip_work
*works
;
3071 crtc_id
= (entry
->src_id
- 8) >> 1;
3072 amdgpu_crtc
= adev
->mode_info
.crtcs
[crtc_id
];
3074 if (crtc_id
>= adev
->mode_info
.num_crtc
) {
3075 DRM_ERROR("invalid pageflip crtc %d\n", crtc_id
);
3079 if (RREG32(mmGRPH_INTERRUPT_STATUS
+ crtc_offsets
[crtc_id
]) &
3080 GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK
)
3081 WREG32(mmGRPH_INTERRUPT_STATUS
+ crtc_offsets
[crtc_id
],
3082 GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK
);
3084 /* IRQ could occur when in initial stage */
3085 if (amdgpu_crtc
== NULL
)
3088 spin_lock_irqsave(&adev
->ddev
->event_lock
, flags
);
3089 works
= amdgpu_crtc
->pflip_works
;
3090 if (amdgpu_crtc
->pflip_status
!= AMDGPU_FLIP_SUBMITTED
){
3091 DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
3092 "AMDGPU_FLIP_SUBMITTED(%d)\n",
3093 amdgpu_crtc
->pflip_status
,
3094 AMDGPU_FLIP_SUBMITTED
);
3095 spin_unlock_irqrestore(&adev
->ddev
->event_lock
, flags
);
3099 /* page flip completed. clean up */
3100 amdgpu_crtc
->pflip_status
= AMDGPU_FLIP_NONE
;
3101 amdgpu_crtc
->pflip_works
= NULL
;
3103 /* wakeup usersapce */
3105 drm_crtc_send_vblank_event(&amdgpu_crtc
->base
, works
->event
);
3107 spin_unlock_irqrestore(&adev
->ddev
->event_lock
, flags
);
3109 drm_crtc_vblank_put(&amdgpu_crtc
->base
);
3110 schedule_work(&works
->unpin_work
);
3115 static int dce_v8_0_hpd_irq(struct amdgpu_device
*adev
,
3116 struct amdgpu_irq_src
*source
,
3117 struct amdgpu_iv_entry
*entry
)
3119 uint32_t disp_int
, mask
, tmp
;
3122 if (entry
->src_data
[0] >= adev
->mode_info
.num_hpd
) {
3123 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry
->src_id
, entry
->src_data
[0]);
3127 hpd
= entry
->src_data
[0];
3128 disp_int
= RREG32(interrupt_status_offsets
[hpd
].reg
);
3129 mask
= interrupt_status_offsets
[hpd
].hpd
;
3131 if (disp_int
& mask
) {
3132 tmp
= RREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[hpd
]);
3133 tmp
|= DC_HPD1_INT_CONTROL__DC_HPD1_INT_ACK_MASK
;
3134 WREG32(mmDC_HPD1_INT_CONTROL
+ hpd_offsets
[hpd
], tmp
);
3135 schedule_work(&adev
->hotplug_work
);
3136 DRM_DEBUG("IH: HPD%d\n", hpd
+ 1);
3143 static int dce_v8_0_set_clockgating_state(void *handle
,
3144 enum amd_clockgating_state state
)
3149 static int dce_v8_0_set_powergating_state(void *handle
,
3150 enum amd_powergating_state state
)
3155 static const struct amd_ip_funcs dce_v8_0_ip_funcs
= {
3157 .early_init
= dce_v8_0_early_init
,
3159 .sw_init
= dce_v8_0_sw_init
,
3160 .sw_fini
= dce_v8_0_sw_fini
,
3161 .hw_init
= dce_v8_0_hw_init
,
3162 .hw_fini
= dce_v8_0_hw_fini
,
3163 .suspend
= dce_v8_0_suspend
,
3164 .resume
= dce_v8_0_resume
,
3165 .is_idle
= dce_v8_0_is_idle
,
3166 .wait_for_idle
= dce_v8_0_wait_for_idle
,
3167 .soft_reset
= dce_v8_0_soft_reset
,
3168 .set_clockgating_state
= dce_v8_0_set_clockgating_state
,
3169 .set_powergating_state
= dce_v8_0_set_powergating_state
,
3173 dce_v8_0_encoder_mode_set(struct drm_encoder
*encoder
,
3174 struct drm_display_mode
*mode
,
3175 struct drm_display_mode
*adjusted_mode
)
3177 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3179 amdgpu_encoder
->pixel_clock
= adjusted_mode
->clock
;
3181 /* need to call this here rather than in prepare() since we need some crtc info */
3182 amdgpu_atombios_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
3184 /* set scaler clears this on some chips */
3185 dce_v8_0_set_interleave(encoder
->crtc
, mode
);
3187 if (amdgpu_atombios_encoder_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
) {
3188 dce_v8_0_afmt_enable(encoder
, true);
3189 dce_v8_0_afmt_setmode(encoder
, adjusted_mode
);
3193 static void dce_v8_0_encoder_prepare(struct drm_encoder
*encoder
)
3195 struct amdgpu_device
*adev
= encoder
->dev
->dev_private
;
3196 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3197 struct drm_connector
*connector
= amdgpu_get_connector_for_encoder(encoder
);
3199 if ((amdgpu_encoder
->active_device
&
3200 (ATOM_DEVICE_DFP_SUPPORT
| ATOM_DEVICE_LCD_SUPPORT
)) ||
3201 (amdgpu_encoder_get_dp_bridge_encoder_id(encoder
) !=
3202 ENCODER_OBJECT_ID_NONE
)) {
3203 struct amdgpu_encoder_atom_dig
*dig
= amdgpu_encoder
->enc_priv
;
3205 dig
->dig_encoder
= dce_v8_0_pick_dig_encoder(encoder
);
3206 if (amdgpu_encoder
->active_device
& ATOM_DEVICE_DFP_SUPPORT
)
3207 dig
->afmt
= adev
->mode_info
.afmt
[dig
->dig_encoder
];
3211 amdgpu_atombios_scratch_regs_lock(adev
, true);
3214 struct amdgpu_connector
*amdgpu_connector
= to_amdgpu_connector(connector
);
3216 /* select the clock/data port if it uses a router */
3217 if (amdgpu_connector
->router
.cd_valid
)
3218 amdgpu_i2c_router_select_cd_port(amdgpu_connector
);
3220 /* turn eDP panel on for mode set */
3221 if (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
)
3222 amdgpu_atombios_encoder_set_edp_panel_power(connector
,
3223 ATOM_TRANSMITTER_ACTION_POWER_ON
);
3226 /* this is needed for the pll/ss setup to work correctly in some cases */
3227 amdgpu_atombios_encoder_set_crtc_source(encoder
);
3228 /* set up the FMT blocks */
3229 dce_v8_0_program_fmt(encoder
);
3232 static void dce_v8_0_encoder_commit(struct drm_encoder
*encoder
)
3234 struct drm_device
*dev
= encoder
->dev
;
3235 struct amdgpu_device
*adev
= dev
->dev_private
;
3237 /* need to call this here as we need the crtc set up */
3238 amdgpu_atombios_encoder_dpms(encoder
, DRM_MODE_DPMS_ON
);
3239 amdgpu_atombios_scratch_regs_lock(adev
, false);
3242 static void dce_v8_0_encoder_disable(struct drm_encoder
*encoder
)
3244 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3245 struct amdgpu_encoder_atom_dig
*dig
;
3247 amdgpu_atombios_encoder_dpms(encoder
, DRM_MODE_DPMS_OFF
);
3249 if (amdgpu_atombios_encoder_is_digital(encoder
)) {
3250 if (amdgpu_atombios_encoder_get_encoder_mode(encoder
) == ATOM_ENCODER_MODE_HDMI
)
3251 dce_v8_0_afmt_enable(encoder
, false);
3252 dig
= amdgpu_encoder
->enc_priv
;
3253 dig
->dig_encoder
= -1;
3255 amdgpu_encoder
->active_device
= 0;
3258 /* these are handled by the primary encoders */
3259 static void dce_v8_0_ext_prepare(struct drm_encoder
*encoder
)
3264 static void dce_v8_0_ext_commit(struct drm_encoder
*encoder
)
3270 dce_v8_0_ext_mode_set(struct drm_encoder
*encoder
,
3271 struct drm_display_mode
*mode
,
3272 struct drm_display_mode
*adjusted_mode
)
3277 static void dce_v8_0_ext_disable(struct drm_encoder
*encoder
)
3283 dce_v8_0_ext_dpms(struct drm_encoder
*encoder
, int mode
)
3288 static const struct drm_encoder_helper_funcs dce_v8_0_ext_helper_funcs
= {
3289 .dpms
= dce_v8_0_ext_dpms
,
3290 .prepare
= dce_v8_0_ext_prepare
,
3291 .mode_set
= dce_v8_0_ext_mode_set
,
3292 .commit
= dce_v8_0_ext_commit
,
3293 .disable
= dce_v8_0_ext_disable
,
3294 /* no detect for TMDS/LVDS yet */
3297 static const struct drm_encoder_helper_funcs dce_v8_0_dig_helper_funcs
= {
3298 .dpms
= amdgpu_atombios_encoder_dpms
,
3299 .mode_fixup
= amdgpu_atombios_encoder_mode_fixup
,
3300 .prepare
= dce_v8_0_encoder_prepare
,
3301 .mode_set
= dce_v8_0_encoder_mode_set
,
3302 .commit
= dce_v8_0_encoder_commit
,
3303 .disable
= dce_v8_0_encoder_disable
,
3304 .detect
= amdgpu_atombios_encoder_dig_detect
,
3307 static const struct drm_encoder_helper_funcs dce_v8_0_dac_helper_funcs
= {
3308 .dpms
= amdgpu_atombios_encoder_dpms
,
3309 .mode_fixup
= amdgpu_atombios_encoder_mode_fixup
,
3310 .prepare
= dce_v8_0_encoder_prepare
,
3311 .mode_set
= dce_v8_0_encoder_mode_set
,
3312 .commit
= dce_v8_0_encoder_commit
,
3313 .detect
= amdgpu_atombios_encoder_dac_detect
,
3316 static void dce_v8_0_encoder_destroy(struct drm_encoder
*encoder
)
3318 struct amdgpu_encoder
*amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3319 if (amdgpu_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
3320 amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder
);
3321 kfree(amdgpu_encoder
->enc_priv
);
3322 drm_encoder_cleanup(encoder
);
3323 kfree(amdgpu_encoder
);
3326 static const struct drm_encoder_funcs dce_v8_0_encoder_funcs
= {
3327 .destroy
= dce_v8_0_encoder_destroy
,
3330 static void dce_v8_0_encoder_add(struct amdgpu_device
*adev
,
3331 uint32_t encoder_enum
,
3332 uint32_t supported_device
,
3335 struct drm_device
*dev
= adev
->ddev
;
3336 struct drm_encoder
*encoder
;
3337 struct amdgpu_encoder
*amdgpu_encoder
;
3339 /* see if we already added it */
3340 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
3341 amdgpu_encoder
= to_amdgpu_encoder(encoder
);
3342 if (amdgpu_encoder
->encoder_enum
== encoder_enum
) {
3343 amdgpu_encoder
->devices
|= supported_device
;
3350 amdgpu_encoder
= kzalloc(sizeof(struct amdgpu_encoder
), GFP_KERNEL
);
3351 if (!amdgpu_encoder
)
3354 encoder
= &amdgpu_encoder
->base
;
3355 switch (adev
->mode_info
.num_crtc
) {
3357 encoder
->possible_crtcs
= 0x1;
3361 encoder
->possible_crtcs
= 0x3;
3364 encoder
->possible_crtcs
= 0xf;
3367 encoder
->possible_crtcs
= 0x3f;
3371 amdgpu_encoder
->enc_priv
= NULL
;
3373 amdgpu_encoder
->encoder_enum
= encoder_enum
;
3374 amdgpu_encoder
->encoder_id
= (encoder_enum
& OBJECT_ID_MASK
) >> OBJECT_ID_SHIFT
;
3375 amdgpu_encoder
->devices
= supported_device
;
3376 amdgpu_encoder
->rmx_type
= RMX_OFF
;
3377 amdgpu_encoder
->underscan_type
= UNDERSCAN_OFF
;
3378 amdgpu_encoder
->is_ext_encoder
= false;
3379 amdgpu_encoder
->caps
= caps
;
3381 switch (amdgpu_encoder
->encoder_id
) {
3382 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1
:
3383 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2
:
3384 drm_encoder_init(dev
, encoder
, &dce_v8_0_encoder_funcs
,
3385 DRM_MODE_ENCODER_DAC
, NULL
);
3386 drm_encoder_helper_add(encoder
, &dce_v8_0_dac_helper_funcs
);
3388 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1
:
3389 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY
:
3390 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1
:
3391 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2
:
3392 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3
:
3393 if (amdgpu_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
)) {
3394 amdgpu_encoder
->rmx_type
= RMX_FULL
;
3395 drm_encoder_init(dev
, encoder
, &dce_v8_0_encoder_funcs
,
3396 DRM_MODE_ENCODER_LVDS
, NULL
);
3397 amdgpu_encoder
->enc_priv
= amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder
);
3398 } else if (amdgpu_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
)) {
3399 drm_encoder_init(dev
, encoder
, &dce_v8_0_encoder_funcs
,
3400 DRM_MODE_ENCODER_DAC
, NULL
);
3401 amdgpu_encoder
->enc_priv
= amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder
);
3403 drm_encoder_init(dev
, encoder
, &dce_v8_0_encoder_funcs
,
3404 DRM_MODE_ENCODER_TMDS
, NULL
);
3405 amdgpu_encoder
->enc_priv
= amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder
);
3407 drm_encoder_helper_add(encoder
, &dce_v8_0_dig_helper_funcs
);
3409 case ENCODER_OBJECT_ID_SI170B
:
3410 case ENCODER_OBJECT_ID_CH7303
:
3411 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA
:
3412 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB
:
3413 case ENCODER_OBJECT_ID_TITFP513
:
3414 case ENCODER_OBJECT_ID_VT1623
:
3415 case ENCODER_OBJECT_ID_HDMI_SI1930
:
3416 case ENCODER_OBJECT_ID_TRAVIS
:
3417 case ENCODER_OBJECT_ID_NUTMEG
:
3418 /* these are handled by the primary encoders */
3419 amdgpu_encoder
->is_ext_encoder
= true;
3420 if (amdgpu_encoder
->devices
& (ATOM_DEVICE_LCD_SUPPORT
))
3421 drm_encoder_init(dev
, encoder
, &dce_v8_0_encoder_funcs
,
3422 DRM_MODE_ENCODER_LVDS
, NULL
);
3423 else if (amdgpu_encoder
->devices
& (ATOM_DEVICE_CRT_SUPPORT
))
3424 drm_encoder_init(dev
, encoder
, &dce_v8_0_encoder_funcs
,
3425 DRM_MODE_ENCODER_DAC
, NULL
);
3427 drm_encoder_init(dev
, encoder
, &dce_v8_0_encoder_funcs
,
3428 DRM_MODE_ENCODER_TMDS
, NULL
);
3429 drm_encoder_helper_add(encoder
, &dce_v8_0_ext_helper_funcs
);
3434 static const struct amdgpu_display_funcs dce_v8_0_display_funcs
= {
3435 .bandwidth_update
= &dce_v8_0_bandwidth_update
,
3436 .vblank_get_counter
= &dce_v8_0_vblank_get_counter
,
3437 .backlight_set_level
= &amdgpu_atombios_encoder_set_backlight_level
,
3438 .backlight_get_level
= &amdgpu_atombios_encoder_get_backlight_level
,
3439 .hpd_sense
= &dce_v8_0_hpd_sense
,
3440 .hpd_set_polarity
= &dce_v8_0_hpd_set_polarity
,
3441 .hpd_get_gpio_reg
= &dce_v8_0_hpd_get_gpio_reg
,
3442 .page_flip
= &dce_v8_0_page_flip
,
3443 .page_flip_get_scanoutpos
= &dce_v8_0_crtc_get_scanoutpos
,
3444 .add_encoder
= &dce_v8_0_encoder_add
,
3445 .add_connector
= &amdgpu_connector_add
,
3448 static void dce_v8_0_set_display_funcs(struct amdgpu_device
*adev
)
3450 if (adev
->mode_info
.funcs
== NULL
)
3451 adev
->mode_info
.funcs
= &dce_v8_0_display_funcs
;
3454 static const struct amdgpu_irq_src_funcs dce_v8_0_crtc_irq_funcs
= {
3455 .set
= dce_v8_0_set_crtc_interrupt_state
,
3456 .process
= dce_v8_0_crtc_irq
,
3459 static const struct amdgpu_irq_src_funcs dce_v8_0_pageflip_irq_funcs
= {
3460 .set
= dce_v8_0_set_pageflip_interrupt_state
,
3461 .process
= dce_v8_0_pageflip_irq
,
3464 static const struct amdgpu_irq_src_funcs dce_v8_0_hpd_irq_funcs
= {
3465 .set
= dce_v8_0_set_hpd_interrupt_state
,
3466 .process
= dce_v8_0_hpd_irq
,
3469 static void dce_v8_0_set_irq_funcs(struct amdgpu_device
*adev
)
3471 if (adev
->mode_info
.num_crtc
> 0)
3472 adev
->crtc_irq
.num_types
= AMDGPU_CRTC_IRQ_VLINE1
+ adev
->mode_info
.num_crtc
;
3474 adev
->crtc_irq
.num_types
= 0;
3475 adev
->crtc_irq
.funcs
= &dce_v8_0_crtc_irq_funcs
;
3477 adev
->pageflip_irq
.num_types
= adev
->mode_info
.num_crtc
;
3478 adev
->pageflip_irq
.funcs
= &dce_v8_0_pageflip_irq_funcs
;
3480 adev
->hpd_irq
.num_types
= adev
->mode_info
.num_hpd
;
3481 adev
->hpd_irq
.funcs
= &dce_v8_0_hpd_irq_funcs
;
3484 const struct amdgpu_ip_block_version dce_v8_0_ip_block
=
3486 .type
= AMD_IP_BLOCK_TYPE_DCE
,
3490 .funcs
= &dce_v8_0_ip_funcs
,
3493 const struct amdgpu_ip_block_version dce_v8_1_ip_block
=
3495 .type
= AMD_IP_BLOCK_TYPE_DCE
,
3499 .funcs
= &dce_v8_0_ip_funcs
,
3502 const struct amdgpu_ip_block_version dce_v8_2_ip_block
=
3504 .type
= AMD_IP_BLOCK_TYPE_DCE
,
3508 .funcs
= &dce_v8_0_ip_funcs
,
3511 const struct amdgpu_ip_block_version dce_v8_3_ip_block
=
3513 .type
= AMD_IP_BLOCK_TYPE_DCE
,
3517 .funcs
= &dce_v8_0_ip_funcs
,
3520 const struct amdgpu_ip_block_version dce_v8_5_ip_block
=
3522 .type
= AMD_IP_BLOCK_TYPE_DCE
,
3526 .funcs
= &dce_v8_0_ip_funcs
,