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.
24 #include <drm/drm_fourcc.h>
25 #include <drm/drm_vblank.h>
28 #include "amdgpu_pm.h"
29 #include "amdgpu_i2c.h"
32 #include "amdgpu_atombios.h"
33 #include "atombios_crtc.h"
34 #include "atombios_encoders.h"
35 #include "amdgpu_pll.h"
36 #include "amdgpu_connectors.h"
37 #include "amdgpu_display.h"
40 #include "dce/dce_8_0_d.h"
41 #include "dce/dce_8_0_sh_mask.h"
43 #include "gca/gfx_7_2_enum.h"
45 #include "gmc/gmc_7_1_d.h"
46 #include "gmc/gmc_7_1_sh_mask.h"
48 #include "oss/oss_2_0_d.h"
49 #include "oss/oss_2_0_sh_mask.h"
51 static void dce_v8_0_set_display_funcs(struct amdgpu_device *adev);
52 static void dce_v8_0_set_irq_funcs(struct amdgpu_device *adev);
54 static const u32 crtc_offsets[6] =
56 CRTC0_REGISTER_OFFSET,
57 CRTC1_REGISTER_OFFSET,
58 CRTC2_REGISTER_OFFSET,
59 CRTC3_REGISTER_OFFSET,
60 CRTC4_REGISTER_OFFSET,
64 static const u32 hpd_offsets[] =
74 static const uint32_t dig_offsets[] = {
75 CRTC0_REGISTER_OFFSET,
76 CRTC1_REGISTER_OFFSET,
77 CRTC2_REGISTER_OFFSET,
78 CRTC3_REGISTER_OFFSET,
79 CRTC4_REGISTER_OFFSET,
80 CRTC5_REGISTER_OFFSET,
81 (0x13830 - 0x7030) >> 2,
90 } interrupt_status_offsets[6] = { {
91 .reg = mmDISP_INTERRUPT_STATUS,
92 .vblank = DISP_INTERRUPT_STATUS__LB_D1_VBLANK_INTERRUPT_MASK,
93 .vline = DISP_INTERRUPT_STATUS__LB_D1_VLINE_INTERRUPT_MASK,
94 .hpd = DISP_INTERRUPT_STATUS__DC_HPD1_INTERRUPT_MASK
96 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE,
97 .vblank = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VBLANK_INTERRUPT_MASK,
98 .vline = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VLINE_INTERRUPT_MASK,
99 .hpd = DISP_INTERRUPT_STATUS_CONTINUE__DC_HPD2_INTERRUPT_MASK
101 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE2,
102 .vblank = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VBLANK_INTERRUPT_MASK,
103 .vline = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VLINE_INTERRUPT_MASK,
104 .hpd = DISP_INTERRUPT_STATUS_CONTINUE2__DC_HPD3_INTERRUPT_MASK
106 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE3,
107 .vblank = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VBLANK_INTERRUPT_MASK,
108 .vline = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VLINE_INTERRUPT_MASK,
109 .hpd = DISP_INTERRUPT_STATUS_CONTINUE3__DC_HPD4_INTERRUPT_MASK
111 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE4,
112 .vblank = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VBLANK_INTERRUPT_MASK,
113 .vline = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VLINE_INTERRUPT_MASK,
114 .hpd = DISP_INTERRUPT_STATUS_CONTINUE4__DC_HPD5_INTERRUPT_MASK
116 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE5,
117 .vblank = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VBLANK_INTERRUPT_MASK,
118 .vline = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VLINE_INTERRUPT_MASK,
119 .hpd = DISP_INTERRUPT_STATUS_CONTINUE5__DC_HPD6_INTERRUPT_MASK
122 static u32 dce_v8_0_audio_endpt_rreg(struct amdgpu_device *adev,
123 u32 block_offset, u32 reg)
128 spin_lock_irqsave(&adev->audio_endpt_idx_lock, flags);
129 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX + block_offset, reg);
130 r = RREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA + block_offset);
131 spin_unlock_irqrestore(&adev->audio_endpt_idx_lock, flags);
136 static void dce_v8_0_audio_endpt_wreg(struct amdgpu_device *adev,
137 u32 block_offset, u32 reg, u32 v)
141 spin_lock_irqsave(&adev->audio_endpt_idx_lock, flags);
142 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_INDEX + block_offset, reg);
143 WREG32(mmAZALIA_F0_CODEC_ENDPOINT_DATA + block_offset, v);
144 spin_unlock_irqrestore(&adev->audio_endpt_idx_lock, flags);
147 static u32 dce_v8_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
149 if (crtc >= adev->mode_info.num_crtc)
152 return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
155 static void dce_v8_0_pageflip_interrupt_init(struct amdgpu_device *adev)
159 /* Enable pflip interrupts */
160 for (i = 0; i < adev->mode_info.num_crtc; i++)
161 amdgpu_irq_get(adev, &adev->pageflip_irq, i);
164 static void dce_v8_0_pageflip_interrupt_fini(struct amdgpu_device *adev)
168 /* Disable pflip interrupts */
169 for (i = 0; i < adev->mode_info.num_crtc; i++)
170 amdgpu_irq_put(adev, &adev->pageflip_irq, i);
174 * dce_v8_0_page_flip - pageflip callback.
176 * @adev: amdgpu_device pointer
177 * @crtc_id: crtc to cleanup pageflip on
178 * @crtc_base: new address of the crtc (GPU MC address)
180 * Triggers the actual pageflip by updating the primary
181 * surface base address.
183 static void dce_v8_0_page_flip(struct amdgpu_device *adev,
184 int crtc_id, u64 crtc_base, bool async)
186 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
188 /* flip at hsync for async, default is vsync */
189 WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, async ?
190 GRPH_FLIP_CONTROL__GRPH_SURFACE_UPDATE_H_RETRACE_EN_MASK : 0);
191 /* update the primary scanout addresses */
192 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
193 upper_32_bits(crtc_base));
194 /* writing to the low address triggers the update */
195 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
196 lower_32_bits(crtc_base));
198 RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
201 static int dce_v8_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
202 u32 *vbl, u32 *position)
204 if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
207 *vbl = RREG32(mmCRTC_V_BLANK_START_END + crtc_offsets[crtc]);
208 *position = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
214 * dce_v8_0_hpd_sense - hpd sense callback.
216 * @adev: amdgpu_device pointer
217 * @hpd: hpd (hotplug detect) pin
219 * Checks if a digital monitor is connected (evergreen+).
220 * Returns true if connected, false if not connected.
222 static bool dce_v8_0_hpd_sense(struct amdgpu_device *adev,
223 enum amdgpu_hpd_id hpd)
225 bool connected = false;
227 if (hpd >= adev->mode_info.num_hpd)
230 if (RREG32(mmDC_HPD1_INT_STATUS + hpd_offsets[hpd]) &
231 DC_HPD1_INT_STATUS__DC_HPD1_SENSE_MASK)
238 * dce_v8_0_hpd_set_polarity - hpd set polarity callback.
240 * @adev: amdgpu_device pointer
241 * @hpd: hpd (hotplug detect) pin
243 * Set the polarity of the hpd pin (evergreen+).
245 static void dce_v8_0_hpd_set_polarity(struct amdgpu_device *adev,
246 enum amdgpu_hpd_id hpd)
249 bool connected = dce_v8_0_hpd_sense(adev, hpd);
251 if (hpd >= adev->mode_info.num_hpd)
254 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
256 tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
258 tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
259 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
263 * dce_v8_0_hpd_init - hpd setup callback.
265 * @adev: amdgpu_device pointer
267 * Setup the hpd pins used by the card (evergreen+).
268 * Enable the pin, set the polarity, and enable the hpd interrupts.
270 static void dce_v8_0_hpd_init(struct amdgpu_device *adev)
272 struct drm_device *dev = adev->ddev;
273 struct drm_connector *connector;
276 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
277 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
279 if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
282 tmp = RREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
283 tmp |= DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
284 WREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
286 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
287 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
288 /* don't try to enable hpd on eDP or LVDS avoid breaking the
289 * aux dp channel on imac and help (but not completely fix)
290 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
291 * also avoid interrupt storms during dpms.
293 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
294 tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
295 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
299 dce_v8_0_hpd_set_polarity(adev, amdgpu_connector->hpd.hpd);
300 amdgpu_irq_get(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
305 * dce_v8_0_hpd_fini - hpd tear down callback.
307 * @adev: amdgpu_device pointer
309 * Tear down the hpd pins used by the card (evergreen+).
310 * Disable the hpd interrupts.
312 static void dce_v8_0_hpd_fini(struct amdgpu_device *adev)
314 struct drm_device *dev = adev->ddev;
315 struct drm_connector *connector;
318 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
319 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
321 if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
324 tmp = RREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
325 tmp &= ~DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
326 WREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], 0);
328 amdgpu_irq_put(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
332 static u32 dce_v8_0_hpd_get_gpio_reg(struct amdgpu_device *adev)
334 return mmDC_GPIO_HPD_A;
337 static bool dce_v8_0_is_display_hung(struct amdgpu_device *adev)
343 for (i = 0; i < adev->mode_info.num_crtc; i++) {
344 if (RREG32(mmCRTC_CONTROL + crtc_offsets[i]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK) {
345 crtc_status[i] = RREG32(mmCRTC_STATUS_HV_COUNT + crtc_offsets[i]);
346 crtc_hung |= (1 << i);
350 for (j = 0; j < 10; j++) {
351 for (i = 0; i < adev->mode_info.num_crtc; i++) {
352 if (crtc_hung & (1 << i)) {
353 tmp = RREG32(mmCRTC_STATUS_HV_COUNT + crtc_offsets[i]);
354 if (tmp != crtc_status[i])
355 crtc_hung &= ~(1 << i);
366 static void dce_v8_0_set_vga_render_state(struct amdgpu_device *adev,
371 /* Lockout access through VGA aperture*/
372 tmp = RREG32(mmVGA_HDP_CONTROL);
374 tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 0);
376 tmp = REG_SET_FIELD(tmp, VGA_HDP_CONTROL, VGA_MEMORY_DISABLE, 1);
377 WREG32(mmVGA_HDP_CONTROL, tmp);
379 /* disable VGA render */
380 tmp = RREG32(mmVGA_RENDER_CONTROL);
382 tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 1);
384 tmp = REG_SET_FIELD(tmp, VGA_RENDER_CONTROL, VGA_VSTATUS_CNTL, 0);
385 WREG32(mmVGA_RENDER_CONTROL, tmp);
388 static int dce_v8_0_get_num_crtc(struct amdgpu_device *adev)
392 switch (adev->asic_type) {
410 void dce_v8_0_disable_dce(struct amdgpu_device *adev)
412 /*Disable VGA render and enabled crtc, if has DCE engine*/
413 if (amdgpu_atombios_has_dce_engine_info(adev)) {
417 dce_v8_0_set_vga_render_state(adev, false);
420 for (i = 0; i < dce_v8_0_get_num_crtc(adev); i++) {
421 crtc_enabled = REG_GET_FIELD(RREG32(mmCRTC_CONTROL + crtc_offsets[i]),
422 CRTC_CONTROL, CRTC_MASTER_EN);
424 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
425 tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
426 tmp = REG_SET_FIELD(tmp, CRTC_CONTROL, CRTC_MASTER_EN, 0);
427 WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
428 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
434 static void dce_v8_0_program_fmt(struct drm_encoder *encoder)
436 struct drm_device *dev = encoder->dev;
437 struct amdgpu_device *adev = dev->dev_private;
438 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
439 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
440 struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
443 enum amdgpu_connector_dither dither = AMDGPU_FMT_DITHER_DISABLE;
446 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
447 bpc = amdgpu_connector_get_monitor_bpc(connector);
448 dither = amdgpu_connector->dither;
451 /* LVDS/eDP FMT is set up by atom */
452 if (amdgpu_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
455 /* not needed for analog */
456 if ((amdgpu_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
457 (amdgpu_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
465 if (dither == AMDGPU_FMT_DITHER_ENABLE)
466 /* XXX sort out optimal dither settings */
467 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
468 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
469 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
470 (0 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
472 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
473 (0 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
476 if (dither == AMDGPU_FMT_DITHER_ENABLE)
477 /* XXX sort out optimal dither settings */
478 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
479 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
480 FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
481 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
482 (1 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
484 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
485 (1 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
488 if (dither == AMDGPU_FMT_DITHER_ENABLE)
489 /* XXX sort out optimal dither settings */
490 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
491 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
492 FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
493 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
494 (2 << FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH__SHIFT));
496 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
497 (2 << FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH__SHIFT));
504 WREG32(mmFMT_BIT_DEPTH_CONTROL + amdgpu_crtc->crtc_offset, tmp);
508 /* display watermark setup */
510 * dce_v8_0_line_buffer_adjust - Set up the line buffer
512 * @adev: amdgpu_device pointer
513 * @amdgpu_crtc: the selected display controller
514 * @mode: the current display mode on the selected display
517 * Setup up the line buffer allocation for
518 * the selected display controller (CIK).
519 * Returns the line buffer size in pixels.
521 static u32 dce_v8_0_line_buffer_adjust(struct amdgpu_device *adev,
522 struct amdgpu_crtc *amdgpu_crtc,
523 struct drm_display_mode *mode)
525 u32 tmp, buffer_alloc, i;
526 u32 pipe_offset = amdgpu_crtc->crtc_id * 0x8;
529 * There are 6 line buffers, one for each display controllers.
530 * There are 3 partitions per LB. Select the number of partitions
531 * to enable based on the display width. For display widths larger
532 * than 4096, you need use to use 2 display controllers and combine
533 * them using the stereo blender.
535 if (amdgpu_crtc->base.enabled && mode) {
536 if (mode->crtc_hdisplay < 1920) {
539 } else if (mode->crtc_hdisplay < 2560) {
542 } else if (mode->crtc_hdisplay < 4096) {
544 buffer_alloc = (adev->flags & AMD_IS_APU) ? 2 : 4;
546 DRM_DEBUG_KMS("Mode too big for LB!\n");
548 buffer_alloc = (adev->flags & AMD_IS_APU) ? 2 : 4;
555 WREG32(mmLB_MEMORY_CTRL + amdgpu_crtc->crtc_offset,
556 (tmp << LB_MEMORY_CTRL__LB_MEMORY_CONFIG__SHIFT) |
557 (0x6B0 << LB_MEMORY_CTRL__LB_MEMORY_SIZE__SHIFT));
559 WREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
560 (buffer_alloc << PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATED__SHIFT));
561 for (i = 0; i < adev->usec_timeout; i++) {
562 if (RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
563 PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATION_COMPLETED_MASK)
568 if (amdgpu_crtc->base.enabled && mode) {
580 /* controller not enabled, so no lb used */
585 * cik_get_number_of_dram_channels - get the number of dram channels
587 * @adev: amdgpu_device pointer
589 * Look up the number of video ram channels (CIK).
590 * Used for display watermark bandwidth calculations
591 * Returns the number of dram channels
593 static u32 cik_get_number_of_dram_channels(struct amdgpu_device *adev)
595 u32 tmp = RREG32(mmMC_SHARED_CHMAP);
597 switch ((tmp & MC_SHARED_CHMAP__NOOFCHAN_MASK) >> MC_SHARED_CHMAP__NOOFCHAN__SHIFT) {
620 struct dce8_wm_params {
621 u32 dram_channels; /* number of dram channels */
622 u32 yclk; /* bandwidth per dram data pin in kHz */
623 u32 sclk; /* engine clock in kHz */
624 u32 disp_clk; /* display clock in kHz */
625 u32 src_width; /* viewport width */
626 u32 active_time; /* active display time in ns */
627 u32 blank_time; /* blank time in ns */
628 bool interlaced; /* mode is interlaced */
629 fixed20_12 vsc; /* vertical scale ratio */
630 u32 num_heads; /* number of active crtcs */
631 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
632 u32 lb_size; /* line buffer allocated to pipe */
633 u32 vtaps; /* vertical scaler taps */
637 * dce_v8_0_dram_bandwidth - get the dram bandwidth
639 * @wm: watermark calculation data
641 * Calculate the raw dram bandwidth (CIK).
642 * Used for display watermark bandwidth calculations
643 * Returns the dram bandwidth in MBytes/s
645 static u32 dce_v8_0_dram_bandwidth(struct dce8_wm_params *wm)
647 /* Calculate raw DRAM Bandwidth */
648 fixed20_12 dram_efficiency; /* 0.7 */
649 fixed20_12 yclk, dram_channels, bandwidth;
652 a.full = dfixed_const(1000);
653 yclk.full = dfixed_const(wm->yclk);
654 yclk.full = dfixed_div(yclk, a);
655 dram_channels.full = dfixed_const(wm->dram_channels * 4);
656 a.full = dfixed_const(10);
657 dram_efficiency.full = dfixed_const(7);
658 dram_efficiency.full = dfixed_div(dram_efficiency, a);
659 bandwidth.full = dfixed_mul(dram_channels, yclk);
660 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
662 return dfixed_trunc(bandwidth);
666 * dce_v8_0_dram_bandwidth_for_display - get the dram bandwidth for display
668 * @wm: watermark calculation data
670 * Calculate the dram bandwidth used for display (CIK).
671 * Used for display watermark bandwidth calculations
672 * Returns the dram bandwidth for display in MBytes/s
674 static u32 dce_v8_0_dram_bandwidth_for_display(struct dce8_wm_params *wm)
676 /* Calculate DRAM Bandwidth and the part allocated to display. */
677 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
678 fixed20_12 yclk, dram_channels, bandwidth;
681 a.full = dfixed_const(1000);
682 yclk.full = dfixed_const(wm->yclk);
683 yclk.full = dfixed_div(yclk, a);
684 dram_channels.full = dfixed_const(wm->dram_channels * 4);
685 a.full = dfixed_const(10);
686 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
687 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
688 bandwidth.full = dfixed_mul(dram_channels, yclk);
689 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
691 return dfixed_trunc(bandwidth);
695 * dce_v8_0_data_return_bandwidth - get the data return bandwidth
697 * @wm: watermark calculation data
699 * Calculate the data return bandwidth used for display (CIK).
700 * Used for display watermark bandwidth calculations
701 * Returns the data return bandwidth in MBytes/s
703 static u32 dce_v8_0_data_return_bandwidth(struct dce8_wm_params *wm)
705 /* Calculate the display Data return Bandwidth */
706 fixed20_12 return_efficiency; /* 0.8 */
707 fixed20_12 sclk, bandwidth;
710 a.full = dfixed_const(1000);
711 sclk.full = dfixed_const(wm->sclk);
712 sclk.full = dfixed_div(sclk, a);
713 a.full = dfixed_const(10);
714 return_efficiency.full = dfixed_const(8);
715 return_efficiency.full = dfixed_div(return_efficiency, a);
716 a.full = dfixed_const(32);
717 bandwidth.full = dfixed_mul(a, sclk);
718 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
720 return dfixed_trunc(bandwidth);
724 * dce_v8_0_dmif_request_bandwidth - get the dmif bandwidth
726 * @wm: watermark calculation data
728 * Calculate the dmif bandwidth used for display (CIK).
729 * Used for display watermark bandwidth calculations
730 * Returns the dmif bandwidth in MBytes/s
732 static u32 dce_v8_0_dmif_request_bandwidth(struct dce8_wm_params *wm)
734 /* Calculate the DMIF Request Bandwidth */
735 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
736 fixed20_12 disp_clk, bandwidth;
739 a.full = dfixed_const(1000);
740 disp_clk.full = dfixed_const(wm->disp_clk);
741 disp_clk.full = dfixed_div(disp_clk, a);
742 a.full = dfixed_const(32);
743 b.full = dfixed_mul(a, disp_clk);
745 a.full = dfixed_const(10);
746 disp_clk_request_efficiency.full = dfixed_const(8);
747 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
749 bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
751 return dfixed_trunc(bandwidth);
755 * dce_v8_0_available_bandwidth - get the min available bandwidth
757 * @wm: watermark calculation data
759 * Calculate the min available bandwidth used for display (CIK).
760 * Used for display watermark bandwidth calculations
761 * Returns the min available bandwidth in MBytes/s
763 static u32 dce_v8_0_available_bandwidth(struct dce8_wm_params *wm)
765 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
766 u32 dram_bandwidth = dce_v8_0_dram_bandwidth(wm);
767 u32 data_return_bandwidth = dce_v8_0_data_return_bandwidth(wm);
768 u32 dmif_req_bandwidth = dce_v8_0_dmif_request_bandwidth(wm);
770 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
774 * dce_v8_0_average_bandwidth - get the average available bandwidth
776 * @wm: watermark calculation data
778 * Calculate the average available bandwidth used for display (CIK).
779 * Used for display watermark bandwidth calculations
780 * Returns the average available bandwidth in MBytes/s
782 static u32 dce_v8_0_average_bandwidth(struct dce8_wm_params *wm)
784 /* Calculate the display mode Average Bandwidth
785 * DisplayMode should contain the source and destination dimensions,
789 fixed20_12 line_time;
790 fixed20_12 src_width;
791 fixed20_12 bandwidth;
794 a.full = dfixed_const(1000);
795 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
796 line_time.full = dfixed_div(line_time, a);
797 bpp.full = dfixed_const(wm->bytes_per_pixel);
798 src_width.full = dfixed_const(wm->src_width);
799 bandwidth.full = dfixed_mul(src_width, bpp);
800 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
801 bandwidth.full = dfixed_div(bandwidth, line_time);
803 return dfixed_trunc(bandwidth);
807 * dce_v8_0_latency_watermark - get the latency watermark
809 * @wm: watermark calculation data
811 * Calculate the latency watermark (CIK).
812 * Used for display watermark bandwidth calculations
813 * Returns the latency watermark in ns
815 static u32 dce_v8_0_latency_watermark(struct dce8_wm_params *wm)
817 /* First calculate the latency in ns */
818 u32 mc_latency = 2000; /* 2000 ns. */
819 u32 available_bandwidth = dce_v8_0_available_bandwidth(wm);
820 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
821 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
822 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
823 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
824 (wm->num_heads * cursor_line_pair_return_time);
825 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
826 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
827 u32 tmp, dmif_size = 12288;
830 if (wm->num_heads == 0)
833 a.full = dfixed_const(2);
834 b.full = dfixed_const(1);
835 if ((wm->vsc.full > a.full) ||
836 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
838 ((wm->vsc.full >= a.full) && wm->interlaced))
839 max_src_lines_per_dst_line = 4;
841 max_src_lines_per_dst_line = 2;
843 a.full = dfixed_const(available_bandwidth);
844 b.full = dfixed_const(wm->num_heads);
845 a.full = dfixed_div(a, b);
846 tmp = div_u64((u64) dmif_size * (u64) wm->disp_clk, mc_latency + 512);
847 tmp = min(dfixed_trunc(a), tmp);
849 lb_fill_bw = min(tmp, wm->disp_clk * wm->bytes_per_pixel / 1000);
851 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
852 b.full = dfixed_const(1000);
853 c.full = dfixed_const(lb_fill_bw);
854 b.full = dfixed_div(c, b);
855 a.full = dfixed_div(a, b);
856 line_fill_time = dfixed_trunc(a);
858 if (line_fill_time < wm->active_time)
861 return latency + (line_fill_time - wm->active_time);
866 * dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display - check
867 * average and available dram bandwidth
869 * @wm: watermark calculation data
871 * Check if the display average bandwidth fits in the display
872 * dram bandwidth (CIK).
873 * Used for display watermark bandwidth calculations
874 * Returns true if the display fits, false if not.
876 static bool dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
878 if (dce_v8_0_average_bandwidth(wm) <=
879 (dce_v8_0_dram_bandwidth_for_display(wm) / wm->num_heads))
886 * dce_v8_0_average_bandwidth_vs_available_bandwidth - check
887 * average and available bandwidth
889 * @wm: watermark calculation data
891 * Check if the display average bandwidth fits in the display
892 * available bandwidth (CIK).
893 * Used for display watermark bandwidth calculations
894 * Returns true if the display fits, false if not.
896 static bool dce_v8_0_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
898 if (dce_v8_0_average_bandwidth(wm) <=
899 (dce_v8_0_available_bandwidth(wm) / wm->num_heads))
906 * dce_v8_0_check_latency_hiding - check latency hiding
908 * @wm: watermark calculation data
910 * Check latency hiding (CIK).
911 * Used for display watermark bandwidth calculations
912 * Returns true if the display fits, false if not.
914 static bool dce_v8_0_check_latency_hiding(struct dce8_wm_params *wm)
916 u32 lb_partitions = wm->lb_size / wm->src_width;
917 u32 line_time = wm->active_time + wm->blank_time;
918 u32 latency_tolerant_lines;
922 a.full = dfixed_const(1);
923 if (wm->vsc.full > a.full)
924 latency_tolerant_lines = 1;
926 if (lb_partitions <= (wm->vtaps + 1))
927 latency_tolerant_lines = 1;
929 latency_tolerant_lines = 2;
932 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
934 if (dce_v8_0_latency_watermark(wm) <= latency_hiding)
941 * dce_v8_0_program_watermarks - program display watermarks
943 * @adev: amdgpu_device pointer
944 * @amdgpu_crtc: the selected display controller
945 * @lb_size: line buffer size
946 * @num_heads: number of display controllers in use
948 * Calculate and program the display watermarks for the
949 * selected display controller (CIK).
951 static void dce_v8_0_program_watermarks(struct amdgpu_device *adev,
952 struct amdgpu_crtc *amdgpu_crtc,
953 u32 lb_size, u32 num_heads)
955 struct drm_display_mode *mode = &amdgpu_crtc->base.mode;
956 struct dce8_wm_params wm_low, wm_high;
959 u32 latency_watermark_a = 0, latency_watermark_b = 0;
960 u32 tmp, wm_mask, lb_vblank_lead_lines = 0;
962 if (amdgpu_crtc->base.enabled && num_heads && mode) {
963 active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
965 line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
967 line_time = min(line_time, (u32)65535);
969 /* watermark for high clocks */
970 if (adev->pm.dpm_enabled) {
972 amdgpu_dpm_get_mclk(adev, false) * 10;
974 amdgpu_dpm_get_sclk(adev, false) * 10;
976 wm_high.yclk = adev->pm.current_mclk * 10;
977 wm_high.sclk = adev->pm.current_sclk * 10;
980 wm_high.disp_clk = mode->clock;
981 wm_high.src_width = mode->crtc_hdisplay;
982 wm_high.active_time = active_time;
983 wm_high.blank_time = line_time - wm_high.active_time;
984 wm_high.interlaced = false;
985 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
986 wm_high.interlaced = true;
987 wm_high.vsc = amdgpu_crtc->vsc;
989 if (amdgpu_crtc->rmx_type != RMX_OFF)
991 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
992 wm_high.lb_size = lb_size;
993 wm_high.dram_channels = cik_get_number_of_dram_channels(adev);
994 wm_high.num_heads = num_heads;
996 /* set for high clocks */
997 latency_watermark_a = min(dce_v8_0_latency_watermark(&wm_high), (u32)65535);
999 /* possibly force display priority to high */
1000 /* should really do this at mode validation time... */
1001 if (!dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
1002 !dce_v8_0_average_bandwidth_vs_available_bandwidth(&wm_high) ||
1003 !dce_v8_0_check_latency_hiding(&wm_high) ||
1004 (adev->mode_info.disp_priority == 2)) {
1005 DRM_DEBUG_KMS("force priority to high\n");
1008 /* watermark for low clocks */
1009 if (adev->pm.dpm_enabled) {
1011 amdgpu_dpm_get_mclk(adev, true) * 10;
1013 amdgpu_dpm_get_sclk(adev, true) * 10;
1015 wm_low.yclk = adev->pm.current_mclk * 10;
1016 wm_low.sclk = adev->pm.current_sclk * 10;
1019 wm_low.disp_clk = mode->clock;
1020 wm_low.src_width = mode->crtc_hdisplay;
1021 wm_low.active_time = active_time;
1022 wm_low.blank_time = line_time - wm_low.active_time;
1023 wm_low.interlaced = false;
1024 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1025 wm_low.interlaced = true;
1026 wm_low.vsc = amdgpu_crtc->vsc;
1028 if (amdgpu_crtc->rmx_type != RMX_OFF)
1030 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
1031 wm_low.lb_size = lb_size;
1032 wm_low.dram_channels = cik_get_number_of_dram_channels(adev);
1033 wm_low.num_heads = num_heads;
1035 /* set for low clocks */
1036 latency_watermark_b = min(dce_v8_0_latency_watermark(&wm_low), (u32)65535);
1038 /* possibly force display priority to high */
1039 /* should really do this at mode validation time... */
1040 if (!dce_v8_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
1041 !dce_v8_0_average_bandwidth_vs_available_bandwidth(&wm_low) ||
1042 !dce_v8_0_check_latency_hiding(&wm_low) ||
1043 (adev->mode_info.disp_priority == 2)) {
1044 DRM_DEBUG_KMS("force priority to high\n");
1046 lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
1050 wm_mask = RREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset);
1052 tmp &= ~(3 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
1053 tmp |= (1 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
1054 WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, tmp);
1055 WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
1056 ((latency_watermark_a << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
1057 (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
1059 tmp = RREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset);
1060 tmp &= ~(3 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
1061 tmp |= (2 << DPG_WATERMARK_MASK_CONTROL__URGENCY_WATERMARK_MASK__SHIFT);
1062 WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, tmp);
1063 WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
1064 ((latency_watermark_b << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
1065 (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
1066 /* restore original selection */
1067 WREG32(mmDPG_WATERMARK_MASK_CONTROL + amdgpu_crtc->crtc_offset, wm_mask);
1069 /* save values for DPM */
1070 amdgpu_crtc->line_time = line_time;
1071 amdgpu_crtc->wm_high = latency_watermark_a;
1072 amdgpu_crtc->wm_low = latency_watermark_b;
1073 /* Save number of lines the linebuffer leads before the scanout */
1074 amdgpu_crtc->lb_vblank_lead_lines = lb_vblank_lead_lines;
1078 * dce_v8_0_bandwidth_update - program display watermarks
1080 * @adev: amdgpu_device pointer
1082 * Calculate and program the display watermarks and line
1083 * buffer allocation (CIK).
1085 static void dce_v8_0_bandwidth_update(struct amdgpu_device *adev)
1087 struct drm_display_mode *mode = NULL;
1088 u32 num_heads = 0, lb_size;
1091 amdgpu_display_update_priority(adev);
1093 for (i = 0; i < adev->mode_info.num_crtc; i++) {
1094 if (adev->mode_info.crtcs[i]->base.enabled)
1097 for (i = 0; i < adev->mode_info.num_crtc; i++) {
1098 mode = &adev->mode_info.crtcs[i]->base.mode;
1099 lb_size = dce_v8_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i], mode);
1100 dce_v8_0_program_watermarks(adev, adev->mode_info.crtcs[i],
1101 lb_size, num_heads);
1105 static void dce_v8_0_audio_get_connected_pins(struct amdgpu_device *adev)
1110 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1111 offset = adev->mode_info.audio.pin[i].offset;
1112 tmp = RREG32_AUDIO_ENDPT(offset,
1113 ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT);
1115 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY_MASK) >>
1116 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT__PORT_CONNECTIVITY__SHIFT) == 1)
1117 adev->mode_info.audio.pin[i].connected = false;
1119 adev->mode_info.audio.pin[i].connected = true;
1123 static struct amdgpu_audio_pin *dce_v8_0_audio_get_pin(struct amdgpu_device *adev)
1127 dce_v8_0_audio_get_connected_pins(adev);
1129 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1130 if (adev->mode_info.audio.pin[i].connected)
1131 return &adev->mode_info.audio.pin[i];
1133 DRM_ERROR("No connected audio pins found!\n");
1137 static void dce_v8_0_afmt_audio_select_pin(struct drm_encoder *encoder)
1139 struct amdgpu_device *adev = encoder->dev->dev_private;
1140 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1141 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1144 if (!dig || !dig->afmt || !dig->afmt->pin)
1147 offset = dig->afmt->offset;
1149 WREG32(mmAFMT_AUDIO_SRC_CONTROL + offset,
1150 (dig->afmt->pin->id << AFMT_AUDIO_SRC_CONTROL__AFMT_AUDIO_SRC_SELECT__SHIFT));
1153 static void dce_v8_0_audio_write_latency_fields(struct drm_encoder *encoder,
1154 struct drm_display_mode *mode)
1156 struct amdgpu_device *adev = encoder->dev->dev_private;
1157 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1158 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1159 struct drm_connector *connector;
1160 struct amdgpu_connector *amdgpu_connector = NULL;
1161 u32 tmp = 0, offset;
1163 if (!dig || !dig->afmt || !dig->afmt->pin)
1166 offset = dig->afmt->pin->offset;
1168 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
1169 if (connector->encoder == encoder) {
1170 amdgpu_connector = to_amdgpu_connector(connector);
1175 if (!amdgpu_connector) {
1176 DRM_ERROR("Couldn't find encoder's connector\n");
1180 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1181 if (connector->latency_present[1])
1183 (connector->video_latency[1] <<
1184 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
1185 (connector->audio_latency[1] <<
1186 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
1190 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
1192 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
1194 if (connector->latency_present[0])
1196 (connector->video_latency[0] <<
1197 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
1198 (connector->audio_latency[0] <<
1199 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
1203 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__VIDEO_LIPSYNC__SHIFT) |
1205 AZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC__AUDIO_LIPSYNC__SHIFT);
1208 WREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_RESPONSE_LIPSYNC, tmp);
1211 static void dce_v8_0_audio_write_speaker_allocation(struct drm_encoder *encoder)
1213 struct amdgpu_device *adev = encoder->dev->dev_private;
1214 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1215 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1216 struct drm_connector *connector;
1217 struct amdgpu_connector *amdgpu_connector = NULL;
1222 if (!dig || !dig->afmt || !dig->afmt->pin)
1225 offset = dig->afmt->pin->offset;
1227 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
1228 if (connector->encoder == encoder) {
1229 amdgpu_connector = to_amdgpu_connector(connector);
1234 if (!amdgpu_connector) {
1235 DRM_ERROR("Couldn't find encoder's connector\n");
1239 sad_count = drm_edid_to_speaker_allocation(amdgpu_connector_edid(connector), &sadb);
1240 if (sad_count < 0) {
1241 DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
1245 /* program the speaker allocation */
1246 tmp = RREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER);
1247 tmp &= ~(AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__DP_CONNECTION_MASK |
1248 AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION_MASK);
1250 tmp |= AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__HDMI_CONNECTION_MASK;
1252 tmp |= (sadb[0] << AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION__SHIFT);
1254 tmp |= (5 << AZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER__SPEAKER_ALLOCATION__SHIFT); /* stereo */
1255 WREG32_AUDIO_ENDPT(offset, ixAZALIA_F0_CODEC_PIN_CONTROL_CHANNEL_SPEAKER, tmp);
1260 static void dce_v8_0_audio_write_sad_regs(struct drm_encoder *encoder)
1262 struct amdgpu_device *adev = encoder->dev->dev_private;
1263 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1264 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1266 struct drm_connector *connector;
1267 struct amdgpu_connector *amdgpu_connector = NULL;
1268 struct cea_sad *sads;
1271 static const u16 eld_reg_to_type[][2] = {
1272 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
1273 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
1274 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
1275 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
1276 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
1277 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
1278 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
1279 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
1280 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
1281 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
1282 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
1283 { ixAZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
1286 if (!dig || !dig->afmt || !dig->afmt->pin)
1289 offset = dig->afmt->pin->offset;
1291 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
1292 if (connector->encoder == encoder) {
1293 amdgpu_connector = to_amdgpu_connector(connector);
1298 if (!amdgpu_connector) {
1299 DRM_ERROR("Couldn't find encoder's connector\n");
1303 sad_count = drm_edid_to_sad(amdgpu_connector_edid(connector), &sads);
1304 if (sad_count <= 0) {
1305 DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
1310 for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
1312 u8 stereo_freqs = 0;
1313 int max_channels = -1;
1316 for (j = 0; j < sad_count; j++) {
1317 struct cea_sad *sad = &sads[j];
1319 if (sad->format == eld_reg_to_type[i][1]) {
1320 if (sad->channels > max_channels) {
1321 value = (sad->channels <<
1322 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__MAX_CHANNELS__SHIFT) |
1324 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__DESCRIPTOR_BYTE_2__SHIFT) |
1326 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES__SHIFT);
1327 max_channels = sad->channels;
1330 if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
1331 stereo_freqs |= sad->freq;
1337 value |= (stereo_freqs <<
1338 AZALIA_F0_CODEC_PIN_CONTROL_AUDIO_DESCRIPTOR0__SUPPORTED_FREQUENCIES_STEREO__SHIFT);
1340 WREG32_AUDIO_ENDPT(offset, eld_reg_to_type[i][0], value);
1346 static void dce_v8_0_audio_enable(struct amdgpu_device *adev,
1347 struct amdgpu_audio_pin *pin,
1353 WREG32_AUDIO_ENDPT(pin->offset, ixAZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL,
1354 enable ? AZALIA_F0_CODEC_PIN_CONTROL_HOT_PLUG_CONTROL__AUDIO_ENABLED_MASK : 0);
1357 static const u32 pin_offsets[7] =
1368 static int dce_v8_0_audio_init(struct amdgpu_device *adev)
1375 adev->mode_info.audio.enabled = true;
1377 if (adev->asic_type == CHIP_KAVERI) /* KV: 4 streams, 7 endpoints */
1378 adev->mode_info.audio.num_pins = 7;
1379 else if ((adev->asic_type == CHIP_KABINI) ||
1380 (adev->asic_type == CHIP_MULLINS)) /* KB/ML: 2 streams, 3 endpoints */
1381 adev->mode_info.audio.num_pins = 3;
1382 else if ((adev->asic_type == CHIP_BONAIRE) ||
1383 (adev->asic_type == CHIP_HAWAII))/* BN/HW: 6 streams, 7 endpoints */
1384 adev->mode_info.audio.num_pins = 7;
1386 adev->mode_info.audio.num_pins = 3;
1388 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1389 adev->mode_info.audio.pin[i].channels = -1;
1390 adev->mode_info.audio.pin[i].rate = -1;
1391 adev->mode_info.audio.pin[i].bits_per_sample = -1;
1392 adev->mode_info.audio.pin[i].status_bits = 0;
1393 adev->mode_info.audio.pin[i].category_code = 0;
1394 adev->mode_info.audio.pin[i].connected = false;
1395 adev->mode_info.audio.pin[i].offset = pin_offsets[i];
1396 adev->mode_info.audio.pin[i].id = i;
1397 /* disable audio. it will be set up later */
1398 /* XXX remove once we switch to ip funcs */
1399 dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
1405 static void dce_v8_0_audio_fini(struct amdgpu_device *adev)
1412 if (!adev->mode_info.audio.enabled)
1415 for (i = 0; i < adev->mode_info.audio.num_pins; i++)
1416 dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
1418 adev->mode_info.audio.enabled = false;
1422 * update the N and CTS parameters for a given pixel clock rate
1424 static void dce_v8_0_afmt_update_ACR(struct drm_encoder *encoder, uint32_t clock)
1426 struct drm_device *dev = encoder->dev;
1427 struct amdgpu_device *adev = dev->dev_private;
1428 struct amdgpu_afmt_acr acr = amdgpu_afmt_acr(clock);
1429 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1430 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1431 uint32_t offset = dig->afmt->offset;
1433 WREG32(mmHDMI_ACR_32_0 + offset, (acr.cts_32khz << HDMI_ACR_32_0__HDMI_ACR_CTS_32__SHIFT));
1434 WREG32(mmHDMI_ACR_32_1 + offset, acr.n_32khz);
1436 WREG32(mmHDMI_ACR_44_0 + offset, (acr.cts_44_1khz << HDMI_ACR_44_0__HDMI_ACR_CTS_44__SHIFT));
1437 WREG32(mmHDMI_ACR_44_1 + offset, acr.n_44_1khz);
1439 WREG32(mmHDMI_ACR_48_0 + offset, (acr.cts_48khz << HDMI_ACR_48_0__HDMI_ACR_CTS_48__SHIFT));
1440 WREG32(mmHDMI_ACR_48_1 + offset, acr.n_48khz);
1444 * build a HDMI Video Info Frame
1446 static void dce_v8_0_afmt_update_avi_infoframe(struct drm_encoder *encoder,
1447 void *buffer, size_t size)
1449 struct drm_device *dev = encoder->dev;
1450 struct amdgpu_device *adev = dev->dev_private;
1451 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1452 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1453 uint32_t offset = dig->afmt->offset;
1454 uint8_t *frame = buffer + 3;
1455 uint8_t *header = buffer;
1457 WREG32(mmAFMT_AVI_INFO0 + offset,
1458 frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
1459 WREG32(mmAFMT_AVI_INFO1 + offset,
1460 frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
1461 WREG32(mmAFMT_AVI_INFO2 + offset,
1462 frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
1463 WREG32(mmAFMT_AVI_INFO3 + offset,
1464 frame[0xC] | (frame[0xD] << 8) | (header[1] << 24));
1467 static void dce_v8_0_audio_set_dto(struct drm_encoder *encoder, u32 clock)
1469 struct drm_device *dev = encoder->dev;
1470 struct amdgpu_device *adev = dev->dev_private;
1471 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1472 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1473 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
1474 u32 dto_phase = 24 * 1000;
1475 u32 dto_modulo = clock;
1477 if (!dig || !dig->afmt)
1480 /* XXX two dtos; generally use dto0 for hdmi */
1481 /* Express [24MHz / target pixel clock] as an exact rational
1482 * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
1483 * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
1485 WREG32(mmDCCG_AUDIO_DTO_SOURCE, (amdgpu_crtc->crtc_id << DCCG_AUDIO_DTO_SOURCE__DCCG_AUDIO_DTO0_SOURCE_SEL__SHIFT));
1486 WREG32(mmDCCG_AUDIO_DTO0_PHASE, dto_phase);
1487 WREG32(mmDCCG_AUDIO_DTO0_MODULE, dto_modulo);
1491 * update the info frames with the data from the current display mode
1493 static void dce_v8_0_afmt_setmode(struct drm_encoder *encoder,
1494 struct drm_display_mode *mode)
1496 struct drm_device *dev = encoder->dev;
1497 struct amdgpu_device *adev = dev->dev_private;
1498 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1499 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1500 struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
1501 u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
1502 struct hdmi_avi_infoframe frame;
1503 uint32_t offset, val;
1507 if (!dig || !dig->afmt)
1510 /* Silent, r600_hdmi_enable will raise WARN for us */
1511 if (!dig->afmt->enabled)
1514 offset = dig->afmt->offset;
1516 /* hdmi deep color mode general control packets setup, if bpc > 8 */
1517 if (encoder->crtc) {
1518 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
1519 bpc = amdgpu_crtc->bpc;
1522 /* disable audio prior to setting up hw */
1523 dig->afmt->pin = dce_v8_0_audio_get_pin(adev);
1524 dce_v8_0_audio_enable(adev, dig->afmt->pin, false);
1526 dce_v8_0_audio_set_dto(encoder, mode->clock);
1528 WREG32(mmHDMI_VBI_PACKET_CONTROL + offset,
1529 HDMI_VBI_PACKET_CONTROL__HDMI_NULL_SEND_MASK); /* send null packets when required */
1531 WREG32(mmAFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
1533 val = RREG32(mmHDMI_CONTROL + offset);
1534 val &= ~HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
1535 val &= ~HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH_MASK;
1543 DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n",
1544 connector->name, bpc);
1547 val |= HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
1548 val |= 1 << HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH__SHIFT;
1549 DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n",
1553 val |= HDMI_CONTROL__HDMI_DEEP_COLOR_ENABLE_MASK;
1554 val |= 2 << HDMI_CONTROL__HDMI_DEEP_COLOR_DEPTH__SHIFT;
1555 DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n",
1560 WREG32(mmHDMI_CONTROL + offset, val);
1562 WREG32(mmHDMI_VBI_PACKET_CONTROL + offset,
1563 HDMI_VBI_PACKET_CONTROL__HDMI_NULL_SEND_MASK | /* send null packets when required */
1564 HDMI_VBI_PACKET_CONTROL__HDMI_GC_SEND_MASK | /* send general control packets */
1565 HDMI_VBI_PACKET_CONTROL__HDMI_GC_CONT_MASK); /* send general control packets every frame */
1567 WREG32(mmHDMI_INFOFRAME_CONTROL0 + offset,
1568 HDMI_INFOFRAME_CONTROL0__HDMI_AUDIO_INFO_SEND_MASK | /* enable audio info frames (frames won't be set until audio is enabled) */
1569 HDMI_INFOFRAME_CONTROL0__HDMI_AUDIO_INFO_CONT_MASK); /* required for audio info values to be updated */
1571 WREG32(mmAFMT_INFOFRAME_CONTROL0 + offset,
1572 AFMT_INFOFRAME_CONTROL0__AFMT_AUDIO_INFO_UPDATE_MASK); /* required for audio info values to be updated */
1574 WREG32(mmHDMI_INFOFRAME_CONTROL1 + offset,
1575 (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AUDIO_INFO_LINE__SHIFT)); /* anything other than 0 */
1577 WREG32(mmHDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
1579 WREG32(mmHDMI_AUDIO_PACKET_CONTROL + offset,
1580 (1 << HDMI_AUDIO_PACKET_CONTROL__HDMI_AUDIO_DELAY_EN__SHIFT) | /* set the default audio delay */
1581 (3 << HDMI_AUDIO_PACKET_CONTROL__HDMI_AUDIO_PACKETS_PER_LINE__SHIFT)); /* should be suffient for all audio modes and small enough for all hblanks */
1583 WREG32(mmAFMT_AUDIO_PACKET_CONTROL + offset,
1584 AFMT_AUDIO_PACKET_CONTROL__AFMT_60958_CS_UPDATE_MASK); /* allow 60958 channel status fields to be updated */
1586 /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
1589 WREG32(mmHDMI_ACR_PACKET_CONTROL + offset,
1590 HDMI_ACR_PACKET_CONTROL__HDMI_ACR_AUTO_SEND_MASK); /* allow hw to sent ACR packets when required */
1592 WREG32(mmHDMI_ACR_PACKET_CONTROL + offset,
1593 HDMI_ACR_PACKET_CONTROL__HDMI_ACR_SOURCE_MASK | /* select SW CTS value */
1594 HDMI_ACR_PACKET_CONTROL__HDMI_ACR_AUTO_SEND_MASK); /* allow hw to sent ACR packets when required */
1596 dce_v8_0_afmt_update_ACR(encoder, mode->clock);
1598 WREG32(mmAFMT_60958_0 + offset,
1599 (1 << AFMT_60958_0__AFMT_60958_CS_CHANNEL_NUMBER_L__SHIFT));
1601 WREG32(mmAFMT_60958_1 + offset,
1602 (2 << AFMT_60958_1__AFMT_60958_CS_CHANNEL_NUMBER_R__SHIFT));
1604 WREG32(mmAFMT_60958_2 + offset,
1605 (3 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_2__SHIFT) |
1606 (4 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_3__SHIFT) |
1607 (5 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_4__SHIFT) |
1608 (6 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_5__SHIFT) |
1609 (7 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_6__SHIFT) |
1610 (8 << AFMT_60958_2__AFMT_60958_CS_CHANNEL_NUMBER_7__SHIFT));
1612 dce_v8_0_audio_write_speaker_allocation(encoder);
1615 WREG32(mmAFMT_AUDIO_PACKET_CONTROL2 + offset,
1616 (0xff << AFMT_AUDIO_PACKET_CONTROL2__AFMT_AUDIO_CHANNEL_ENABLE__SHIFT));
1618 dce_v8_0_afmt_audio_select_pin(encoder);
1619 dce_v8_0_audio_write_sad_regs(encoder);
1620 dce_v8_0_audio_write_latency_fields(encoder, mode);
1622 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, connector, mode);
1624 DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
1628 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
1630 DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
1634 dce_v8_0_afmt_update_avi_infoframe(encoder, buffer, sizeof(buffer));
1636 WREG32_OR(mmHDMI_INFOFRAME_CONTROL0 + offset,
1637 HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_SEND_MASK | /* enable AVI info frames */
1638 HDMI_INFOFRAME_CONTROL0__HDMI_AVI_INFO_CONT_MASK); /* required for audio info values to be updated */
1640 WREG32_P(mmHDMI_INFOFRAME_CONTROL1 + offset,
1641 (2 << HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE__SHIFT), /* anything other than 0 */
1642 ~HDMI_INFOFRAME_CONTROL1__HDMI_AVI_INFO_LINE_MASK);
1644 WREG32_OR(mmAFMT_AUDIO_PACKET_CONTROL + offset,
1645 AFMT_AUDIO_PACKET_CONTROL__AFMT_AUDIO_SAMPLE_SEND_MASK); /* send audio packets */
1647 WREG32(mmAFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
1648 WREG32(mmAFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
1649 WREG32(mmAFMT_RAMP_CONTROL2 + offset, 0x00000001);
1650 WREG32(mmAFMT_RAMP_CONTROL3 + offset, 0x00000001);
1652 /* enable audio after setting up hw */
1653 dce_v8_0_audio_enable(adev, dig->afmt->pin, true);
1656 static void dce_v8_0_afmt_enable(struct drm_encoder *encoder, bool enable)
1658 struct drm_device *dev = encoder->dev;
1659 struct amdgpu_device *adev = dev->dev_private;
1660 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1661 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1663 if (!dig || !dig->afmt)
1666 /* Silent, r600_hdmi_enable will raise WARN for us */
1667 if (enable && dig->afmt->enabled)
1669 if (!enable && !dig->afmt->enabled)
1672 if (!enable && dig->afmt->pin) {
1673 dce_v8_0_audio_enable(adev, dig->afmt->pin, false);
1674 dig->afmt->pin = NULL;
1677 dig->afmt->enabled = enable;
1679 DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
1680 enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id);
1683 static int dce_v8_0_afmt_init(struct amdgpu_device *adev)
1687 for (i = 0; i < adev->mode_info.num_dig; i++)
1688 adev->mode_info.afmt[i] = NULL;
1690 /* DCE8 has audio blocks tied to DIG encoders */
1691 for (i = 0; i < adev->mode_info.num_dig; i++) {
1692 adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL);
1693 if (adev->mode_info.afmt[i]) {
1694 adev->mode_info.afmt[i]->offset = dig_offsets[i];
1695 adev->mode_info.afmt[i]->id = i;
1698 for (j = 0; j < i; j++) {
1699 kfree(adev->mode_info.afmt[j]);
1700 adev->mode_info.afmt[j] = NULL;
1708 static void dce_v8_0_afmt_fini(struct amdgpu_device *adev)
1712 for (i = 0; i < adev->mode_info.num_dig; i++) {
1713 kfree(adev->mode_info.afmt[i]);
1714 adev->mode_info.afmt[i] = NULL;
1718 static const u32 vga_control_regs[6] =
1728 static void dce_v8_0_vga_enable(struct drm_crtc *crtc, bool enable)
1730 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1731 struct drm_device *dev = crtc->dev;
1732 struct amdgpu_device *adev = dev->dev_private;
1735 vga_control = RREG32(vga_control_regs[amdgpu_crtc->crtc_id]) & ~1;
1737 WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control | 1);
1739 WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control);
1742 static void dce_v8_0_grph_enable(struct drm_crtc *crtc, bool enable)
1744 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1745 struct drm_device *dev = crtc->dev;
1746 struct amdgpu_device *adev = dev->dev_private;
1749 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 1);
1751 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0);
1754 static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
1755 struct drm_framebuffer *fb,
1756 int x, int y, int atomic)
1758 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1759 struct drm_device *dev = crtc->dev;
1760 struct amdgpu_device *adev = dev->dev_private;
1761 struct drm_framebuffer *target_fb;
1762 struct drm_gem_object *obj;
1763 struct amdgpu_bo *abo;
1764 uint64_t fb_location, tiling_flags;
1765 uint32_t fb_format, fb_pitch_pixels;
1766 u32 fb_swap = (GRPH_ENDIAN_NONE << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1768 u32 viewport_w, viewport_h;
1770 bool bypass_lut = false;
1771 struct drm_format_name_buf format_name;
1774 if (!atomic && !crtc->primary->fb) {
1775 DRM_DEBUG_KMS("No FB bound\n");
1782 target_fb = crtc->primary->fb;
1784 /* If atomic, assume fb object is pinned & idle & fenced and
1785 * just update base pointers
1787 obj = target_fb->obj[0];
1788 abo = gem_to_amdgpu_bo(obj);
1789 r = amdgpu_bo_reserve(abo, false);
1790 if (unlikely(r != 0))
1794 r = amdgpu_bo_pin(abo, AMDGPU_GEM_DOMAIN_VRAM);
1795 if (unlikely(r != 0)) {
1796 amdgpu_bo_unreserve(abo);
1800 fb_location = amdgpu_bo_gpu_offset(abo);
1802 amdgpu_bo_get_tiling_flags(abo, &tiling_flags);
1803 amdgpu_bo_unreserve(abo);
1805 pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
1807 switch (target_fb->format->format) {
1809 fb_format = ((GRPH_DEPTH_8BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1810 (GRPH_FORMAT_INDEXED << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1812 case DRM_FORMAT_XRGB4444:
1813 case DRM_FORMAT_ARGB4444:
1814 fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1815 (GRPH_FORMAT_ARGB4444 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1817 fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1820 case DRM_FORMAT_XRGB1555:
1821 case DRM_FORMAT_ARGB1555:
1822 fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1823 (GRPH_FORMAT_ARGB1555 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1825 fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1828 case DRM_FORMAT_BGRX5551:
1829 case DRM_FORMAT_BGRA5551:
1830 fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1831 (GRPH_FORMAT_BGRA5551 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1833 fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1836 case DRM_FORMAT_RGB565:
1837 fb_format = ((GRPH_DEPTH_16BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1838 (GRPH_FORMAT_ARGB565 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1840 fb_swap = (GRPH_ENDIAN_8IN16 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1843 case DRM_FORMAT_XRGB8888:
1844 case DRM_FORMAT_ARGB8888:
1845 fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1846 (GRPH_FORMAT_ARGB8888 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1848 fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1851 case DRM_FORMAT_XRGB2101010:
1852 case DRM_FORMAT_ARGB2101010:
1853 fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1854 (GRPH_FORMAT_ARGB2101010 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1856 fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1858 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
1861 case DRM_FORMAT_BGRX1010102:
1862 case DRM_FORMAT_BGRA1010102:
1863 fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1864 (GRPH_FORMAT_BGRA1010102 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1866 fb_swap = (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1868 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
1871 case DRM_FORMAT_XBGR8888:
1872 case DRM_FORMAT_ABGR8888:
1873 fb_format = ((GRPH_DEPTH_32BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
1874 (GRPH_FORMAT_ARGB8888 << GRPH_CONTROL__GRPH_FORMAT__SHIFT));
1875 fb_swap = ((GRPH_RED_SEL_B << GRPH_SWAP_CNTL__GRPH_RED_CROSSBAR__SHIFT) |
1876 (GRPH_BLUE_SEL_R << GRPH_SWAP_CNTL__GRPH_BLUE_CROSSBAR__SHIFT));
1878 fb_swap |= (GRPH_ENDIAN_8IN32 << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
1882 DRM_ERROR("Unsupported screen format %s\n",
1883 drm_get_format_name(target_fb->format->format, &format_name));
1887 if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
1888 unsigned bankw, bankh, mtaspect, tile_split, num_banks;
1890 bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
1891 bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
1892 mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
1893 tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
1894 num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
1896 fb_format |= (num_banks << GRPH_CONTROL__GRPH_NUM_BANKS__SHIFT);
1897 fb_format |= (GRPH_ARRAY_2D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT);
1898 fb_format |= (tile_split << GRPH_CONTROL__GRPH_TILE_SPLIT__SHIFT);
1899 fb_format |= (bankw << GRPH_CONTROL__GRPH_BANK_WIDTH__SHIFT);
1900 fb_format |= (bankh << GRPH_CONTROL__GRPH_BANK_HEIGHT__SHIFT);
1901 fb_format |= (mtaspect << GRPH_CONTROL__GRPH_MACRO_TILE_ASPECT__SHIFT);
1902 fb_format |= (DISPLAY_MICRO_TILING << GRPH_CONTROL__GRPH_MICRO_TILE_MODE__SHIFT);
1903 } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
1904 fb_format |= (GRPH_ARRAY_1D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT);
1907 fb_format |= (pipe_config << GRPH_CONTROL__GRPH_PIPE_CONFIG__SHIFT);
1909 dce_v8_0_vga_enable(crtc, false);
1911 /* Make sure surface address is updated at vertical blank rather than
1914 WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, 0);
1916 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
1917 upper_32_bits(fb_location));
1918 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
1919 upper_32_bits(fb_location));
1920 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
1921 (u32)fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
1922 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
1923 (u32) fb_location & GRPH_SECONDARY_SURFACE_ADDRESS__GRPH_SECONDARY_SURFACE_ADDRESS_MASK);
1924 WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format);
1925 WREG32(mmGRPH_SWAP_CNTL + amdgpu_crtc->crtc_offset, fb_swap);
1928 * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
1929 * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
1930 * retain the full precision throughout the pipeline.
1932 WREG32_P(mmGRPH_LUT_10BIT_BYPASS_CONTROL + amdgpu_crtc->crtc_offset,
1933 (bypass_lut ? LUT_10BIT_BYPASS_EN : 0),
1934 ~LUT_10BIT_BYPASS_EN);
1937 DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
1939 WREG32(mmGRPH_SURFACE_OFFSET_X + amdgpu_crtc->crtc_offset, 0);
1940 WREG32(mmGRPH_SURFACE_OFFSET_Y + amdgpu_crtc->crtc_offset, 0);
1941 WREG32(mmGRPH_X_START + amdgpu_crtc->crtc_offset, 0);
1942 WREG32(mmGRPH_Y_START + amdgpu_crtc->crtc_offset, 0);
1943 WREG32(mmGRPH_X_END + amdgpu_crtc->crtc_offset, target_fb->width);
1944 WREG32(mmGRPH_Y_END + amdgpu_crtc->crtc_offset, target_fb->height);
1946 fb_pitch_pixels = target_fb->pitches[0] / target_fb->format->cpp[0];
1947 WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, fb_pitch_pixels);
1949 dce_v8_0_grph_enable(crtc, true);
1951 WREG32(mmLB_DESKTOP_HEIGHT + amdgpu_crtc->crtc_offset,
1956 WREG32(mmVIEWPORT_START + amdgpu_crtc->crtc_offset,
1958 viewport_w = crtc->mode.hdisplay;
1959 viewport_h = (crtc->mode.vdisplay + 1) & ~1;
1960 WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
1961 (viewport_w << 16) | viewport_h);
1963 /* set pageflip to happen anywhere in vblank interval */
1964 WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
1966 if (!atomic && fb && fb != crtc->primary->fb) {
1967 abo = gem_to_amdgpu_bo(fb->obj[0]);
1968 r = amdgpu_bo_reserve(abo, true);
1969 if (unlikely(r != 0))
1971 amdgpu_bo_unpin(abo);
1972 amdgpu_bo_unreserve(abo);
1975 /* Bytes per pixel may have changed */
1976 dce_v8_0_bandwidth_update(adev);
1981 static void dce_v8_0_set_interleave(struct drm_crtc *crtc,
1982 struct drm_display_mode *mode)
1984 struct drm_device *dev = crtc->dev;
1985 struct amdgpu_device *adev = dev->dev_private;
1986 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1988 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1989 WREG32(mmLB_DATA_FORMAT + amdgpu_crtc->crtc_offset,
1990 LB_DATA_FORMAT__INTERLEAVE_EN__SHIFT);
1992 WREG32(mmLB_DATA_FORMAT + amdgpu_crtc->crtc_offset, 0);
1995 static void dce_v8_0_crtc_load_lut(struct drm_crtc *crtc)
1997 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1998 struct drm_device *dev = crtc->dev;
1999 struct amdgpu_device *adev = dev->dev_private;
2003 DRM_DEBUG_KMS("%d\n", amdgpu_crtc->crtc_id);
2005 WREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
2006 ((INPUT_CSC_BYPASS << INPUT_CSC_CONTROL__INPUT_CSC_GRPH_MODE__SHIFT) |
2007 (INPUT_CSC_BYPASS << INPUT_CSC_CONTROL__INPUT_CSC_OVL_MODE__SHIFT)));
2008 WREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset,
2009 PRESCALE_GRPH_CONTROL__GRPH_PRESCALE_BYPASS_MASK);
2010 WREG32(mmPRESCALE_OVL_CONTROL + amdgpu_crtc->crtc_offset,
2011 PRESCALE_OVL_CONTROL__OVL_PRESCALE_BYPASS_MASK);
2012 WREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset,
2013 ((INPUT_GAMMA_USE_LUT << INPUT_GAMMA_CONTROL__GRPH_INPUT_GAMMA_MODE__SHIFT) |
2014 (INPUT_GAMMA_USE_LUT << INPUT_GAMMA_CONTROL__OVL_INPUT_GAMMA_MODE__SHIFT)));
2016 WREG32(mmDC_LUT_CONTROL + amdgpu_crtc->crtc_offset, 0);
2018 WREG32(mmDC_LUT_BLACK_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0);
2019 WREG32(mmDC_LUT_BLACK_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0);
2020 WREG32(mmDC_LUT_BLACK_OFFSET_RED + amdgpu_crtc->crtc_offset, 0);
2022 WREG32(mmDC_LUT_WHITE_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0xffff);
2023 WREG32(mmDC_LUT_WHITE_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0xffff);
2024 WREG32(mmDC_LUT_WHITE_OFFSET_RED + amdgpu_crtc->crtc_offset, 0xffff);
2026 WREG32(mmDC_LUT_RW_MODE + amdgpu_crtc->crtc_offset, 0);
2027 WREG32(mmDC_LUT_WRITE_EN_MASK + amdgpu_crtc->crtc_offset, 0x00000007);
2029 WREG32(mmDC_LUT_RW_INDEX + amdgpu_crtc->crtc_offset, 0);
2030 r = crtc->gamma_store;
2031 g = r + crtc->gamma_size;
2032 b = g + crtc->gamma_size;
2033 for (i = 0; i < 256; i++) {
2034 WREG32(mmDC_LUT_30_COLOR + amdgpu_crtc->crtc_offset,
2035 ((*r++ & 0xffc0) << 14) |
2036 ((*g++ & 0xffc0) << 4) |
2040 WREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
2041 ((DEGAMMA_BYPASS << DEGAMMA_CONTROL__GRPH_DEGAMMA_MODE__SHIFT) |
2042 (DEGAMMA_BYPASS << DEGAMMA_CONTROL__OVL_DEGAMMA_MODE__SHIFT) |
2043 (DEGAMMA_BYPASS << DEGAMMA_CONTROL__CURSOR_DEGAMMA_MODE__SHIFT)));
2044 WREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset,
2045 ((GAMUT_REMAP_BYPASS << GAMUT_REMAP_CONTROL__GRPH_GAMUT_REMAP_MODE__SHIFT) |
2046 (GAMUT_REMAP_BYPASS << GAMUT_REMAP_CONTROL__OVL_GAMUT_REMAP_MODE__SHIFT)));
2047 WREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
2048 ((REGAMMA_BYPASS << REGAMMA_CONTROL__GRPH_REGAMMA_MODE__SHIFT) |
2049 (REGAMMA_BYPASS << REGAMMA_CONTROL__OVL_REGAMMA_MODE__SHIFT)));
2050 WREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
2051 ((OUTPUT_CSC_BYPASS << OUTPUT_CSC_CONTROL__OUTPUT_CSC_GRPH_MODE__SHIFT) |
2052 (OUTPUT_CSC_BYPASS << OUTPUT_CSC_CONTROL__OUTPUT_CSC_OVL_MODE__SHIFT)));
2053 /* XXX match this to the depth of the crtc fmt block, move to modeset? */
2054 WREG32(0x1a50 + amdgpu_crtc->crtc_offset, 0);
2055 /* XXX this only needs to be programmed once per crtc at startup,
2056 * not sure where the best place for it is
2058 WREG32(mmALPHA_CONTROL + amdgpu_crtc->crtc_offset,
2059 ALPHA_CONTROL__CURSOR_ALPHA_BLND_ENA_MASK);
2062 static int dce_v8_0_pick_dig_encoder(struct drm_encoder *encoder)
2064 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2065 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
2067 switch (amdgpu_encoder->encoder_id) {
2068 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2074 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2080 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2086 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
2090 DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id);
2096 * dce_v8_0_pick_pll - Allocate a PPLL for use by the crtc.
2100 * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
2101 * a single PPLL can be used for all DP crtcs/encoders. For non-DP
2102 * monitors a dedicated PPLL must be used. If a particular board has
2103 * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
2104 * as there is no need to program the PLL itself. If we are not able to
2105 * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
2106 * avoid messing up an existing monitor.
2108 * Asic specific PLL information
2112 * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP)
2114 * - PPLL0, PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC
2117 static u32 dce_v8_0_pick_pll(struct drm_crtc *crtc)
2119 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2120 struct drm_device *dev = crtc->dev;
2121 struct amdgpu_device *adev = dev->dev_private;
2125 if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) {
2126 if (adev->clock.dp_extclk)
2127 /* skip PPLL programming if using ext clock */
2128 return ATOM_PPLL_INVALID;
2130 /* use the same PPLL for all DP monitors */
2131 pll = amdgpu_pll_get_shared_dp_ppll(crtc);
2132 if (pll != ATOM_PPLL_INVALID)
2136 /* use the same PPLL for all monitors with the same clock */
2137 pll = amdgpu_pll_get_shared_nondp_ppll(crtc);
2138 if (pll != ATOM_PPLL_INVALID)
2141 /* otherwise, pick one of the plls */
2142 if ((adev->asic_type == CHIP_KABINI) ||
2143 (adev->asic_type == CHIP_MULLINS)) {
2144 /* KB/ML has PPLL1 and PPLL2 */
2145 pll_in_use = amdgpu_pll_get_use_mask(crtc);
2146 if (!(pll_in_use & (1 << ATOM_PPLL2)))
2148 if (!(pll_in_use & (1 << ATOM_PPLL1)))
2150 DRM_ERROR("unable to allocate a PPLL\n");
2151 return ATOM_PPLL_INVALID;
2153 /* CI/KV has PPLL0, PPLL1, and PPLL2 */
2154 pll_in_use = amdgpu_pll_get_use_mask(crtc);
2155 if (!(pll_in_use & (1 << ATOM_PPLL2)))
2157 if (!(pll_in_use & (1 << ATOM_PPLL1)))
2159 if (!(pll_in_use & (1 << ATOM_PPLL0)))
2161 DRM_ERROR("unable to allocate a PPLL\n");
2162 return ATOM_PPLL_INVALID;
2164 return ATOM_PPLL_INVALID;
2167 static void dce_v8_0_lock_cursor(struct drm_crtc *crtc, bool lock)
2169 struct amdgpu_device *adev = crtc->dev->dev_private;
2170 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2173 cur_lock = RREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset);
2175 cur_lock |= CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
2177 cur_lock &= ~CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
2178 WREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset, cur_lock);
2181 static void dce_v8_0_hide_cursor(struct drm_crtc *crtc)
2183 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2184 struct amdgpu_device *adev = crtc->dev->dev_private;
2186 WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
2187 (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
2188 (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
2191 static void dce_v8_0_show_cursor(struct drm_crtc *crtc)
2193 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2194 struct amdgpu_device *adev = crtc->dev->dev_private;
2196 WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
2197 upper_32_bits(amdgpu_crtc->cursor_addr));
2198 WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
2199 lower_32_bits(amdgpu_crtc->cursor_addr));
2201 WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
2202 CUR_CONTROL__CURSOR_EN_MASK |
2203 (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
2204 (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
2207 static int dce_v8_0_cursor_move_locked(struct drm_crtc *crtc,
2210 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2211 struct amdgpu_device *adev = crtc->dev->dev_private;
2212 int xorigin = 0, yorigin = 0;
2214 amdgpu_crtc->cursor_x = x;
2215 amdgpu_crtc->cursor_y = y;
2217 /* avivo cursor are offset into the total surface */
2220 DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
2223 xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
2227 yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
2231 WREG32(mmCUR_POSITION + amdgpu_crtc->crtc_offset, (x << 16) | y);
2232 WREG32(mmCUR_HOT_SPOT + amdgpu_crtc->crtc_offset, (xorigin << 16) | yorigin);
2233 WREG32(mmCUR_SIZE + amdgpu_crtc->crtc_offset,
2234 ((amdgpu_crtc->cursor_width - 1) << 16) | (amdgpu_crtc->cursor_height - 1));
2239 static int dce_v8_0_crtc_cursor_move(struct drm_crtc *crtc,
2244 dce_v8_0_lock_cursor(crtc, true);
2245 ret = dce_v8_0_cursor_move_locked(crtc, x, y);
2246 dce_v8_0_lock_cursor(crtc, false);
2251 static int dce_v8_0_crtc_cursor_set2(struct drm_crtc *crtc,
2252 struct drm_file *file_priv,
2259 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2260 struct drm_gem_object *obj;
2261 struct amdgpu_bo *aobj;
2265 /* turn off cursor */
2266 dce_v8_0_hide_cursor(crtc);
2271 if ((width > amdgpu_crtc->max_cursor_width) ||
2272 (height > amdgpu_crtc->max_cursor_height)) {
2273 DRM_ERROR("bad cursor width or height %d x %d\n", width, height);
2277 obj = drm_gem_object_lookup(file_priv, handle);
2279 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, amdgpu_crtc->crtc_id);
2283 aobj = gem_to_amdgpu_bo(obj);
2284 ret = amdgpu_bo_reserve(aobj, false);
2286 drm_gem_object_put_unlocked(obj);
2290 ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM);
2291 amdgpu_bo_unreserve(aobj);
2293 DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret);
2294 drm_gem_object_put_unlocked(obj);
2297 amdgpu_crtc->cursor_addr = amdgpu_bo_gpu_offset(aobj);
2299 dce_v8_0_lock_cursor(crtc, true);
2301 if (width != amdgpu_crtc->cursor_width ||
2302 height != amdgpu_crtc->cursor_height ||
2303 hot_x != amdgpu_crtc->cursor_hot_x ||
2304 hot_y != amdgpu_crtc->cursor_hot_y) {
2307 x = amdgpu_crtc->cursor_x + amdgpu_crtc->cursor_hot_x - hot_x;
2308 y = amdgpu_crtc->cursor_y + amdgpu_crtc->cursor_hot_y - hot_y;
2310 dce_v8_0_cursor_move_locked(crtc, x, y);
2312 amdgpu_crtc->cursor_width = width;
2313 amdgpu_crtc->cursor_height = height;
2314 amdgpu_crtc->cursor_hot_x = hot_x;
2315 amdgpu_crtc->cursor_hot_y = hot_y;
2318 dce_v8_0_show_cursor(crtc);
2319 dce_v8_0_lock_cursor(crtc, false);
2322 if (amdgpu_crtc->cursor_bo) {
2323 struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
2324 ret = amdgpu_bo_reserve(aobj, true);
2325 if (likely(ret == 0)) {
2326 amdgpu_bo_unpin(aobj);
2327 amdgpu_bo_unreserve(aobj);
2329 drm_gem_object_put_unlocked(amdgpu_crtc->cursor_bo);
2332 amdgpu_crtc->cursor_bo = obj;
2336 static void dce_v8_0_cursor_reset(struct drm_crtc *crtc)
2338 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2340 if (amdgpu_crtc->cursor_bo) {
2341 dce_v8_0_lock_cursor(crtc, true);
2343 dce_v8_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x,
2344 amdgpu_crtc->cursor_y);
2346 dce_v8_0_show_cursor(crtc);
2348 dce_v8_0_lock_cursor(crtc, false);
2352 static int dce_v8_0_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
2353 u16 *blue, uint32_t size,
2354 struct drm_modeset_acquire_ctx *ctx)
2356 dce_v8_0_crtc_load_lut(crtc);
2361 static void dce_v8_0_crtc_destroy(struct drm_crtc *crtc)
2363 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2365 drm_crtc_cleanup(crtc);
2369 static const struct drm_crtc_funcs dce_v8_0_crtc_funcs = {
2370 .cursor_set2 = dce_v8_0_crtc_cursor_set2,
2371 .cursor_move = dce_v8_0_crtc_cursor_move,
2372 .gamma_set = dce_v8_0_crtc_gamma_set,
2373 .set_config = amdgpu_display_crtc_set_config,
2374 .destroy = dce_v8_0_crtc_destroy,
2375 .page_flip_target = amdgpu_display_crtc_page_flip_target,
2378 static void dce_v8_0_crtc_dpms(struct drm_crtc *crtc, int mode)
2380 struct drm_device *dev = crtc->dev;
2381 struct amdgpu_device *adev = dev->dev_private;
2382 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2386 case DRM_MODE_DPMS_ON:
2387 amdgpu_crtc->enabled = true;
2388 amdgpu_atombios_crtc_enable(crtc, ATOM_ENABLE);
2389 dce_v8_0_vga_enable(crtc, true);
2390 amdgpu_atombios_crtc_blank(crtc, ATOM_DISABLE);
2391 dce_v8_0_vga_enable(crtc, false);
2392 /* Make sure VBLANK and PFLIP interrupts are still enabled */
2393 type = amdgpu_display_crtc_idx_to_irq_type(adev,
2394 amdgpu_crtc->crtc_id);
2395 amdgpu_irq_update(adev, &adev->crtc_irq, type);
2396 amdgpu_irq_update(adev, &adev->pageflip_irq, type);
2397 drm_crtc_vblank_on(crtc);
2398 dce_v8_0_crtc_load_lut(crtc);
2400 case DRM_MODE_DPMS_STANDBY:
2401 case DRM_MODE_DPMS_SUSPEND:
2402 case DRM_MODE_DPMS_OFF:
2403 drm_crtc_vblank_off(crtc);
2404 if (amdgpu_crtc->enabled) {
2405 dce_v8_0_vga_enable(crtc, true);
2406 amdgpu_atombios_crtc_blank(crtc, ATOM_ENABLE);
2407 dce_v8_0_vga_enable(crtc, false);
2409 amdgpu_atombios_crtc_enable(crtc, ATOM_DISABLE);
2410 amdgpu_crtc->enabled = false;
2413 /* adjust pm to dpms */
2414 amdgpu_pm_compute_clocks(adev);
2417 static void dce_v8_0_crtc_prepare(struct drm_crtc *crtc)
2419 /* disable crtc pair power gating before programming */
2420 amdgpu_atombios_crtc_powergate(crtc, ATOM_DISABLE);
2421 amdgpu_atombios_crtc_lock(crtc, ATOM_ENABLE);
2422 dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
2425 static void dce_v8_0_crtc_commit(struct drm_crtc *crtc)
2427 dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
2428 amdgpu_atombios_crtc_lock(crtc, ATOM_DISABLE);
2431 static void dce_v8_0_crtc_disable(struct drm_crtc *crtc)
2433 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2434 struct drm_device *dev = crtc->dev;
2435 struct amdgpu_device *adev = dev->dev_private;
2436 struct amdgpu_atom_ss ss;
2439 dce_v8_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
2440 if (crtc->primary->fb) {
2442 struct amdgpu_bo *abo;
2444 abo = gem_to_amdgpu_bo(crtc->primary->fb->obj[0]);
2445 r = amdgpu_bo_reserve(abo, true);
2447 DRM_ERROR("failed to reserve abo before unpin\n");
2449 amdgpu_bo_unpin(abo);
2450 amdgpu_bo_unreserve(abo);
2453 /* disable the GRPH */
2454 dce_v8_0_grph_enable(crtc, false);
2456 amdgpu_atombios_crtc_powergate(crtc, ATOM_ENABLE);
2458 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2459 if (adev->mode_info.crtcs[i] &&
2460 adev->mode_info.crtcs[i]->enabled &&
2461 i != amdgpu_crtc->crtc_id &&
2462 amdgpu_crtc->pll_id == adev->mode_info.crtcs[i]->pll_id) {
2463 /* one other crtc is using this pll don't turn
2470 switch (amdgpu_crtc->pll_id) {
2473 /* disable the ppll */
2474 amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
2475 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
2478 /* disable the ppll */
2479 if ((adev->asic_type == CHIP_KAVERI) ||
2480 (adev->asic_type == CHIP_BONAIRE) ||
2481 (adev->asic_type == CHIP_HAWAII))
2482 amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
2483 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
2489 amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
2490 amdgpu_crtc->adjusted_clock = 0;
2491 amdgpu_crtc->encoder = NULL;
2492 amdgpu_crtc->connector = NULL;
2495 static int dce_v8_0_crtc_mode_set(struct drm_crtc *crtc,
2496 struct drm_display_mode *mode,
2497 struct drm_display_mode *adjusted_mode,
2498 int x, int y, struct drm_framebuffer *old_fb)
2500 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2502 if (!amdgpu_crtc->adjusted_clock)
2505 amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode);
2506 amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode);
2507 dce_v8_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
2508 amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode);
2509 amdgpu_atombios_crtc_scaler_setup(crtc);
2510 dce_v8_0_cursor_reset(crtc);
2511 /* update the hw version fpr dpm */
2512 amdgpu_crtc->hw_mode = *adjusted_mode;
2517 static bool dce_v8_0_crtc_mode_fixup(struct drm_crtc *crtc,
2518 const struct drm_display_mode *mode,
2519 struct drm_display_mode *adjusted_mode)
2521 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2522 struct drm_device *dev = crtc->dev;
2523 struct drm_encoder *encoder;
2525 /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
2526 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2527 if (encoder->crtc == crtc) {
2528 amdgpu_crtc->encoder = encoder;
2529 amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder);
2533 if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) {
2534 amdgpu_crtc->encoder = NULL;
2535 amdgpu_crtc->connector = NULL;
2538 if (!amdgpu_display_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
2540 if (amdgpu_atombios_crtc_prepare_pll(crtc, adjusted_mode))
2543 amdgpu_crtc->pll_id = dce_v8_0_pick_pll(crtc);
2544 /* if we can't get a PPLL for a non-DP encoder, fail */
2545 if ((amdgpu_crtc->pll_id == ATOM_PPLL_INVALID) &&
2546 !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder)))
2552 static int dce_v8_0_crtc_set_base(struct drm_crtc *crtc, int x, int y,
2553 struct drm_framebuffer *old_fb)
2555 return dce_v8_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
2558 static int dce_v8_0_crtc_set_base_atomic(struct drm_crtc *crtc,
2559 struct drm_framebuffer *fb,
2560 int x, int y, enum mode_set_atomic state)
2562 return dce_v8_0_crtc_do_set_base(crtc, fb, x, y, 1);
2565 static const struct drm_crtc_helper_funcs dce_v8_0_crtc_helper_funcs = {
2566 .dpms = dce_v8_0_crtc_dpms,
2567 .mode_fixup = dce_v8_0_crtc_mode_fixup,
2568 .mode_set = dce_v8_0_crtc_mode_set,
2569 .mode_set_base = dce_v8_0_crtc_set_base,
2570 .mode_set_base_atomic = dce_v8_0_crtc_set_base_atomic,
2571 .prepare = dce_v8_0_crtc_prepare,
2572 .commit = dce_v8_0_crtc_commit,
2573 .disable = dce_v8_0_crtc_disable,
2576 static int dce_v8_0_crtc_init(struct amdgpu_device *adev, int index)
2578 struct amdgpu_crtc *amdgpu_crtc;
2580 amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) +
2581 (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
2582 if (amdgpu_crtc == NULL)
2585 drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_v8_0_crtc_funcs);
2587 drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256);
2588 amdgpu_crtc->crtc_id = index;
2589 adev->mode_info.crtcs[index] = amdgpu_crtc;
2591 amdgpu_crtc->max_cursor_width = CIK_CURSOR_WIDTH;
2592 amdgpu_crtc->max_cursor_height = CIK_CURSOR_HEIGHT;
2593 adev->ddev->mode_config.cursor_width = amdgpu_crtc->max_cursor_width;
2594 adev->ddev->mode_config.cursor_height = amdgpu_crtc->max_cursor_height;
2596 amdgpu_crtc->crtc_offset = crtc_offsets[amdgpu_crtc->crtc_id];
2598 amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
2599 amdgpu_crtc->adjusted_clock = 0;
2600 amdgpu_crtc->encoder = NULL;
2601 amdgpu_crtc->connector = NULL;
2602 drm_crtc_helper_add(&amdgpu_crtc->base, &dce_v8_0_crtc_helper_funcs);
2607 static int dce_v8_0_early_init(void *handle)
2609 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2611 adev->audio_endpt_rreg = &dce_v8_0_audio_endpt_rreg;
2612 adev->audio_endpt_wreg = &dce_v8_0_audio_endpt_wreg;
2614 dce_v8_0_set_display_funcs(adev);
2616 adev->mode_info.num_crtc = dce_v8_0_get_num_crtc(adev);
2618 switch (adev->asic_type) {
2621 adev->mode_info.num_hpd = 6;
2622 adev->mode_info.num_dig = 6;
2625 adev->mode_info.num_hpd = 6;
2626 adev->mode_info.num_dig = 7;
2630 adev->mode_info.num_hpd = 6;
2631 adev->mode_info.num_dig = 6; /* ? */
2634 /* FIXME: not supported yet */
2638 dce_v8_0_set_irq_funcs(adev);
2643 static int dce_v8_0_sw_init(void *handle)
2646 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2648 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2649 r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, i + 1, &adev->crtc_irq);
2654 for (i = 8; i < 20; i += 2) {
2655 r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, i, &adev->pageflip_irq);
2661 r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, 42, &adev->hpd_irq);
2665 adev->ddev->mode_config.funcs = &amdgpu_mode_funcs;
2667 adev->ddev->mode_config.async_page_flip = true;
2669 adev->ddev->mode_config.max_width = 16384;
2670 adev->ddev->mode_config.max_height = 16384;
2672 adev->ddev->mode_config.preferred_depth = 24;
2673 adev->ddev->mode_config.prefer_shadow = 1;
2675 adev->ddev->mode_config.fb_base = adev->gmc.aper_base;
2677 r = amdgpu_display_modeset_create_props(adev);
2681 adev->ddev->mode_config.max_width = 16384;
2682 adev->ddev->mode_config.max_height = 16384;
2684 /* allocate crtcs */
2685 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2686 r = dce_v8_0_crtc_init(adev, i);
2691 if (amdgpu_atombios_get_connector_info_from_object_table(adev))
2692 amdgpu_display_print_display_setup(adev->ddev);
2697 r = dce_v8_0_afmt_init(adev);
2701 r = dce_v8_0_audio_init(adev);
2705 drm_kms_helper_poll_init(adev->ddev);
2707 adev->mode_info.mode_config_initialized = true;
2711 static int dce_v8_0_sw_fini(void *handle)
2713 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2715 kfree(adev->mode_info.bios_hardcoded_edid);
2717 drm_kms_helper_poll_fini(adev->ddev);
2719 dce_v8_0_audio_fini(adev);
2721 dce_v8_0_afmt_fini(adev);
2723 drm_mode_config_cleanup(adev->ddev);
2724 adev->mode_info.mode_config_initialized = false;
2729 static int dce_v8_0_hw_init(void *handle)
2732 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2734 /* disable vga render */
2735 dce_v8_0_set_vga_render_state(adev, false);
2736 /* init dig PHYs, disp eng pll */
2737 amdgpu_atombios_encoder_init_dig(adev);
2738 amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk);
2740 /* initialize hpd */
2741 dce_v8_0_hpd_init(adev);
2743 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
2744 dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
2747 dce_v8_0_pageflip_interrupt_init(adev);
2752 static int dce_v8_0_hw_fini(void *handle)
2755 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2757 dce_v8_0_hpd_fini(adev);
2759 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
2760 dce_v8_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
2763 dce_v8_0_pageflip_interrupt_fini(adev);
2768 static int dce_v8_0_suspend(void *handle)
2770 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2772 adev->mode_info.bl_level =
2773 amdgpu_atombios_encoder_get_backlight_level_from_reg(adev);
2775 return dce_v8_0_hw_fini(handle);
2778 static int dce_v8_0_resume(void *handle)
2780 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2783 amdgpu_atombios_encoder_set_backlight_level_to_reg(adev,
2784 adev->mode_info.bl_level);
2786 ret = dce_v8_0_hw_init(handle);
2788 /* turn on the BL */
2789 if (adev->mode_info.bl_encoder) {
2790 u8 bl_level = amdgpu_display_backlight_get_level(adev,
2791 adev->mode_info.bl_encoder);
2792 amdgpu_display_backlight_set_level(adev, adev->mode_info.bl_encoder,
2799 static bool dce_v8_0_is_idle(void *handle)
2804 static int dce_v8_0_wait_for_idle(void *handle)
2809 static int dce_v8_0_soft_reset(void *handle)
2811 u32 srbm_soft_reset = 0, tmp;
2812 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2814 if (dce_v8_0_is_display_hung(adev))
2815 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK;
2817 if (srbm_soft_reset) {
2818 tmp = RREG32(mmSRBM_SOFT_RESET);
2819 tmp |= srbm_soft_reset;
2820 dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
2821 WREG32(mmSRBM_SOFT_RESET, tmp);
2822 tmp = RREG32(mmSRBM_SOFT_RESET);
2826 tmp &= ~srbm_soft_reset;
2827 WREG32(mmSRBM_SOFT_RESET, tmp);
2828 tmp = RREG32(mmSRBM_SOFT_RESET);
2830 /* Wait a little for things to settle down */
2836 static void dce_v8_0_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev,
2838 enum amdgpu_interrupt_state state)
2840 u32 reg_block, lb_interrupt_mask;
2842 if (crtc >= adev->mode_info.num_crtc) {
2843 DRM_DEBUG("invalid crtc %d\n", crtc);
2849 reg_block = CRTC0_REGISTER_OFFSET;
2852 reg_block = CRTC1_REGISTER_OFFSET;
2855 reg_block = CRTC2_REGISTER_OFFSET;
2858 reg_block = CRTC3_REGISTER_OFFSET;
2861 reg_block = CRTC4_REGISTER_OFFSET;
2864 reg_block = CRTC5_REGISTER_OFFSET;
2867 DRM_DEBUG("invalid crtc %d\n", crtc);
2872 case AMDGPU_IRQ_STATE_DISABLE:
2873 lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
2874 lb_interrupt_mask &= ~LB_INTERRUPT_MASK__VBLANK_INTERRUPT_MASK_MASK;
2875 WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
2877 case AMDGPU_IRQ_STATE_ENABLE:
2878 lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
2879 lb_interrupt_mask |= LB_INTERRUPT_MASK__VBLANK_INTERRUPT_MASK_MASK;
2880 WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
2887 static void dce_v8_0_set_crtc_vline_interrupt_state(struct amdgpu_device *adev,
2889 enum amdgpu_interrupt_state state)
2891 u32 reg_block, lb_interrupt_mask;
2893 if (crtc >= adev->mode_info.num_crtc) {
2894 DRM_DEBUG("invalid crtc %d\n", crtc);
2900 reg_block = CRTC0_REGISTER_OFFSET;
2903 reg_block = CRTC1_REGISTER_OFFSET;
2906 reg_block = CRTC2_REGISTER_OFFSET;
2909 reg_block = CRTC3_REGISTER_OFFSET;
2912 reg_block = CRTC4_REGISTER_OFFSET;
2915 reg_block = CRTC5_REGISTER_OFFSET;
2918 DRM_DEBUG("invalid crtc %d\n", crtc);
2923 case AMDGPU_IRQ_STATE_DISABLE:
2924 lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
2925 lb_interrupt_mask &= ~LB_INTERRUPT_MASK__VLINE_INTERRUPT_MASK_MASK;
2926 WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
2928 case AMDGPU_IRQ_STATE_ENABLE:
2929 lb_interrupt_mask = RREG32(mmLB_INTERRUPT_MASK + reg_block);
2930 lb_interrupt_mask |= LB_INTERRUPT_MASK__VLINE_INTERRUPT_MASK_MASK;
2931 WREG32(mmLB_INTERRUPT_MASK + reg_block, lb_interrupt_mask);
2938 static int dce_v8_0_set_hpd_interrupt_state(struct amdgpu_device *adev,
2939 struct amdgpu_irq_src *src,
2941 enum amdgpu_interrupt_state state)
2943 u32 dc_hpd_int_cntl;
2945 if (type >= adev->mode_info.num_hpd) {
2946 DRM_DEBUG("invalid hdp %d\n", type);
2951 case AMDGPU_IRQ_STATE_DISABLE:
2952 dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
2953 dc_hpd_int_cntl &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
2954 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
2956 case AMDGPU_IRQ_STATE_ENABLE:
2957 dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
2958 dc_hpd_int_cntl |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
2959 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
2968 static int dce_v8_0_set_crtc_interrupt_state(struct amdgpu_device *adev,
2969 struct amdgpu_irq_src *src,
2971 enum amdgpu_interrupt_state state)
2974 case AMDGPU_CRTC_IRQ_VBLANK1:
2975 dce_v8_0_set_crtc_vblank_interrupt_state(adev, 0, state);
2977 case AMDGPU_CRTC_IRQ_VBLANK2:
2978 dce_v8_0_set_crtc_vblank_interrupt_state(adev, 1, state);
2980 case AMDGPU_CRTC_IRQ_VBLANK3:
2981 dce_v8_0_set_crtc_vblank_interrupt_state(adev, 2, state);
2983 case AMDGPU_CRTC_IRQ_VBLANK4:
2984 dce_v8_0_set_crtc_vblank_interrupt_state(adev, 3, state);
2986 case AMDGPU_CRTC_IRQ_VBLANK5:
2987 dce_v8_0_set_crtc_vblank_interrupt_state(adev, 4, state);
2989 case AMDGPU_CRTC_IRQ_VBLANK6:
2990 dce_v8_0_set_crtc_vblank_interrupt_state(adev, 5, state);
2992 case AMDGPU_CRTC_IRQ_VLINE1:
2993 dce_v8_0_set_crtc_vline_interrupt_state(adev, 0, state);
2995 case AMDGPU_CRTC_IRQ_VLINE2:
2996 dce_v8_0_set_crtc_vline_interrupt_state(adev, 1, state);
2998 case AMDGPU_CRTC_IRQ_VLINE3:
2999 dce_v8_0_set_crtc_vline_interrupt_state(adev, 2, state);
3001 case AMDGPU_CRTC_IRQ_VLINE4:
3002 dce_v8_0_set_crtc_vline_interrupt_state(adev, 3, state);
3004 case AMDGPU_CRTC_IRQ_VLINE5:
3005 dce_v8_0_set_crtc_vline_interrupt_state(adev, 4, state);
3007 case AMDGPU_CRTC_IRQ_VLINE6:
3008 dce_v8_0_set_crtc_vline_interrupt_state(adev, 5, state);
3016 static int dce_v8_0_crtc_irq(struct amdgpu_device *adev,
3017 struct amdgpu_irq_src *source,
3018 struct amdgpu_iv_entry *entry)
3020 unsigned crtc = entry->src_id - 1;
3021 uint32_t disp_int = RREG32(interrupt_status_offsets[crtc].reg);
3022 unsigned int irq_type = amdgpu_display_crtc_idx_to_irq_type(adev,
3025 switch (entry->src_data[0]) {
3026 case 0: /* vblank */
3027 if (disp_int & interrupt_status_offsets[crtc].vblank)
3028 WREG32(mmLB_VBLANK_STATUS + crtc_offsets[crtc], LB_VBLANK_STATUS__VBLANK_ACK_MASK);
3030 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
3032 if (amdgpu_irq_enabled(adev, source, irq_type)) {
3033 drm_handle_vblank(adev->ddev, crtc);
3035 DRM_DEBUG("IH: D%d vblank\n", crtc + 1);
3038 if (disp_int & interrupt_status_offsets[crtc].vline)
3039 WREG32(mmLB_VLINE_STATUS + crtc_offsets[crtc], LB_VLINE_STATUS__VLINE_ACK_MASK);
3041 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
3043 DRM_DEBUG("IH: D%d vline\n", crtc + 1);
3046 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]);
3053 static int dce_v8_0_set_pageflip_interrupt_state(struct amdgpu_device *adev,
3054 struct amdgpu_irq_src *src,
3056 enum amdgpu_interrupt_state state)
3060 if (type >= adev->mode_info.num_crtc) {
3061 DRM_ERROR("invalid pageflip crtc %d\n", type);
3065 reg = RREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type]);
3066 if (state == AMDGPU_IRQ_STATE_DISABLE)
3067 WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
3068 reg & ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
3070 WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
3071 reg | GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
3076 static int dce_v8_0_pageflip_irq(struct amdgpu_device *adev,
3077 struct amdgpu_irq_src *source,
3078 struct amdgpu_iv_entry *entry)
3080 unsigned long flags;
3082 struct amdgpu_crtc *amdgpu_crtc;
3083 struct amdgpu_flip_work *works;
3085 crtc_id = (entry->src_id - 8) >> 1;
3086 amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
3088 if (crtc_id >= adev->mode_info.num_crtc) {
3089 DRM_ERROR("invalid pageflip crtc %d\n", crtc_id);
3093 if (RREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id]) &
3094 GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK)
3095 WREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id],
3096 GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK);
3098 /* IRQ could occur when in initial stage */
3099 if (amdgpu_crtc == NULL)
3102 spin_lock_irqsave(&adev->ddev->event_lock, flags);
3103 works = amdgpu_crtc->pflip_works;
3104 if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){
3105 DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
3106 "AMDGPU_FLIP_SUBMITTED(%d)\n",
3107 amdgpu_crtc->pflip_status,
3108 AMDGPU_FLIP_SUBMITTED);
3109 spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
3113 /* page flip completed. clean up */
3114 amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
3115 amdgpu_crtc->pflip_works = NULL;
3117 /* wakeup usersapce */
3119 drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event);
3121 spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
3123 drm_crtc_vblank_put(&amdgpu_crtc->base);
3124 schedule_work(&works->unpin_work);
3129 static int dce_v8_0_hpd_irq(struct amdgpu_device *adev,
3130 struct amdgpu_irq_src *source,
3131 struct amdgpu_iv_entry *entry)
3133 uint32_t disp_int, mask, tmp;
3136 if (entry->src_data[0] >= adev->mode_info.num_hpd) {
3137 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data[0]);
3141 hpd = entry->src_data[0];
3142 disp_int = RREG32(interrupt_status_offsets[hpd].reg);
3143 mask = interrupt_status_offsets[hpd].hpd;
3145 if (disp_int & mask) {
3146 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
3147 tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_ACK_MASK;
3148 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
3149 schedule_work(&adev->hotplug_work);
3150 DRM_DEBUG("IH: HPD%d\n", hpd + 1);
3157 static int dce_v8_0_set_clockgating_state(void *handle,
3158 enum amd_clockgating_state state)
3163 static int dce_v8_0_set_powergating_state(void *handle,
3164 enum amd_powergating_state state)
3169 static const struct amd_ip_funcs dce_v8_0_ip_funcs = {
3171 .early_init = dce_v8_0_early_init,
3173 .sw_init = dce_v8_0_sw_init,
3174 .sw_fini = dce_v8_0_sw_fini,
3175 .hw_init = dce_v8_0_hw_init,
3176 .hw_fini = dce_v8_0_hw_fini,
3177 .suspend = dce_v8_0_suspend,
3178 .resume = dce_v8_0_resume,
3179 .is_idle = dce_v8_0_is_idle,
3180 .wait_for_idle = dce_v8_0_wait_for_idle,
3181 .soft_reset = dce_v8_0_soft_reset,
3182 .set_clockgating_state = dce_v8_0_set_clockgating_state,
3183 .set_powergating_state = dce_v8_0_set_powergating_state,
3187 dce_v8_0_encoder_mode_set(struct drm_encoder *encoder,
3188 struct drm_display_mode *mode,
3189 struct drm_display_mode *adjusted_mode)
3191 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
3193 amdgpu_encoder->pixel_clock = adjusted_mode->clock;
3195 /* need to call this here rather than in prepare() since we need some crtc info */
3196 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
3198 /* set scaler clears this on some chips */
3199 dce_v8_0_set_interleave(encoder->crtc, mode);
3201 if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
3202 dce_v8_0_afmt_enable(encoder, true);
3203 dce_v8_0_afmt_setmode(encoder, adjusted_mode);
3207 static void dce_v8_0_encoder_prepare(struct drm_encoder *encoder)
3209 struct amdgpu_device *adev = encoder->dev->dev_private;
3210 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
3211 struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
3213 if ((amdgpu_encoder->active_device &
3214 (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
3215 (amdgpu_encoder_get_dp_bridge_encoder_id(encoder) !=
3216 ENCODER_OBJECT_ID_NONE)) {
3217 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
3219 dig->dig_encoder = dce_v8_0_pick_dig_encoder(encoder);
3220 if (amdgpu_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT)
3221 dig->afmt = adev->mode_info.afmt[dig->dig_encoder];
3225 amdgpu_atombios_scratch_regs_lock(adev, true);
3228 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
3230 /* select the clock/data port if it uses a router */
3231 if (amdgpu_connector->router.cd_valid)
3232 amdgpu_i2c_router_select_cd_port(amdgpu_connector);
3234 /* turn eDP panel on for mode set */
3235 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
3236 amdgpu_atombios_encoder_set_edp_panel_power(connector,
3237 ATOM_TRANSMITTER_ACTION_POWER_ON);
3240 /* this is needed for the pll/ss setup to work correctly in some cases */
3241 amdgpu_atombios_encoder_set_crtc_source(encoder);
3242 /* set up the FMT blocks */
3243 dce_v8_0_program_fmt(encoder);
3246 static void dce_v8_0_encoder_commit(struct drm_encoder *encoder)
3248 struct drm_device *dev = encoder->dev;
3249 struct amdgpu_device *adev = dev->dev_private;
3251 /* need to call this here as we need the crtc set up */
3252 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
3253 amdgpu_atombios_scratch_regs_lock(adev, false);
3256 static void dce_v8_0_encoder_disable(struct drm_encoder *encoder)
3258 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
3259 struct amdgpu_encoder_atom_dig *dig;
3261 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
3263 if (amdgpu_atombios_encoder_is_digital(encoder)) {
3264 if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
3265 dce_v8_0_afmt_enable(encoder, false);
3266 dig = amdgpu_encoder->enc_priv;
3267 dig->dig_encoder = -1;
3269 amdgpu_encoder->active_device = 0;
3272 /* these are handled by the primary encoders */
3273 static void dce_v8_0_ext_prepare(struct drm_encoder *encoder)
3278 static void dce_v8_0_ext_commit(struct drm_encoder *encoder)
3284 dce_v8_0_ext_mode_set(struct drm_encoder *encoder,
3285 struct drm_display_mode *mode,
3286 struct drm_display_mode *adjusted_mode)
3291 static void dce_v8_0_ext_disable(struct drm_encoder *encoder)
3297 dce_v8_0_ext_dpms(struct drm_encoder *encoder, int mode)
3302 static const struct drm_encoder_helper_funcs dce_v8_0_ext_helper_funcs = {
3303 .dpms = dce_v8_0_ext_dpms,
3304 .prepare = dce_v8_0_ext_prepare,
3305 .mode_set = dce_v8_0_ext_mode_set,
3306 .commit = dce_v8_0_ext_commit,
3307 .disable = dce_v8_0_ext_disable,
3308 /* no detect for TMDS/LVDS yet */
3311 static const struct drm_encoder_helper_funcs dce_v8_0_dig_helper_funcs = {
3312 .dpms = amdgpu_atombios_encoder_dpms,
3313 .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
3314 .prepare = dce_v8_0_encoder_prepare,
3315 .mode_set = dce_v8_0_encoder_mode_set,
3316 .commit = dce_v8_0_encoder_commit,
3317 .disable = dce_v8_0_encoder_disable,
3318 .detect = amdgpu_atombios_encoder_dig_detect,
3321 static const struct drm_encoder_helper_funcs dce_v8_0_dac_helper_funcs = {
3322 .dpms = amdgpu_atombios_encoder_dpms,
3323 .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
3324 .prepare = dce_v8_0_encoder_prepare,
3325 .mode_set = dce_v8_0_encoder_mode_set,
3326 .commit = dce_v8_0_encoder_commit,
3327 .detect = amdgpu_atombios_encoder_dac_detect,
3330 static void dce_v8_0_encoder_destroy(struct drm_encoder *encoder)
3332 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
3333 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
3334 amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder);
3335 kfree(amdgpu_encoder->enc_priv);
3336 drm_encoder_cleanup(encoder);
3337 kfree(amdgpu_encoder);
3340 static const struct drm_encoder_funcs dce_v8_0_encoder_funcs = {
3341 .destroy = dce_v8_0_encoder_destroy,
3344 static void dce_v8_0_encoder_add(struct amdgpu_device *adev,
3345 uint32_t encoder_enum,
3346 uint32_t supported_device,
3349 struct drm_device *dev = adev->ddev;
3350 struct drm_encoder *encoder;
3351 struct amdgpu_encoder *amdgpu_encoder;
3353 /* see if we already added it */
3354 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3355 amdgpu_encoder = to_amdgpu_encoder(encoder);
3356 if (amdgpu_encoder->encoder_enum == encoder_enum) {
3357 amdgpu_encoder->devices |= supported_device;
3364 amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL);
3365 if (!amdgpu_encoder)
3368 encoder = &amdgpu_encoder->base;
3369 switch (adev->mode_info.num_crtc) {
3371 encoder->possible_crtcs = 0x1;
3375 encoder->possible_crtcs = 0x3;
3378 encoder->possible_crtcs = 0xf;
3381 encoder->possible_crtcs = 0x3f;
3385 amdgpu_encoder->enc_priv = NULL;
3387 amdgpu_encoder->encoder_enum = encoder_enum;
3388 amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
3389 amdgpu_encoder->devices = supported_device;
3390 amdgpu_encoder->rmx_type = RMX_OFF;
3391 amdgpu_encoder->underscan_type = UNDERSCAN_OFF;
3392 amdgpu_encoder->is_ext_encoder = false;
3393 amdgpu_encoder->caps = caps;
3395 switch (amdgpu_encoder->encoder_id) {
3396 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
3397 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
3398 drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
3399 DRM_MODE_ENCODER_DAC, NULL);
3400 drm_encoder_helper_add(encoder, &dce_v8_0_dac_helper_funcs);
3402 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
3403 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
3404 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
3405 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
3406 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
3407 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
3408 amdgpu_encoder->rmx_type = RMX_FULL;
3409 drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
3410 DRM_MODE_ENCODER_LVDS, NULL);
3411 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder);
3412 } else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
3413 drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
3414 DRM_MODE_ENCODER_DAC, NULL);
3415 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
3417 drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
3418 DRM_MODE_ENCODER_TMDS, NULL);
3419 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
3421 drm_encoder_helper_add(encoder, &dce_v8_0_dig_helper_funcs);
3423 case ENCODER_OBJECT_ID_SI170B:
3424 case ENCODER_OBJECT_ID_CH7303:
3425 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
3426 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
3427 case ENCODER_OBJECT_ID_TITFP513:
3428 case ENCODER_OBJECT_ID_VT1623:
3429 case ENCODER_OBJECT_ID_HDMI_SI1930:
3430 case ENCODER_OBJECT_ID_TRAVIS:
3431 case ENCODER_OBJECT_ID_NUTMEG:
3432 /* these are handled by the primary encoders */
3433 amdgpu_encoder->is_ext_encoder = true;
3434 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
3435 drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
3436 DRM_MODE_ENCODER_LVDS, NULL);
3437 else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
3438 drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
3439 DRM_MODE_ENCODER_DAC, NULL);
3441 drm_encoder_init(dev, encoder, &dce_v8_0_encoder_funcs,
3442 DRM_MODE_ENCODER_TMDS, NULL);
3443 drm_encoder_helper_add(encoder, &dce_v8_0_ext_helper_funcs);
3448 static const struct amdgpu_display_funcs dce_v8_0_display_funcs = {
3449 .bandwidth_update = &dce_v8_0_bandwidth_update,
3450 .vblank_get_counter = &dce_v8_0_vblank_get_counter,
3451 .backlight_set_level = &amdgpu_atombios_encoder_set_backlight_level,
3452 .backlight_get_level = &amdgpu_atombios_encoder_get_backlight_level,
3453 .hpd_sense = &dce_v8_0_hpd_sense,
3454 .hpd_set_polarity = &dce_v8_0_hpd_set_polarity,
3455 .hpd_get_gpio_reg = &dce_v8_0_hpd_get_gpio_reg,
3456 .page_flip = &dce_v8_0_page_flip,
3457 .page_flip_get_scanoutpos = &dce_v8_0_crtc_get_scanoutpos,
3458 .add_encoder = &dce_v8_0_encoder_add,
3459 .add_connector = &amdgpu_connector_add,
3462 static void dce_v8_0_set_display_funcs(struct amdgpu_device *adev)
3464 adev->mode_info.funcs = &dce_v8_0_display_funcs;
3467 static const struct amdgpu_irq_src_funcs dce_v8_0_crtc_irq_funcs = {
3468 .set = dce_v8_0_set_crtc_interrupt_state,
3469 .process = dce_v8_0_crtc_irq,
3472 static const struct amdgpu_irq_src_funcs dce_v8_0_pageflip_irq_funcs = {
3473 .set = dce_v8_0_set_pageflip_interrupt_state,
3474 .process = dce_v8_0_pageflip_irq,
3477 static const struct amdgpu_irq_src_funcs dce_v8_0_hpd_irq_funcs = {
3478 .set = dce_v8_0_set_hpd_interrupt_state,
3479 .process = dce_v8_0_hpd_irq,
3482 static void dce_v8_0_set_irq_funcs(struct amdgpu_device *adev)
3484 if (adev->mode_info.num_crtc > 0)
3485 adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_VLINE1 + adev->mode_info.num_crtc;
3487 adev->crtc_irq.num_types = 0;
3488 adev->crtc_irq.funcs = &dce_v8_0_crtc_irq_funcs;
3490 adev->pageflip_irq.num_types = adev->mode_info.num_crtc;
3491 adev->pageflip_irq.funcs = &dce_v8_0_pageflip_irq_funcs;
3493 adev->hpd_irq.num_types = adev->mode_info.num_hpd;
3494 adev->hpd_irq.funcs = &dce_v8_0_hpd_irq_funcs;
3497 const struct amdgpu_ip_block_version dce_v8_0_ip_block =
3499 .type = AMD_IP_BLOCK_TYPE_DCE,
3503 .funcs = &dce_v8_0_ip_funcs,
3506 const struct amdgpu_ip_block_version dce_v8_1_ip_block =
3508 .type = AMD_IP_BLOCK_TYPE_DCE,
3512 .funcs = &dce_v8_0_ip_funcs,
3515 const struct amdgpu_ip_block_version dce_v8_2_ip_block =
3517 .type = AMD_IP_BLOCK_TYPE_DCE,
3521 .funcs = &dce_v8_0_ip_funcs,
3524 const struct amdgpu_ip_block_version dce_v8_3_ip_block =
3526 .type = AMD_IP_BLOCK_TYPE_DCE,
3530 .funcs = &dce_v8_0_ip_funcs,
3533 const struct amdgpu_ip_block_version dce_v8_5_ip_block =
3535 .type = AMD_IP_BLOCK_TYPE_DCE,
3539 .funcs = &dce_v8_0_ip_funcs,