]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
drm/amd/amdgpu: enable GUI idle INT after enabling CGCG
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / amd / amdgpu / dce_v6_0.c
CommitLineData
e2cdf640
KW
1/*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23#include "drmP.h"
24#include "amdgpu.h"
25#include "amdgpu_pm.h"
26#include "amdgpu_i2c.h"
27#include "atom.h"
28#include "amdgpu_atombios.h"
29#include "atombios_crtc.h"
30#include "atombios_encoders.h"
31#include "amdgpu_pll.h"
32#include "amdgpu_connectors.h"
b00861b9
TSD
33
34#include "bif/bif_3_0_d.h"
35#include "bif/bif_3_0_sh_mask.h"
36#include "oss/oss_1_0_d.h"
37#include "oss/oss_1_0_sh_mask.h"
38#include "gca/gfx_6_0_d.h"
39#include "gca/gfx_6_0_sh_mask.h"
40#include "gmc/gmc_6_0_d.h"
41#include "gmc/gmc_6_0_sh_mask.h"
42#include "dce/dce_6_0_d.h"
43#include "dce/dce_6_0_sh_mask.h"
44#include "gca/gfx_7_2_enum.h"
45#include "si_enums.h"
e2cdf640
KW
46
47static void dce_v6_0_set_display_funcs(struct amdgpu_device *adev);
48static void dce_v6_0_set_irq_funcs(struct amdgpu_device *adev);
49
50static const u32 crtc_offsets[6] =
51{
52 SI_CRTC0_REGISTER_OFFSET,
53 SI_CRTC1_REGISTER_OFFSET,
54 SI_CRTC2_REGISTER_OFFSET,
55 SI_CRTC3_REGISTER_OFFSET,
56 SI_CRTC4_REGISTER_OFFSET,
57 SI_CRTC5_REGISTER_OFFSET
58};
59
34386043
AD
60static const u32 hpd_offsets[] =
61{
b00861b9
TSD
62 mmDC_HPD1_INT_STATUS - mmDC_HPD1_INT_STATUS,
63 mmDC_HPD2_INT_STATUS - mmDC_HPD1_INT_STATUS,
64 mmDC_HPD3_INT_STATUS - mmDC_HPD1_INT_STATUS,
65 mmDC_HPD4_INT_STATUS - mmDC_HPD1_INT_STATUS,
66 mmDC_HPD5_INT_STATUS - mmDC_HPD1_INT_STATUS,
67 mmDC_HPD6_INT_STATUS - mmDC_HPD1_INT_STATUS,
34386043
AD
68};
69
e2cdf640
KW
70static const uint32_t dig_offsets[] = {
71 SI_CRTC0_REGISTER_OFFSET,
72 SI_CRTC1_REGISTER_OFFSET,
73 SI_CRTC2_REGISTER_OFFSET,
74 SI_CRTC3_REGISTER_OFFSET,
75 SI_CRTC4_REGISTER_OFFSET,
76 SI_CRTC5_REGISTER_OFFSET,
77 (0x13830 - 0x7030) >> 2,
78};
79
80static const struct {
81 uint32_t reg;
82 uint32_t vblank;
83 uint32_t vline;
84 uint32_t hpd;
85
86} interrupt_status_offsets[6] = { {
b00861b9 87 .reg = mmDISP_INTERRUPT_STATUS,
e2cdf640
KW
88 .vblank = DISP_INTERRUPT_STATUS__LB_D1_VBLANK_INTERRUPT_MASK,
89 .vline = DISP_INTERRUPT_STATUS__LB_D1_VLINE_INTERRUPT_MASK,
90 .hpd = DISP_INTERRUPT_STATUS__DC_HPD1_INTERRUPT_MASK
91}, {
b00861b9 92 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE,
e2cdf640
KW
93 .vblank = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VBLANK_INTERRUPT_MASK,
94 .vline = DISP_INTERRUPT_STATUS_CONTINUE__LB_D2_VLINE_INTERRUPT_MASK,
95 .hpd = DISP_INTERRUPT_STATUS_CONTINUE__DC_HPD2_INTERRUPT_MASK
96}, {
b00861b9 97 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE2,
e2cdf640
KW
98 .vblank = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VBLANK_INTERRUPT_MASK,
99 .vline = DISP_INTERRUPT_STATUS_CONTINUE2__LB_D3_VLINE_INTERRUPT_MASK,
100 .hpd = DISP_INTERRUPT_STATUS_CONTINUE2__DC_HPD3_INTERRUPT_MASK
101}, {
b00861b9 102 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE3,
e2cdf640
KW
103 .vblank = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VBLANK_INTERRUPT_MASK,
104 .vline = DISP_INTERRUPT_STATUS_CONTINUE3__LB_D4_VLINE_INTERRUPT_MASK,
105 .hpd = DISP_INTERRUPT_STATUS_CONTINUE3__DC_HPD4_INTERRUPT_MASK
106}, {
b00861b9 107 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE4,
e2cdf640
KW
108 .vblank = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VBLANK_INTERRUPT_MASK,
109 .vline = DISP_INTERRUPT_STATUS_CONTINUE4__LB_D5_VLINE_INTERRUPT_MASK,
110 .hpd = DISP_INTERRUPT_STATUS_CONTINUE4__DC_HPD5_INTERRUPT_MASK
111}, {
b00861b9 112 .reg = mmDISP_INTERRUPT_STATUS_CONTINUE5,
e2cdf640
KW
113 .vblank = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VBLANK_INTERRUPT_MASK,
114 .vline = DISP_INTERRUPT_STATUS_CONTINUE5__LB_D6_VLINE_INTERRUPT_MASK,
115 .hpd = DISP_INTERRUPT_STATUS_CONTINUE5__DC_HPD6_INTERRUPT_MASK
116} };
117
e2cdf640
KW
118static u32 dce_v6_0_audio_endpt_rreg(struct amdgpu_device *adev,
119 u32 block_offset, u32 reg)
120{
121 DRM_INFO("xxxx: dce_v6_0_audio_endpt_rreg ----no impl!!!!\n");
122 return 0;
123}
124
125static void dce_v6_0_audio_endpt_wreg(struct amdgpu_device *adev,
126 u32 block_offset, u32 reg, u32 v)
127{
128 DRM_INFO("xxxx: dce_v6_0_audio_endpt_wreg ----no impl!!!!\n");
129}
130
131static bool dce_v6_0_is_in_vblank(struct amdgpu_device *adev, int crtc)
132{
b00861b9 133 if (RREG32(mmCRTC_STATUS + crtc_offsets[crtc]) & CRTC_STATUS__CRTC_V_BLANK_MASK)
e2cdf640
KW
134 return true;
135 else
136 return false;
137}
138
139static bool dce_v6_0_is_counter_moving(struct amdgpu_device *adev, int crtc)
140{
141 u32 pos1, pos2;
142
b00861b9
TSD
143 pos1 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
144 pos2 = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
e2cdf640
KW
145
146 if (pos1 != pos2)
147 return true;
148 else
149 return false;
150}
151
152/**
153 * dce_v6_0_wait_for_vblank - vblank wait asic callback.
154 *
155 * @crtc: crtc to wait for vblank on
156 *
157 * Wait for vblank on the requested crtc (evergreen+).
158 */
159static void dce_v6_0_vblank_wait(struct amdgpu_device *adev, int crtc)
160{
e37e4f05 161 unsigned i = 100;
e2cdf640
KW
162
163 if (crtc >= adev->mode_info.num_crtc)
164 return;
165
b00861b9 166 if (!(RREG32(mmCRTC_CONTROL + crtc_offsets[crtc]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK))
e2cdf640
KW
167 return;
168
169 /* depending on when we hit vblank, we may be close to active; if so,
170 * wait for another frame.
171 */
172 while (dce_v6_0_is_in_vblank(adev, crtc)) {
e37e4f05
TSD
173 if (i++ == 100) {
174 i = 0;
e2cdf640
KW
175 if (!dce_v6_0_is_counter_moving(adev, crtc))
176 break;
177 }
178 }
179
180 while (!dce_v6_0_is_in_vblank(adev, crtc)) {
e37e4f05
TSD
181 if (i++ == 100) {
182 i = 0;
e2cdf640
KW
183 if (!dce_v6_0_is_counter_moving(adev, crtc))
184 break;
185 }
186 }
187}
188
189static u32 dce_v6_0_vblank_get_counter(struct amdgpu_device *adev, int crtc)
190{
191 if (crtc >= adev->mode_info.num_crtc)
192 return 0;
193 else
b00861b9 194 return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
e2cdf640
KW
195}
196
197static void dce_v6_0_pageflip_interrupt_init(struct amdgpu_device *adev)
198{
199 unsigned i;
200
201 /* Enable pflip interrupts */
02124a03 202 for (i = 0; i < adev->mode_info.num_crtc; i++)
e2cdf640
KW
203 amdgpu_irq_get(adev, &adev->pageflip_irq, i);
204}
205
206static void dce_v6_0_pageflip_interrupt_fini(struct amdgpu_device *adev)
207{
208 unsigned i;
209
210 /* Disable pflip interrupts */
02124a03 211 for (i = 0; i < adev->mode_info.num_crtc; i++)
e2cdf640
KW
212 amdgpu_irq_put(adev, &adev->pageflip_irq, i);
213}
214
215/**
216 * dce_v6_0_page_flip - pageflip callback.
217 *
218 * @adev: amdgpu_device pointer
219 * @crtc_id: crtc to cleanup pageflip on
220 * @crtc_base: new address of the crtc (GPU MC address)
221 *
222 * Does the actual pageflip (evergreen+).
223 * During vblank we take the crtc lock and wait for the update_pending
224 * bit to go high, when it does, we release the lock, and allow the
225 * double buffered update to take place.
226 * Returns the current update pending status.
227 */
228static void dce_v6_0_page_flip(struct amdgpu_device *adev,
229 int crtc_id, u64 crtc_base, bool async)
230{
231 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
232
233 /* flip at hsync for async, default is vsync */
b00861b9
TSD
234 WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, async ?
235 GRPH_FLIP_CONTROL__GRPH_SURFACE_UPDATE_H_RETRACE_EN_MASK : 0);
e2cdf640 236 /* update the scanout addresses */
b00861b9 237 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
e2cdf640 238 upper_32_bits(crtc_base));
b00861b9 239 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
e2cdf640
KW
240 (u32)crtc_base);
241
242 /* post the write */
b00861b9 243 RREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset);
e2cdf640
KW
244}
245
246static int dce_v6_0_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
247 u32 *vbl, u32 *position)
248{
249 if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
250 return -EINVAL;
b00861b9
TSD
251 *vbl = RREG32(mmCRTC_V_BLANK_START_END + crtc_offsets[crtc]);
252 *position = RREG32(mmCRTC_STATUS_POSITION + crtc_offsets[crtc]);
e2cdf640
KW
253
254 return 0;
255
256}
257
258/**
259 * dce_v6_0_hpd_sense - hpd sense callback.
260 *
261 * @adev: amdgpu_device pointer
262 * @hpd: hpd (hotplug detect) pin
263 *
264 * Checks if a digital monitor is connected (evergreen+).
265 * Returns true if connected, false if not connected.
266 */
267static bool dce_v6_0_hpd_sense(struct amdgpu_device *adev,
268 enum amdgpu_hpd_id hpd)
269{
270 bool connected = false;
271
34386043
AD
272 if (hpd >= adev->mode_info.num_hpd)
273 return connected;
274
b00861b9 275 if (RREG32(mmDC_HPD1_INT_STATUS + hpd_offsets[hpd]) & DC_HPD1_INT_STATUS__DC_HPD1_SENSE_MASK)
34386043 276 connected = true;
e2cdf640
KW
277
278 return connected;
279}
280
281/**
282 * dce_v6_0_hpd_set_polarity - hpd set polarity callback.
283 *
284 * @adev: amdgpu_device pointer
285 * @hpd: hpd (hotplug detect) pin
286 *
287 * Set the polarity of the hpd pin (evergreen+).
288 */
289static void dce_v6_0_hpd_set_polarity(struct amdgpu_device *adev,
290 enum amdgpu_hpd_id hpd)
291{
292 u32 tmp;
293 bool connected = dce_v6_0_hpd_sense(adev, hpd);
294
34386043
AD
295 if (hpd >= adev->mode_info.num_hpd)
296 return;
297
b00861b9 298 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
34386043 299 if (connected)
b00861b9 300 tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
34386043 301 else
b00861b9
TSD
302 tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_POLARITY_MASK;
303 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
e2cdf640
KW
304}
305
306/**
307 * dce_v6_0_hpd_init - hpd setup callback.
308 *
309 * @adev: amdgpu_device pointer
310 *
311 * Setup the hpd pins used by the card (evergreen+).
312 * Enable the pin, set the polarity, and enable the hpd interrupts.
313 */
314static void dce_v6_0_hpd_init(struct amdgpu_device *adev)
315{
316 struct drm_device *dev = adev->ddev;
317 struct drm_connector *connector;
079ea190 318 u32 tmp;
e2cdf640
KW
319
320 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
321 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
322
34386043
AD
323 if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
324 continue;
325
b00861b9
TSD
326 tmp = RREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
327 tmp |= DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
328 WREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
2744b647
AD
329
330 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
331 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
332 /* don't try to enable hpd on eDP or LVDS avoid breaking the
333 * aux dp channel on imac and help (but not completely fix)
334 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
335 * also avoid interrupt storms during dpms.
336 */
b00861b9
TSD
337 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
338 tmp &= ~DC_HPD1_INT_CONTROL__DC_HPD1_INT_EN_MASK;
339 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], tmp);
2744b647
AD
340 continue;
341 }
342
e2cdf640
KW
343 dce_v6_0_hpd_set_polarity(adev, amdgpu_connector->hpd.hpd);
344 amdgpu_irq_get(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
345 }
346
347}
348
349/**
350 * dce_v6_0_hpd_fini - hpd tear down callback.
351 *
352 * @adev: amdgpu_device pointer
353 *
354 * Tear down the hpd pins used by the card (evergreen+).
355 * Disable the hpd interrupts.
356 */
357static void dce_v6_0_hpd_fini(struct amdgpu_device *adev)
358{
359 struct drm_device *dev = adev->ddev;
360 struct drm_connector *connector;
079ea190 361 u32 tmp;
e2cdf640
KW
362
363 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
364 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
365
34386043
AD
366 if (amdgpu_connector->hpd.hpd >= adev->mode_info.num_hpd)
367 continue;
368
b00861b9
TSD
369 tmp = RREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd]);
370 tmp &= ~DC_HPD1_CONTROL__DC_HPD1_EN_MASK;
371 WREG32(mmDC_HPD1_CONTROL + hpd_offsets[amdgpu_connector->hpd.hpd], 0);
34386043 372
e2cdf640
KW
373 amdgpu_irq_put(adev, &adev->hpd_irq, amdgpu_connector->hpd.hpd);
374 }
375}
376
377static u32 dce_v6_0_hpd_get_gpio_reg(struct amdgpu_device *adev)
378{
b00861b9 379 return mmDC_GPIO_HPD_A;
e2cdf640
KW
380}
381
382static u32 evergreen_get_vblank_counter(struct amdgpu_device* adev, int crtc)
383{
384 if (crtc >= adev->mode_info.num_crtc)
385 return 0;
386 else
b00861b9 387 return RREG32(mmCRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
e2cdf640
KW
388}
389
390static void dce_v6_0_stop_mc_access(struct amdgpu_device *adev,
391 struct amdgpu_mode_mc_save *save)
392{
393 u32 crtc_enabled, tmp, frame_count;
394 int i, j;
395
b00861b9
TSD
396 save->vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
397 save->vga_hdp_control = RREG32(mmVGA_HDP_CONTROL);
e2cdf640
KW
398
399 /* disable VGA render */
b00861b9 400 WREG32(mmVGA_RENDER_CONTROL, 0);
e2cdf640
KW
401
402 /* blank the display controllers */
403 for (i = 0; i < adev->mode_info.num_crtc; i++) {
b00861b9 404 crtc_enabled = RREG32(mmCRTC_CONTROL + crtc_offsets[i]) & CRTC_CONTROL__CRTC_MASTER_EN_MASK;
e2cdf640
KW
405 if (crtc_enabled) {
406 save->crtc_enabled[i] = true;
b00861b9 407 tmp = RREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i]);
e2cdf640 408
b00861b9 409 if (!(tmp & CRTC_BLANK_CONTROL__CRTC_BLANK_DATA_EN_MASK)) {
e2cdf640 410 dce_v6_0_vblank_wait(adev, i);
b00861b9
TSD
411 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
412 tmp |= CRTC_BLANK_CONTROL__CRTC_BLANK_DATA_EN_MASK;
413 WREG32(mmCRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
414 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
e2cdf640
KW
415 }
416 /* wait for the next frame */
417 frame_count = evergreen_get_vblank_counter(adev, i);
418 for (j = 0; j < adev->usec_timeout; j++) {
419 if (evergreen_get_vblank_counter(adev, i) != frame_count)
420 break;
421 udelay(1);
422 }
423
424 /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
b00861b9
TSD
425 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
426 tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
427 tmp &= ~CRTC_CONTROL__CRTC_MASTER_EN_MASK;
428 WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
429 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
e2cdf640
KW
430 save->crtc_enabled[i] = false;
431 /* ***** */
432 } else {
433 save->crtc_enabled[i] = false;
434 }
435 }
436}
437
438static void dce_v6_0_resume_mc_access(struct amdgpu_device *adev,
439 struct amdgpu_mode_mc_save *save)
440{
441 u32 tmp;
442 int i, j;
443
444 /* update crtc base addresses */
445 for (i = 0; i < adev->mode_info.num_crtc; i++) {
b00861b9 446 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
e2cdf640 447 upper_32_bits(adev->mc.vram_start));
b00861b9 448 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
e2cdf640 449 upper_32_bits(adev->mc.vram_start));
b00861b9 450 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
e2cdf640 451 (u32)adev->mc.vram_start);
b00861b9 452 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
e2cdf640
KW
453 (u32)adev->mc.vram_start);
454 }
455
b00861b9
TSD
456 WREG32(mmVGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(adev->mc.vram_start));
457 WREG32(mmVGA_MEMORY_BASE_ADDRESS, (u32)adev->mc.vram_start);
e2cdf640
KW
458
459 /* unlock regs and wait for update */
460 for (i = 0; i < adev->mode_info.num_crtc; i++) {
461 if (save->crtc_enabled[i]) {
b00861b9 462 tmp = RREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i]);
e2cdf640
KW
463 if ((tmp & 0x7) != 3) {
464 tmp &= ~0x7;
465 tmp |= 0x3;
b00861b9 466 WREG32(mmMASTER_UPDATE_MODE + crtc_offsets[i], tmp);
e2cdf640 467 }
b00861b9
TSD
468 tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
469 if (tmp & GRPH_UPDATE__GRPH_UPDATE_LOCK_MASK) {
470 tmp &= ~GRPH_UPDATE__GRPH_UPDATE_LOCK_MASK;
471 WREG32(mmGRPH_UPDATE + crtc_offsets[i], tmp);
e2cdf640 472 }
b00861b9 473 tmp = RREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i]);
e2cdf640
KW
474 if (tmp & 1) {
475 tmp &= ~1;
b00861b9 476 WREG32(mmMASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
e2cdf640
KW
477 }
478 for (j = 0; j < adev->usec_timeout; j++) {
b00861b9
TSD
479 tmp = RREG32(mmGRPH_UPDATE + crtc_offsets[i]);
480 if ((tmp & GRPH_UPDATE__GRPH_SURFACE_UPDATE_PENDING_MASK) == 0)
e2cdf640
KW
481 break;
482 udelay(1);
483 }
484 }
485 }
486
487 /* Unlock vga access */
b00861b9 488 WREG32(mmVGA_HDP_CONTROL, save->vga_hdp_control);
e2cdf640 489 mdelay(1);
b00861b9 490 WREG32(mmVGA_RENDER_CONTROL, save->vga_render_control);
e2cdf640
KW
491
492}
493
494static void dce_v6_0_set_vga_render_state(struct amdgpu_device *adev,
495 bool render)
496{
1d160f43 497 if (!render)
b00861b9
TSD
498 WREG32(mmVGA_RENDER_CONTROL,
499 RREG32(mmVGA_RENDER_CONTROL) & VGA_VSTATUS_CNTL);
e2cdf640
KW
500
501}
502
1d160f43
AD
503static int dce_v6_0_get_num_crtc(struct amdgpu_device *adev)
504{
505 int num_crtc = 0;
506
507 switch (adev->asic_type) {
508 case CHIP_TAHITI:
509 case CHIP_PITCAIRN:
510 case CHIP_VERDE:
511 num_crtc = 6;
512 break;
513 case CHIP_OLAND:
514 num_crtc = 2;
515 break;
516 default:
517 num_crtc = 0;
518 }
519 return num_crtc;
520}
521
522void dce_v6_0_disable_dce(struct amdgpu_device *adev)
523{
524 /*Disable VGA render and enabled crtc, if has DCE engine*/
525 if (amdgpu_atombios_has_dce_engine_info(adev)) {
526 u32 tmp;
527 int crtc_enabled, i;
528
529 dce_v6_0_set_vga_render_state(adev, false);
530
531 /*Disable crtc*/
532 for (i = 0; i < dce_v6_0_get_num_crtc(adev); i++) {
b00861b9
TSD
533 crtc_enabled = RREG32(mmCRTC_CONTROL + crtc_offsets[i]) &
534 CRTC_CONTROL__CRTC_MASTER_EN_MASK;
1d160f43 535 if (crtc_enabled) {
b00861b9
TSD
536 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 1);
537 tmp = RREG32(mmCRTC_CONTROL + crtc_offsets[i]);
538 tmp &= ~CRTC_CONTROL__CRTC_MASTER_EN_MASK;
539 WREG32(mmCRTC_CONTROL + crtc_offsets[i], tmp);
540 WREG32(mmCRTC_UPDATE_LOCK + crtc_offsets[i], 0);
1d160f43
AD
541 }
542 }
543 }
544}
545
e2cdf640
KW
546static void dce_v6_0_program_fmt(struct drm_encoder *encoder)
547{
548
549 struct drm_device *dev = encoder->dev;
550 struct amdgpu_device *adev = dev->dev_private;
551 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
552 struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
553 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(encoder->crtc);
554 int bpc = 0;
555 u32 tmp = 0;
556 enum amdgpu_connector_dither dither = AMDGPU_FMT_DITHER_DISABLE;
557
558 if (connector) {
559 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
560 bpc = amdgpu_connector_get_monitor_bpc(connector);
561 dither = amdgpu_connector->dither;
562 }
563
564 /* LVDS FMT is set up by atom */
565 if (amdgpu_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
566 return;
567
568 if (bpc == 0)
569 return;
570
571
572 switch (bpc) {
573 case 6:
574 if (dither == AMDGPU_FMT_DITHER_ENABLE)
575 /* XXX sort out optimal dither settings */
b00861b9
TSD
576 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
577 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
578 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK);
e2cdf640 579 else
b00861b9 580 tmp |= FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK;
e2cdf640
KW
581 break;
582 case 8:
583 if (dither == AMDGPU_FMT_DITHER_ENABLE)
584 /* XXX sort out optimal dither settings */
b00861b9
TSD
585 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_FRAME_RANDOM_ENABLE_MASK |
586 FMT_BIT_DEPTH_CONTROL__FMT_HIGHPASS_RANDOM_ENABLE_MASK |
587 FMT_BIT_DEPTH_CONTROL__FMT_RGB_RANDOM_ENABLE_MASK |
588 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_EN_MASK |
589 FMT_BIT_DEPTH_CONTROL__FMT_SPATIAL_DITHER_DEPTH_MASK);
e2cdf640 590 else
b00861b9
TSD
591 tmp |= (FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_EN_MASK |
592 FMT_BIT_DEPTH_CONTROL__FMT_TRUNCATE_DEPTH_MASK);
e2cdf640
KW
593 break;
594 case 10:
595 default:
596 /* not needed */
597 break;
598 }
599
b00861b9 600 WREG32(mmFMT_BIT_DEPTH_CONTROL + amdgpu_crtc->crtc_offset, tmp);
e2cdf640
KW
601}
602
603/**
604 * cik_get_number_of_dram_channels - get the number of dram channels
605 *
606 * @adev: amdgpu_device pointer
607 *
608 * Look up the number of video ram channels (CIK).
609 * Used for display watermark bandwidth calculations
610 * Returns the number of dram channels
611 */
612static u32 si_get_number_of_dram_channels(struct amdgpu_device *adev)
613{
b00861b9 614 u32 tmp = RREG32(mmMC_SHARED_CHMAP);
e2cdf640
KW
615
616 switch ((tmp & MC_SHARED_CHMAP__NOOFCHAN_MASK) >> MC_SHARED_CHMAP__NOOFCHAN__SHIFT) {
617 case 0:
618 default:
619 return 1;
620 case 1:
621 return 2;
622 case 2:
623 return 4;
624 case 3:
625 return 8;
626 case 4:
627 return 3;
628 case 5:
629 return 6;
630 case 6:
631 return 10;
632 case 7:
633 return 12;
634 case 8:
635 return 16;
636 }
637}
638
639struct dce6_wm_params {
640 u32 dram_channels; /* number of dram channels */
641 u32 yclk; /* bandwidth per dram data pin in kHz */
642 u32 sclk; /* engine clock in kHz */
643 u32 disp_clk; /* display clock in kHz */
644 u32 src_width; /* viewport width */
645 u32 active_time; /* active display time in ns */
646 u32 blank_time; /* blank time in ns */
647 bool interlaced; /* mode is interlaced */
648 fixed20_12 vsc; /* vertical scale ratio */
649 u32 num_heads; /* number of active crtcs */
650 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
651 u32 lb_size; /* line buffer allocated to pipe */
652 u32 vtaps; /* vertical scaler taps */
653};
654
655/**
656 * dce_v6_0_dram_bandwidth - get the dram bandwidth
657 *
658 * @wm: watermark calculation data
659 *
660 * Calculate the raw dram bandwidth (CIK).
661 * Used for display watermark bandwidth calculations
662 * Returns the dram bandwidth in MBytes/s
663 */
664static u32 dce_v6_0_dram_bandwidth(struct dce6_wm_params *wm)
665{
666 /* Calculate raw DRAM Bandwidth */
667 fixed20_12 dram_efficiency; /* 0.7 */
668 fixed20_12 yclk, dram_channels, bandwidth;
669 fixed20_12 a;
670
671 a.full = dfixed_const(1000);
672 yclk.full = dfixed_const(wm->yclk);
673 yclk.full = dfixed_div(yclk, a);
674 dram_channels.full = dfixed_const(wm->dram_channels * 4);
675 a.full = dfixed_const(10);
676 dram_efficiency.full = dfixed_const(7);
677 dram_efficiency.full = dfixed_div(dram_efficiency, a);
678 bandwidth.full = dfixed_mul(dram_channels, yclk);
679 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
680
681 return dfixed_trunc(bandwidth);
682}
683
684/**
685 * dce_v6_0_dram_bandwidth_for_display - get the dram bandwidth for display
686 *
687 * @wm: watermark calculation data
688 *
689 * Calculate the dram bandwidth used for display (CIK).
690 * Used for display watermark bandwidth calculations
691 * Returns the dram bandwidth for display in MBytes/s
692 */
693static u32 dce_v6_0_dram_bandwidth_for_display(struct dce6_wm_params *wm)
694{
695 /* Calculate DRAM Bandwidth and the part allocated to display. */
696 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
697 fixed20_12 yclk, dram_channels, bandwidth;
698 fixed20_12 a;
699
700 a.full = dfixed_const(1000);
701 yclk.full = dfixed_const(wm->yclk);
702 yclk.full = dfixed_div(yclk, a);
703 dram_channels.full = dfixed_const(wm->dram_channels * 4);
704 a.full = dfixed_const(10);
705 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
706 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
707 bandwidth.full = dfixed_mul(dram_channels, yclk);
708 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
709
710 return dfixed_trunc(bandwidth);
711}
712
713/**
714 * dce_v6_0_data_return_bandwidth - get the data return bandwidth
715 *
716 * @wm: watermark calculation data
717 *
718 * Calculate the data return bandwidth used for display (CIK).
719 * Used for display watermark bandwidth calculations
720 * Returns the data return bandwidth in MBytes/s
721 */
722static u32 dce_v6_0_data_return_bandwidth(struct dce6_wm_params *wm)
723{
724 /* Calculate the display Data return Bandwidth */
725 fixed20_12 return_efficiency; /* 0.8 */
726 fixed20_12 sclk, bandwidth;
727 fixed20_12 a;
728
729 a.full = dfixed_const(1000);
730 sclk.full = dfixed_const(wm->sclk);
731 sclk.full = dfixed_div(sclk, a);
732 a.full = dfixed_const(10);
733 return_efficiency.full = dfixed_const(8);
734 return_efficiency.full = dfixed_div(return_efficiency, a);
735 a.full = dfixed_const(32);
736 bandwidth.full = dfixed_mul(a, sclk);
737 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
738
739 return dfixed_trunc(bandwidth);
740}
741
742/**
743 * dce_v6_0_dmif_request_bandwidth - get the dmif bandwidth
744 *
745 * @wm: watermark calculation data
746 *
747 * Calculate the dmif bandwidth used for display (CIK).
748 * Used for display watermark bandwidth calculations
749 * Returns the dmif bandwidth in MBytes/s
750 */
751static u32 dce_v6_0_dmif_request_bandwidth(struct dce6_wm_params *wm)
752{
753 /* Calculate the DMIF Request Bandwidth */
754 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
755 fixed20_12 disp_clk, bandwidth;
756 fixed20_12 a, b;
757
758 a.full = dfixed_const(1000);
759 disp_clk.full = dfixed_const(wm->disp_clk);
760 disp_clk.full = dfixed_div(disp_clk, a);
761 a.full = dfixed_const(32);
762 b.full = dfixed_mul(a, disp_clk);
763
764 a.full = dfixed_const(10);
765 disp_clk_request_efficiency.full = dfixed_const(8);
766 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
767
768 bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
769
770 return dfixed_trunc(bandwidth);
771}
772
773/**
774 * dce_v6_0_available_bandwidth - get the min available bandwidth
775 *
776 * @wm: watermark calculation data
777 *
778 * Calculate the min available bandwidth used for display (CIK).
779 * Used for display watermark bandwidth calculations
780 * Returns the min available bandwidth in MBytes/s
781 */
782static u32 dce_v6_0_available_bandwidth(struct dce6_wm_params *wm)
783{
784 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
785 u32 dram_bandwidth = dce_v6_0_dram_bandwidth(wm);
786 u32 data_return_bandwidth = dce_v6_0_data_return_bandwidth(wm);
787 u32 dmif_req_bandwidth = dce_v6_0_dmif_request_bandwidth(wm);
788
789 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
790}
791
792/**
793 * dce_v6_0_average_bandwidth - get the average available bandwidth
794 *
795 * @wm: watermark calculation data
796 *
797 * Calculate the average available bandwidth used for display (CIK).
798 * Used for display watermark bandwidth calculations
799 * Returns the average available bandwidth in MBytes/s
800 */
801static u32 dce_v6_0_average_bandwidth(struct dce6_wm_params *wm)
802{
803 /* Calculate the display mode Average Bandwidth
804 * DisplayMode should contain the source and destination dimensions,
805 * timing, etc.
806 */
807 fixed20_12 bpp;
808 fixed20_12 line_time;
809 fixed20_12 src_width;
810 fixed20_12 bandwidth;
811 fixed20_12 a;
812
813 a.full = dfixed_const(1000);
814 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
815 line_time.full = dfixed_div(line_time, a);
816 bpp.full = dfixed_const(wm->bytes_per_pixel);
817 src_width.full = dfixed_const(wm->src_width);
818 bandwidth.full = dfixed_mul(src_width, bpp);
819 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
820 bandwidth.full = dfixed_div(bandwidth, line_time);
821
822 return dfixed_trunc(bandwidth);
823}
824
825/**
826 * dce_v6_0_latency_watermark - get the latency watermark
827 *
828 * @wm: watermark calculation data
829 *
830 * Calculate the latency watermark (CIK).
831 * Used for display watermark bandwidth calculations
832 * Returns the latency watermark in ns
833 */
834static u32 dce_v6_0_latency_watermark(struct dce6_wm_params *wm)
835{
836 /* First calculate the latency in ns */
837 u32 mc_latency = 2000; /* 2000 ns. */
838 u32 available_bandwidth = dce_v6_0_available_bandwidth(wm);
839 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
840 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
841 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
842 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
843 (wm->num_heads * cursor_line_pair_return_time);
844 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
845 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
846 u32 tmp, dmif_size = 12288;
847 fixed20_12 a, b, c;
848
849 if (wm->num_heads == 0)
850 return 0;
851
852 a.full = dfixed_const(2);
853 b.full = dfixed_const(1);
854 if ((wm->vsc.full > a.full) ||
855 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
856 (wm->vtaps >= 5) ||
857 ((wm->vsc.full >= a.full) && wm->interlaced))
858 max_src_lines_per_dst_line = 4;
859 else
860 max_src_lines_per_dst_line = 2;
861
862 a.full = dfixed_const(available_bandwidth);
863 b.full = dfixed_const(wm->num_heads);
864 a.full = dfixed_div(a, b);
865
866 b.full = dfixed_const(mc_latency + 512);
867 c.full = dfixed_const(wm->disp_clk);
868 b.full = dfixed_div(b, c);
869
870 c.full = dfixed_const(dmif_size);
871 b.full = dfixed_div(c, b);
872
873 tmp = min(dfixed_trunc(a), dfixed_trunc(b));
874
875 b.full = dfixed_const(1000);
876 c.full = dfixed_const(wm->disp_clk);
877 b.full = dfixed_div(c, b);
878 c.full = dfixed_const(wm->bytes_per_pixel);
879 b.full = dfixed_mul(b, c);
880
881 lb_fill_bw = min(tmp, dfixed_trunc(b));
882
883 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
884 b.full = dfixed_const(1000);
885 c.full = dfixed_const(lb_fill_bw);
886 b.full = dfixed_div(c, b);
887 a.full = dfixed_div(a, b);
888 line_fill_time = dfixed_trunc(a);
889
890 if (line_fill_time < wm->active_time)
891 return latency;
892 else
893 return latency + (line_fill_time - wm->active_time);
894
895}
896
897/**
898 * dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display - check
899 * average and available dram bandwidth
900 *
901 * @wm: watermark calculation data
902 *
903 * Check if the display average bandwidth fits in the display
904 * dram bandwidth (CIK).
905 * Used for display watermark bandwidth calculations
906 * Returns true if the display fits, false if not.
907 */
908static bool dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
909{
910 if (dce_v6_0_average_bandwidth(wm) <=
911 (dce_v6_0_dram_bandwidth_for_display(wm) / wm->num_heads))
912 return true;
913 else
914 return false;
915}
916
917/**
918 * dce_v6_0_average_bandwidth_vs_available_bandwidth - check
919 * average and available bandwidth
920 *
921 * @wm: watermark calculation data
922 *
923 * Check if the display average bandwidth fits in the display
924 * available bandwidth (CIK).
925 * Used for display watermark bandwidth calculations
926 * Returns true if the display fits, false if not.
927 */
928static bool dce_v6_0_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
929{
930 if (dce_v6_0_average_bandwidth(wm) <=
931 (dce_v6_0_available_bandwidth(wm) / wm->num_heads))
932 return true;
933 else
934 return false;
935}
936
937/**
938 * dce_v6_0_check_latency_hiding - check latency hiding
939 *
940 * @wm: watermark calculation data
941 *
942 * Check latency hiding (CIK).
943 * Used for display watermark bandwidth calculations
944 * Returns true if the display fits, false if not.
945 */
946static bool dce_v6_0_check_latency_hiding(struct dce6_wm_params *wm)
947{
948 u32 lb_partitions = wm->lb_size / wm->src_width;
949 u32 line_time = wm->active_time + wm->blank_time;
950 u32 latency_tolerant_lines;
951 u32 latency_hiding;
952 fixed20_12 a;
953
954 a.full = dfixed_const(1);
955 if (wm->vsc.full > a.full)
956 latency_tolerant_lines = 1;
957 else {
958 if (lb_partitions <= (wm->vtaps + 1))
959 latency_tolerant_lines = 1;
960 else
961 latency_tolerant_lines = 2;
962 }
963
964 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
965
966 if (dce_v6_0_latency_watermark(wm) <= latency_hiding)
967 return true;
968 else
969 return false;
970}
971
972/**
973 * dce_v6_0_program_watermarks - program display watermarks
974 *
975 * @adev: amdgpu_device pointer
976 * @amdgpu_crtc: the selected display controller
977 * @lb_size: line buffer size
978 * @num_heads: number of display controllers in use
979 *
980 * Calculate and program the display watermarks for the
981 * selected display controller (CIK).
982 */
983static void dce_v6_0_program_watermarks(struct amdgpu_device *adev,
984 struct amdgpu_crtc *amdgpu_crtc,
985 u32 lb_size, u32 num_heads)
986{
987 struct drm_display_mode *mode = &amdgpu_crtc->base.mode;
988 struct dce6_wm_params wm_low, wm_high;
989 u32 dram_channels;
990 u32 pixel_period;
991 u32 line_time = 0;
992 u32 latency_watermark_a = 0, latency_watermark_b = 0;
993 u32 priority_a_mark = 0, priority_b_mark = 0;
994 u32 priority_a_cnt = PRIORITY_OFF;
995 u32 priority_b_cnt = PRIORITY_OFF;
996 u32 tmp, arb_control3;
997 fixed20_12 a, b, c;
998
999 if (amdgpu_crtc->base.enabled && num_heads && mode) {
1000 pixel_period = 1000000 / (u32)mode->clock;
1001 line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
1002 priority_a_cnt = 0;
1003 priority_b_cnt = 0;
1004
1005 dram_channels = si_get_number_of_dram_channels(adev);
1006
1007 /* watermark for high clocks */
1008 if (adev->pm.dpm_enabled) {
1009 wm_high.yclk =
1010 amdgpu_dpm_get_mclk(adev, false) * 10;
1011 wm_high.sclk =
1012 amdgpu_dpm_get_sclk(adev, false) * 10;
1013 } else {
1014 wm_high.yclk = adev->pm.current_mclk * 10;
1015 wm_high.sclk = adev->pm.current_sclk * 10;
1016 }
1017
1018 wm_high.disp_clk = mode->clock;
1019 wm_high.src_width = mode->crtc_hdisplay;
1020 wm_high.active_time = mode->crtc_hdisplay * pixel_period;
1021 wm_high.blank_time = line_time - wm_high.active_time;
1022 wm_high.interlaced = false;
1023 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1024 wm_high.interlaced = true;
1025 wm_high.vsc = amdgpu_crtc->vsc;
1026 wm_high.vtaps = 1;
1027 if (amdgpu_crtc->rmx_type != RMX_OFF)
1028 wm_high.vtaps = 2;
1029 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
1030 wm_high.lb_size = lb_size;
1031 wm_high.dram_channels = dram_channels;
1032 wm_high.num_heads = num_heads;
1033
1034 if (adev->pm.dpm_enabled) {
1035 /* watermark for low clocks */
1036 wm_low.yclk =
1037 amdgpu_dpm_get_mclk(adev, true) * 10;
1038 wm_low.sclk =
1039 amdgpu_dpm_get_sclk(adev, true) * 10;
1040 } else {
1041 wm_low.yclk = adev->pm.current_mclk * 10;
1042 wm_low.sclk = adev->pm.current_sclk * 10;
1043 }
1044
1045 wm_low.disp_clk = mode->clock;
1046 wm_low.src_width = mode->crtc_hdisplay;
1047 wm_low.active_time = mode->crtc_hdisplay * pixel_period;
1048 wm_low.blank_time = line_time - wm_low.active_time;
1049 wm_low.interlaced = false;
1050 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1051 wm_low.interlaced = true;
1052 wm_low.vsc = amdgpu_crtc->vsc;
1053 wm_low.vtaps = 1;
1054 if (amdgpu_crtc->rmx_type != RMX_OFF)
1055 wm_low.vtaps = 2;
1056 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
1057 wm_low.lb_size = lb_size;
1058 wm_low.dram_channels = dram_channels;
1059 wm_low.num_heads = num_heads;
1060
1061 /* set for high clocks */
1062 latency_watermark_a = min(dce_v6_0_latency_watermark(&wm_high), (u32)65535);
1063 /* set for low clocks */
1064 latency_watermark_b = min(dce_v6_0_latency_watermark(&wm_low), (u32)65535);
1065
1066 /* possibly force display priority to high */
1067 /* should really do this at mode validation time... */
1068 if (!dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
1069 !dce_v6_0_average_bandwidth_vs_available_bandwidth(&wm_high) ||
1070 !dce_v6_0_check_latency_hiding(&wm_high) ||
1071 (adev->mode_info.disp_priority == 2)) {
1072 DRM_DEBUG_KMS("force priority to high\n");
1073 priority_a_cnt |= PRIORITY_ALWAYS_ON;
1074 priority_b_cnt |= PRIORITY_ALWAYS_ON;
1075 }
1076 if (!dce_v6_0_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
1077 !dce_v6_0_average_bandwidth_vs_available_bandwidth(&wm_low) ||
1078 !dce_v6_0_check_latency_hiding(&wm_low) ||
1079 (adev->mode_info.disp_priority == 2)) {
1080 DRM_DEBUG_KMS("force priority to high\n");
1081 priority_a_cnt |= PRIORITY_ALWAYS_ON;
1082 priority_b_cnt |= PRIORITY_ALWAYS_ON;
1083 }
1084
1085 a.full = dfixed_const(1000);
1086 b.full = dfixed_const(mode->clock);
1087 b.full = dfixed_div(b, a);
1088 c.full = dfixed_const(latency_watermark_a);
1089 c.full = dfixed_mul(c, b);
1090 c.full = dfixed_mul(c, amdgpu_crtc->hsc);
1091 c.full = dfixed_div(c, a);
1092 a.full = dfixed_const(16);
1093 c.full = dfixed_div(c, a);
1094 priority_a_mark = dfixed_trunc(c);
1095 priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
1096
1097 a.full = dfixed_const(1000);
1098 b.full = dfixed_const(mode->clock);
1099 b.full = dfixed_div(b, a);
1100 c.full = dfixed_const(latency_watermark_b);
1101 c.full = dfixed_mul(c, b);
1102 c.full = dfixed_mul(c, amdgpu_crtc->hsc);
1103 c.full = dfixed_div(c, a);
1104 a.full = dfixed_const(16);
1105 c.full = dfixed_div(c, a);
1106 priority_b_mark = dfixed_trunc(c);
1107 priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
1108 }
1109
1110 /* select wm A */
b00861b9 1111 arb_control3 = RREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset);
e2cdf640
KW
1112 tmp = arb_control3;
1113 tmp &= ~LATENCY_WATERMARK_MASK(3);
1114 tmp |= LATENCY_WATERMARK_MASK(1);
b00861b9
TSD
1115 WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, tmp);
1116 WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
1117 ((latency_watermark_a << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
1118 (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
e2cdf640 1119 /* select wm B */
b00861b9 1120 tmp = RREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset);
e2cdf640
KW
1121 tmp &= ~LATENCY_WATERMARK_MASK(3);
1122 tmp |= LATENCY_WATERMARK_MASK(2);
b00861b9
TSD
1123 WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, tmp);
1124 WREG32(mmDPG_PIPE_URGENCY_CONTROL + amdgpu_crtc->crtc_offset,
1125 ((latency_watermark_b << DPG_PIPE_URGENCY_CONTROL__URGENCY_LOW_WATERMARK__SHIFT) |
1126 (line_time << DPG_PIPE_URGENCY_CONTROL__URGENCY_HIGH_WATERMARK__SHIFT)));
e2cdf640 1127 /* restore original selection */
b00861b9 1128 WREG32(mmDPG_PIPE_ARBITRATION_CONTROL3 + amdgpu_crtc->crtc_offset, arb_control3);
e2cdf640
KW
1129
1130 /* write the priority marks */
b00861b9
TSD
1131 WREG32(mmPRIORITY_A_CNT + amdgpu_crtc->crtc_offset, priority_a_cnt);
1132 WREG32(mmPRIORITY_B_CNT + amdgpu_crtc->crtc_offset, priority_b_cnt);
e2cdf640
KW
1133
1134 /* save values for DPM */
1135 amdgpu_crtc->line_time = line_time;
1136 amdgpu_crtc->wm_high = latency_watermark_a;
1137}
1138
1139/* watermark setup */
1140static u32 dce_v6_0_line_buffer_adjust(struct amdgpu_device *adev,
1141 struct amdgpu_crtc *amdgpu_crtc,
1142 struct drm_display_mode *mode,
1143 struct drm_display_mode *other_mode)
1144{
1145 u32 tmp, buffer_alloc, i;
1146 u32 pipe_offset = amdgpu_crtc->crtc_id * 0x8;
1147 /*
1148 * Line Buffer Setup
1149 * There are 3 line buffers, each one shared by 2 display controllers.
b00861b9 1150 * mmDC_LB_MEMORY_SPLIT controls how that line buffer is shared between
e2cdf640
KW
1151 * the display controllers. The paritioning is done via one of four
1152 * preset allocations specified in bits 21:20:
1153 * 0 - half lb
1154 * 2 - whole lb, other crtc must be disabled
1155 */
1156 /* this can get tricky if we have two large displays on a paired group
1157 * of crtcs. Ideally for multiple large displays we'd assign them to
1158 * non-linked crtcs for maximum line buffer allocation.
1159 */
1160 if (amdgpu_crtc->base.enabled && mode) {
1161 if (other_mode) {
1162 tmp = 0; /* 1/2 */
1163 buffer_alloc = 1;
1164 } else {
1165 tmp = 2; /* whole */
1166 buffer_alloc = 2;
1167 }
1168 } else {
1169 tmp = 0;
1170 buffer_alloc = 0;
1171 }
1172
b00861b9 1173 WREG32(mmDC_LB_MEMORY_SPLIT + amdgpu_crtc->crtc_offset,
e2cdf640
KW
1174 DC_LB_MEMORY_CONFIG(tmp));
1175
b00861b9
TSD
1176 WREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
1177 (buffer_alloc << PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATED__SHIFT));
e2cdf640 1178 for (i = 0; i < adev->usec_timeout; i++) {
b00861b9
TSD
1179 if (RREG32(mmPIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
1180 PIPE0_DMIF_BUFFER_CONTROL__DMIF_BUFFERS_ALLOCATION_COMPLETED_MASK)
e2cdf640
KW
1181 break;
1182 udelay(1);
1183 }
1184
1185 if (amdgpu_crtc->base.enabled && mode) {
1186 switch (tmp) {
1187 case 0:
1188 default:
1189 return 4096 * 2;
1190 case 2:
1191 return 8192 * 2;
1192 }
1193 }
1194
1195 /* controller not enabled, so no lb used */
1196 return 0;
1197}
1198
1199
1200/**
1201 *
1202 * dce_v6_0_bandwidth_update - program display watermarks
1203 *
1204 * @adev: amdgpu_device pointer
1205 *
1206 * Calculate and program the display watermarks and line
1207 * buffer allocation (CIK).
1208 */
1209static void dce_v6_0_bandwidth_update(struct amdgpu_device *adev)
1210{
1211 struct drm_display_mode *mode0 = NULL;
1212 struct drm_display_mode *mode1 = NULL;
1213 u32 num_heads = 0, lb_size;
1214 int i;
1215
1216 if (!adev->mode_info.mode_config_initialized)
1217 return;
1218
1219 amdgpu_update_display_priority(adev);
1220
1221 for (i = 0; i < adev->mode_info.num_crtc; i++) {
1222 if (adev->mode_info.crtcs[i]->base.enabled)
1223 num_heads++;
1224 }
1225 for (i = 0; i < adev->mode_info.num_crtc; i += 2) {
1226 mode0 = &adev->mode_info.crtcs[i]->base.mode;
1227 mode1 = &adev->mode_info.crtcs[i+1]->base.mode;
1228 lb_size = dce_v6_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i], mode0, mode1);
1229 dce_v6_0_program_watermarks(adev, adev->mode_info.crtcs[i], lb_size, num_heads);
1230 lb_size = dce_v6_0_line_buffer_adjust(adev, adev->mode_info.crtcs[i+1], mode1, mode0);
1231 dce_v6_0_program_watermarks(adev, adev->mode_info.crtcs[i+1], lb_size, num_heads);
1232 }
1233}
1234/*
1235static void dce_v6_0_audio_get_connected_pins(struct amdgpu_device *adev)
1236{
1237 int i;
1238 u32 offset, tmp;
1239
1240 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1241 offset = adev->mode_info.audio.pin[i].offset;
1242 tmp = RREG32_AUDIO_ENDPT(offset,
1243 AZ_F0_CODEC_PIN_CONTROL_RESPONSE_CONFIGURATION_DEFAULT);
1244 if (((tmp & PORT_CONNECTIVITY_MASK) >> PORT_CONNECTIVITY_SHIFT) == 1)
1245 adev->mode_info.audio.pin[i].connected = false;
1246 else
1247 adev->mode_info.audio.pin[i].connected = true;
1248 }
1249
1250}
1251
1252static struct amdgpu_audio_pin *dce_v6_0_audio_get_pin(struct amdgpu_device *adev)
1253{
1254 int i;
1255
1256 dce_v6_0_audio_get_connected_pins(adev);
1257
1258 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1259 if (adev->mode_info.audio.pin[i].connected)
1260 return &adev->mode_info.audio.pin[i];
1261 }
1262 DRM_ERROR("No connected audio pins found!\n");
1263 return NULL;
1264}
1265
1266static void dce_v6_0_afmt_audio_select_pin(struct drm_encoder *encoder)
1267{
1268 struct amdgpu_device *adev = encoder->dev->dev_private;
1269 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1270 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1271 u32 offset;
1272
1273 if (!dig || !dig->afmt || !dig->afmt->pin)
1274 return;
1275
1276 offset = dig->afmt->offset;
1277
1278 WREG32(AFMT_AUDIO_SRC_CONTROL + offset,
1279 AFMT_AUDIO_SRC_SELECT(dig->afmt->pin->id));
1280
1281}
1282
1283static void dce_v6_0_audio_write_latency_fields(struct drm_encoder *encoder,
1284 struct drm_display_mode *mode)
1285{
1286 DRM_INFO("xxxx: dce_v6_0_audio_write_latency_fields---no imp!!!!!\n");
1287}
1288
1289static void dce_v6_0_audio_write_speaker_allocation(struct drm_encoder *encoder)
1290{
1291 DRM_INFO("xxxx: dce_v6_0_audio_write_speaker_allocation---no imp!!!!!\n");
1292}
1293
1294static void dce_v6_0_audio_write_sad_regs(struct drm_encoder *encoder)
1295{
1296 DRM_INFO("xxxx: dce_v6_0_audio_write_sad_regs---no imp!!!!!\n");
1297
1298}
1299*/
1300static void dce_v6_0_audio_enable(struct amdgpu_device *adev,
1301 struct amdgpu_audio_pin *pin,
1302 bool enable)
1303{
1304 DRM_INFO("xxxx: dce_v6_0_audio_enable---no imp!!!!!\n");
1305}
1306
1307static const u32 pin_offsets[7] =
1308{
1309 (0x1780 - 0x1780),
1310 (0x1786 - 0x1780),
1311 (0x178c - 0x1780),
1312 (0x1792 - 0x1780),
1313 (0x1798 - 0x1780),
1314 (0x179d - 0x1780),
1315 (0x17a4 - 0x1780),
1316};
1317
1318static int dce_v6_0_audio_init(struct amdgpu_device *adev)
1319{
1320 return 0;
1321}
1322
1323static void dce_v6_0_audio_fini(struct amdgpu_device *adev)
1324{
1325
1326}
1327
1328/*
1329static void dce_v6_0_afmt_update_ACR(struct drm_encoder *encoder, uint32_t clock)
1330{
1331 DRM_INFO("xxxx: dce_v6_0_afmt_update_ACR---no imp!!!!!\n");
1332}
1333*/
1334/*
1335 * build a HDMI Video Info Frame
1336 */
1337/*
1338static void dce_v6_0_afmt_update_avi_infoframe(struct drm_encoder *encoder,
1339 void *buffer, size_t size)
1340{
1341 DRM_INFO("xxxx: dce_v6_0_afmt_update_avi_infoframe---no imp!!!!!\n");
1342}
1343
1344static void dce_v6_0_audio_set_dto(struct drm_encoder *encoder, u32 clock)
1345{
1346 DRM_INFO("xxxx: dce_v6_0_audio_set_dto---no imp!!!!!\n");
1347}
1348*/
1349/*
1350 * update the info frames with the data from the current display mode
1351 */
1352static void dce_v6_0_afmt_setmode(struct drm_encoder *encoder,
1353 struct drm_display_mode *mode)
1354{
1355 DRM_INFO("xxxx: dce_v6_0_afmt_setmode ----no impl !!!!!!!!\n");
1356}
1357
1358static void dce_v6_0_afmt_enable(struct drm_encoder *encoder, bool enable)
1359{
1360 struct drm_device *dev = encoder->dev;
1361 struct amdgpu_device *adev = dev->dev_private;
1362 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1363 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1364
1365 if (!dig || !dig->afmt)
1366 return;
1367
1368 /* Silent, r600_hdmi_enable will raise WARN for us */
1369 if (enable && dig->afmt->enabled)
1370 return;
1371 if (!enable && !dig->afmt->enabled)
1372 return;
1373
1374 if (!enable && dig->afmt->pin) {
1375 dce_v6_0_audio_enable(adev, dig->afmt->pin, false);
1376 dig->afmt->pin = NULL;
1377 }
1378
1379 dig->afmt->enabled = enable;
1380
1381 DRM_DEBUG("%sabling AFMT interface @ 0x%04X for encoder 0x%x\n",
1382 enable ? "En" : "Dis", dig->afmt->offset, amdgpu_encoder->encoder_id);
1383}
1384
beb86f29 1385static int dce_v6_0_afmt_init(struct amdgpu_device *adev)
e2cdf640 1386{
beb86f29 1387 int i, j;
e2cdf640
KW
1388
1389 for (i = 0; i < adev->mode_info.num_dig; i++)
1390 adev->mode_info.afmt[i] = NULL;
1391
beb86f29 1392 /* DCE6 has audio blocks tied to DIG encoders */
e2cdf640
KW
1393 for (i = 0; i < adev->mode_info.num_dig; i++) {
1394 adev->mode_info.afmt[i] = kzalloc(sizeof(struct amdgpu_afmt), GFP_KERNEL);
1395 if (adev->mode_info.afmt[i]) {
1396 adev->mode_info.afmt[i]->offset = dig_offsets[i];
1397 adev->mode_info.afmt[i]->id = i;
beb86f29
TSD
1398 } else {
1399 for (j = 0; j < i; j++) {
1400 kfree(adev->mode_info.afmt[j]);
1401 adev->mode_info.afmt[j] = NULL;
1402 }
1403 DRM_ERROR("Out of memory allocating afmt table\n");
1404 return -ENOMEM;
e2cdf640
KW
1405 }
1406 }
beb86f29 1407 return 0;
e2cdf640
KW
1408}
1409
1410static void dce_v6_0_afmt_fini(struct amdgpu_device *adev)
1411{
1412 int i;
1413
1414 for (i = 0; i < adev->mode_info.num_dig; i++) {
1415 kfree(adev->mode_info.afmt[i]);
1416 adev->mode_info.afmt[i] = NULL;
1417 }
1418}
1419
1420static const u32 vga_control_regs[6] =
1421{
b00861b9
TSD
1422 mmD1VGA_CONTROL,
1423 mmD2VGA_CONTROL,
1424 mmD3VGA_CONTROL,
1425 mmD4VGA_CONTROL,
1426 mmD5VGA_CONTROL,
1427 mmD6VGA_CONTROL,
e2cdf640
KW
1428};
1429
1430static void dce_v6_0_vga_enable(struct drm_crtc *crtc, bool enable)
1431{
1432 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1433 struct drm_device *dev = crtc->dev;
1434 struct amdgpu_device *adev = dev->dev_private;
1435 u32 vga_control;
1436
1437 vga_control = RREG32(vga_control_regs[amdgpu_crtc->crtc_id]) & ~1;
3d5f4d47 1438 WREG32(vga_control_regs[amdgpu_crtc->crtc_id], vga_control | (enable ? 1 : 0));
e2cdf640
KW
1439}
1440
1441static void dce_v6_0_grph_enable(struct drm_crtc *crtc, bool enable)
1442{
1443 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1444 struct drm_device *dev = crtc->dev;
1445 struct amdgpu_device *adev = dev->dev_private;
1446
b00861b9 1447 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, enable ? 1 : 0);
e2cdf640
KW
1448}
1449
1450static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,
1451 struct drm_framebuffer *fb,
1452 int x, int y, int atomic)
1453{
1454 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1455 struct drm_device *dev = crtc->dev;
1456 struct amdgpu_device *adev = dev->dev_private;
1457 struct amdgpu_framebuffer *amdgpu_fb;
1458 struct drm_framebuffer *target_fb;
1459 struct drm_gem_object *obj;
765e7fbf 1460 struct amdgpu_bo *abo;
e2cdf640
KW
1461 uint64_t fb_location, tiling_flags;
1462 uint32_t fb_format, fb_pitch_pixels, pipe_config;
b00861b9 1463 u32 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_NONE);
e2cdf640
KW
1464 u32 viewport_w, viewport_h;
1465 int r;
1466 bool bypass_lut = false;
b3c11ac2 1467 struct drm_format_name_buf format_name;
e2cdf640
KW
1468
1469 /* no fb bound */
1470 if (!atomic && !crtc->primary->fb) {
1471 DRM_DEBUG_KMS("No FB bound\n");
1472 return 0;
1473 }
1474
1475 if (atomic) {
1476 amdgpu_fb = to_amdgpu_framebuffer(fb);
1477 target_fb = fb;
3d5f4d47 1478 } else {
e2cdf640
KW
1479 amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
1480 target_fb = crtc->primary->fb;
1481 }
1482
1483 /* If atomic, assume fb object is pinned & idle & fenced and
1484 * just update base pointers
1485 */
1486 obj = amdgpu_fb->obj;
765e7fbf
CK
1487 abo = gem_to_amdgpu_bo(obj);
1488 r = amdgpu_bo_reserve(abo, false);
e2cdf640
KW
1489 if (unlikely(r != 0))
1490 return r;
1491
3d5f4d47 1492 if (atomic) {
765e7fbf 1493 fb_location = amdgpu_bo_gpu_offset(abo);
3d5f4d47 1494 } else {
765e7fbf 1495 r = amdgpu_bo_pin(abo, AMDGPU_GEM_DOMAIN_VRAM, &fb_location);
e2cdf640 1496 if (unlikely(r != 0)) {
765e7fbf 1497 amdgpu_bo_unreserve(abo);
e2cdf640
KW
1498 return -EINVAL;
1499 }
1500 }
1501
765e7fbf
CK
1502 amdgpu_bo_get_tiling_flags(abo, &tiling_flags);
1503 amdgpu_bo_unreserve(abo);
e2cdf640
KW
1504
1505 switch (target_fb->pixel_format) {
1506 case DRM_FORMAT_C8:
b00861b9
TSD
1507 fb_format = (GRPH_DEPTH(GRPH_DEPTH_8BPP) |
1508 GRPH_FORMAT(GRPH_FORMAT_INDEXED));
e2cdf640
KW
1509 break;
1510 case DRM_FORMAT_XRGB4444:
1511 case DRM_FORMAT_ARGB4444:
b00861b9
TSD
1512 fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
1513 GRPH_FORMAT(GRPH_FORMAT_ARGB4444));
e2cdf640 1514#ifdef __BIG_ENDIAN
b00861b9 1515 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
e2cdf640
KW
1516#endif
1517 break;
1518 case DRM_FORMAT_XRGB1555:
1519 case DRM_FORMAT_ARGB1555:
b00861b9
TSD
1520 fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
1521 GRPH_FORMAT(GRPH_FORMAT_ARGB1555));
e2cdf640 1522#ifdef __BIG_ENDIAN
b00861b9 1523 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
e2cdf640
KW
1524#endif
1525 break;
1526 case DRM_FORMAT_BGRX5551:
1527 case DRM_FORMAT_BGRA5551:
b00861b9
TSD
1528 fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
1529 GRPH_FORMAT(GRPH_FORMAT_BGRA5551));
e2cdf640 1530#ifdef __BIG_ENDIAN
b00861b9 1531 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
e2cdf640
KW
1532#endif
1533 break;
1534 case DRM_FORMAT_RGB565:
b00861b9
TSD
1535 fb_format = (GRPH_DEPTH(GRPH_DEPTH_16BPP) |
1536 GRPH_FORMAT(GRPH_FORMAT_ARGB565));
e2cdf640 1537#ifdef __BIG_ENDIAN
b00861b9 1538 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN16);
e2cdf640
KW
1539#endif
1540 break;
1541 case DRM_FORMAT_XRGB8888:
1542 case DRM_FORMAT_ARGB8888:
b00861b9
TSD
1543 fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
1544 GRPH_FORMAT(GRPH_FORMAT_ARGB8888));
e2cdf640 1545#ifdef __BIG_ENDIAN
b00861b9 1546 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
e2cdf640
KW
1547#endif
1548 break;
1549 case DRM_FORMAT_XRGB2101010:
1550 case DRM_FORMAT_ARGB2101010:
b00861b9
TSD
1551 fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
1552 GRPH_FORMAT(GRPH_FORMAT_ARGB2101010));
e2cdf640 1553#ifdef __BIG_ENDIAN
b00861b9 1554 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
e2cdf640
KW
1555#endif
1556 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
1557 bypass_lut = true;
1558 break;
1559 case DRM_FORMAT_BGRX1010102:
1560 case DRM_FORMAT_BGRA1010102:
b00861b9
TSD
1561 fb_format = (GRPH_DEPTH(GRPH_DEPTH_32BPP) |
1562 GRPH_FORMAT(GRPH_FORMAT_BGRA1010102));
e2cdf640 1563#ifdef __BIG_ENDIAN
b00861b9 1564 fb_swap = GRPH_ENDIAN_SWAP(GRPH_ENDIAN_8IN32);
e2cdf640
KW
1565#endif
1566 /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */
1567 bypass_lut = true;
1568 break;
1569 default:
1570 DRM_ERROR("Unsupported screen format %s\n",
b3c11ac2 1571 drm_get_format_name(target_fb->pixel_format, &format_name));
e2cdf640
KW
1572 return -EINVAL;
1573 }
1574
1575 if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
1576 unsigned bankw, bankh, mtaspect, tile_split, num_banks;
1577
1578 bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
1579 bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
1580 mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
1581 tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
1582 num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
1583
b00861b9
TSD
1584 fb_format |= GRPH_NUM_BANKS(num_banks);
1585 fb_format |= GRPH_ARRAY_MODE(GRPH_ARRAY_2D_TILED_THIN1);
1586 fb_format |= GRPH_TILE_SPLIT(tile_split);
1587 fb_format |= GRPH_BANK_WIDTH(bankw);
1588 fb_format |= GRPH_BANK_HEIGHT(bankh);
1589 fb_format |= GRPH_MACRO_TILE_ASPECT(mtaspect);
3d5f4d47 1590 } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
b00861b9 1591 fb_format |= GRPH_ARRAY_MODE(GRPH_ARRAY_1D_TILED_THIN1);
3d5f4d47 1592 }
e2cdf640
KW
1593
1594 pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
b00861b9 1595 fb_format |= GRPH_PIPE_CONFIG(pipe_config);
e2cdf640
KW
1596
1597 dce_v6_0_vga_enable(crtc, false);
1598
1599 /* Make sure surface address is updated at vertical blank rather than
1600 * horizontal blank
1601 */
b00861b9 1602 WREG32(mmGRPH_FLIP_CONTROL + amdgpu_crtc->crtc_offset, 0);
e2cdf640 1603
b00861b9 1604 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
e2cdf640 1605 upper_32_bits(fb_location));
b00861b9 1606 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
e2cdf640 1607 upper_32_bits(fb_location));
b00861b9
TSD
1608 WREG32(mmGRPH_PRIMARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
1609 (u32)fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
1610 WREG32(mmGRPH_SECONDARY_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
1611 (u32) fb_location & GRPH_PRIMARY_SURFACE_ADDRESS__GRPH_PRIMARY_SURFACE_ADDRESS_MASK);
1612 WREG32(mmGRPH_CONTROL + amdgpu_crtc->crtc_offset, fb_format);
1613 WREG32(mmGRPH_SWAP_CNTL + amdgpu_crtc->crtc_offset, fb_swap);
e2cdf640
KW
1614
1615 /*
1616 * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT
1617 * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to
1618 * retain the full precision throughout the pipeline.
1619 */
b00861b9
TSD
1620 WREG32_P(mmGRPH_LUT_10BIT_BYPASS + amdgpu_crtc->crtc_offset,
1621 (bypass_lut ? GRPH_LUT_10BIT_BYPASS__GRPH_LUT_10BIT_BYPASS_EN_MASK : 0),
1622 ~GRPH_LUT_10BIT_BYPASS__GRPH_LUT_10BIT_BYPASS_EN_MASK);
e2cdf640
KW
1623
1624 if (bypass_lut)
1625 DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n");
1626
b00861b9
TSD
1627 WREG32(mmGRPH_SURFACE_OFFSET_X + amdgpu_crtc->crtc_offset, 0);
1628 WREG32(mmGRPH_SURFACE_OFFSET_Y + amdgpu_crtc->crtc_offset, 0);
1629 WREG32(mmGRPH_X_START + amdgpu_crtc->crtc_offset, 0);
1630 WREG32(mmGRPH_Y_START + amdgpu_crtc->crtc_offset, 0);
1631 WREG32(mmGRPH_X_END + amdgpu_crtc->crtc_offset, target_fb->width);
1632 WREG32(mmGRPH_Y_END + amdgpu_crtc->crtc_offset, target_fb->height);
e2cdf640
KW
1633
1634 fb_pitch_pixels = target_fb->pitches[0] / (target_fb->bits_per_pixel / 8);
b00861b9 1635 WREG32(mmGRPH_PITCH + amdgpu_crtc->crtc_offset, fb_pitch_pixels);
e2cdf640
KW
1636
1637 dce_v6_0_grph_enable(crtc, true);
1638
b00861b9 1639 WREG32(mmDESKTOP_HEIGHT + amdgpu_crtc->crtc_offset,
e2cdf640
KW
1640 target_fb->height);
1641 x &= ~3;
1642 y &= ~1;
b00861b9 1643 WREG32(mmVIEWPORT_START + amdgpu_crtc->crtc_offset,
e2cdf640
KW
1644 (x << 16) | y);
1645 viewport_w = crtc->mode.hdisplay;
1646 viewport_h = (crtc->mode.vdisplay + 1) & ~1;
1647
b00861b9 1648 WREG32(mmVIEWPORT_SIZE + amdgpu_crtc->crtc_offset,
e2cdf640
KW
1649 (viewport_w << 16) | viewport_h);
1650
1651 /* set pageflip to happen anywhere in vblank interval */
b00861b9 1652 WREG32(mmMASTER_UPDATE_MODE + amdgpu_crtc->crtc_offset, 0);
e2cdf640
KW
1653
1654 if (!atomic && fb && fb != crtc->primary->fb) {
1655 amdgpu_fb = to_amdgpu_framebuffer(fb);
765e7fbf
CK
1656 abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
1657 r = amdgpu_bo_reserve(abo, false);
e2cdf640
KW
1658 if (unlikely(r != 0))
1659 return r;
765e7fbf
CK
1660 amdgpu_bo_unpin(abo);
1661 amdgpu_bo_unreserve(abo);
e2cdf640
KW
1662 }
1663
1664 /* Bytes per pixel may have changed */
1665 dce_v6_0_bandwidth_update(adev);
1666
1667 return 0;
1668
1669}
1670
1671static void dce_v6_0_set_interleave(struct drm_crtc *crtc,
1672 struct drm_display_mode *mode)
1673{
1674 struct drm_device *dev = crtc->dev;
1675 struct amdgpu_device *adev = dev->dev_private;
1676 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1677
1678 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
b00861b9
TSD
1679 WREG32(mmDATA_FORMAT + amdgpu_crtc->crtc_offset,
1680 INTERLEAVE_EN);
e2cdf640 1681 else
b00861b9 1682 WREG32(mmDATA_FORMAT + amdgpu_crtc->crtc_offset, 0);
e2cdf640
KW
1683}
1684
1685static void dce_v6_0_crtc_load_lut(struct drm_crtc *crtc)
1686{
1687
1688 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1689 struct drm_device *dev = crtc->dev;
1690 struct amdgpu_device *adev = dev->dev_private;
1691 int i;
1692
1693 DRM_DEBUG_KMS("%d\n", amdgpu_crtc->crtc_id);
1694
b00861b9
TSD
1695 WREG32(mmINPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
1696 ((0 << INPUT_CSC_CONTROL__INPUT_CSC_GRPH_MODE__SHIFT) |
1697 (0 << INPUT_CSC_CONTROL__INPUT_CSC_OVL_MODE__SHIFT)));
1698 WREG32(mmPRESCALE_GRPH_CONTROL + amdgpu_crtc->crtc_offset,
1699 PRESCALE_GRPH_CONTROL__GRPH_PRESCALE_BYPASS_MASK);
1700 WREG32(mmPRESCALE_OVL_CONTROL + amdgpu_crtc->crtc_offset,
1701 PRESCALE_OVL_CONTROL__OVL_PRESCALE_BYPASS_MASK);
1702 WREG32(mmINPUT_GAMMA_CONTROL + amdgpu_crtc->crtc_offset,
1703 ((0 << INPUT_GAMMA_CONTROL__GRPH_INPUT_GAMMA_MODE__SHIFT) |
1704 (0 << INPUT_GAMMA_CONTROL__OVL_INPUT_GAMMA_MODE__SHIFT)));
e2cdf640 1705
b00861b9 1706 WREG32(mmDC_LUT_CONTROL + amdgpu_crtc->crtc_offset, 0);
e2cdf640 1707
b00861b9
TSD
1708 WREG32(mmDC_LUT_BLACK_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0);
1709 WREG32(mmDC_LUT_BLACK_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0);
1710 WREG32(mmDC_LUT_BLACK_OFFSET_RED + amdgpu_crtc->crtc_offset, 0);
e2cdf640 1711
b00861b9
TSD
1712 WREG32(mmDC_LUT_WHITE_OFFSET_BLUE + amdgpu_crtc->crtc_offset, 0xffff);
1713 WREG32(mmDC_LUT_WHITE_OFFSET_GREEN + amdgpu_crtc->crtc_offset, 0xffff);
1714 WREG32(mmDC_LUT_WHITE_OFFSET_RED + amdgpu_crtc->crtc_offset, 0xffff);
e2cdf640 1715
b00861b9
TSD
1716 WREG32(mmDC_LUT_RW_MODE + amdgpu_crtc->crtc_offset, 0);
1717 WREG32(mmDC_LUT_WRITE_EN_MASK + amdgpu_crtc->crtc_offset, 0x00000007);
e2cdf640 1718
b00861b9 1719 WREG32(mmDC_LUT_RW_INDEX + amdgpu_crtc->crtc_offset, 0);
e2cdf640 1720 for (i = 0; i < 256; i++) {
b00861b9 1721 WREG32(mmDC_LUT_30_COLOR + amdgpu_crtc->crtc_offset,
e2cdf640
KW
1722 (amdgpu_crtc->lut_r[i] << 20) |
1723 (amdgpu_crtc->lut_g[i] << 10) |
1724 (amdgpu_crtc->lut_b[i] << 0));
1725 }
1726
b00861b9
TSD
1727 WREG32(mmDEGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
1728 ((0 << DEGAMMA_CONTROL__GRPH_DEGAMMA_MODE__SHIFT) |
1729 (0 << DEGAMMA_CONTROL__OVL_DEGAMMA_MODE__SHIFT) |
1730 ICON_DEGAMMA_MODE(0) |
1731 (0 << DEGAMMA_CONTROL__CURSOR_DEGAMMA_MODE__SHIFT)));
1732 WREG32(mmGAMUT_REMAP_CONTROL + amdgpu_crtc->crtc_offset,
1733 ((0 << GAMUT_REMAP_CONTROL__GRPH_GAMUT_REMAP_MODE__SHIFT) |
1734 (0 << GAMUT_REMAP_CONTROL__OVL_GAMUT_REMAP_MODE__SHIFT)));
1735 WREG32(mmREGAMMA_CONTROL + amdgpu_crtc->crtc_offset,
1736 ((0 << REGAMMA_CONTROL__GRPH_REGAMMA_MODE__SHIFT) |
1737 (0 << REGAMMA_CONTROL__OVL_REGAMMA_MODE__SHIFT)));
1738 WREG32(mmOUTPUT_CSC_CONTROL + amdgpu_crtc->crtc_offset,
1739 ((0 << OUTPUT_CSC_CONTROL__OUTPUT_CSC_GRPH_MODE__SHIFT) |
1740 (0 << OUTPUT_CSC_CONTROL__OUTPUT_CSC_OVL_MODE__SHIFT)));
e2cdf640
KW
1741 /* XXX match this to the depth of the crtc fmt block, move to modeset? */
1742 WREG32(0x1a50 + amdgpu_crtc->crtc_offset, 0);
1743
1744
1745}
1746
1747static int dce_v6_0_pick_dig_encoder(struct drm_encoder *encoder)
1748{
1749 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
1750 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
1751
1752 switch (amdgpu_encoder->encoder_id) {
1753 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
3d5f4d47 1754 return dig->linkb ? 1 : 0;
e2cdf640 1755 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
3d5f4d47 1756 return dig->linkb ? 3 : 2;
e2cdf640 1757 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
3d5f4d47 1758 return dig->linkb ? 5 : 4;
e2cdf640
KW
1759 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
1760 return 6;
e2cdf640
KW
1761 default:
1762 DRM_ERROR("invalid encoder_id: 0x%x\n", amdgpu_encoder->encoder_id);
1763 return 0;
1764 }
1765}
1766
1767/**
1768 * dce_v6_0_pick_pll - Allocate a PPLL for use by the crtc.
1769 *
1770 * @crtc: drm crtc
1771 *
1772 * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors
1773 * a single PPLL can be used for all DP crtcs/encoders. For non-DP
1774 * monitors a dedicated PPLL must be used. If a particular board has
1775 * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming
1776 * as there is no need to program the PLL itself. If we are not able to
1777 * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to
1778 * avoid messing up an existing monitor.
1779 *
1780 *
1781 */
1782static u32 dce_v6_0_pick_pll(struct drm_crtc *crtc)
1783{
1784 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1785 struct drm_device *dev = crtc->dev;
1786 struct amdgpu_device *adev = dev->dev_private;
1787 u32 pll_in_use;
1788 int pll;
1789
1790 if (ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder))) {
1791 if (adev->clock.dp_extclk)
1792 /* skip PPLL programming if using ext clock */
1793 return ATOM_PPLL_INVALID;
1794 else
1795 return ATOM_PPLL0;
1796 } else {
1797 /* use the same PPLL for all monitors with the same clock */
1798 pll = amdgpu_pll_get_shared_nondp_ppll(crtc);
1799 if (pll != ATOM_PPLL_INVALID)
1800 return pll;
1801 }
1802
1803 /* PPLL1, and PPLL2 */
1804 pll_in_use = amdgpu_pll_get_use_mask(crtc);
1805 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1806 return ATOM_PPLL2;
1807 if (!(pll_in_use & (1 << ATOM_PPLL1)))
1808 return ATOM_PPLL1;
1809 DRM_ERROR("unable to allocate a PPLL\n");
1810 return ATOM_PPLL_INVALID;
1811}
1812
1813static void dce_v6_0_lock_cursor(struct drm_crtc *crtc, bool lock)
1814{
1815 struct amdgpu_device *adev = crtc->dev->dev_private;
1816 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1817 uint32_t cur_lock;
1818
b00861b9 1819 cur_lock = RREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset);
e2cdf640 1820 if (lock)
b00861b9 1821 cur_lock |= CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
e2cdf640 1822 else
b00861b9
TSD
1823 cur_lock &= ~CUR_UPDATE__CURSOR_UPDATE_LOCK_MASK;
1824 WREG32(mmCUR_UPDATE + amdgpu_crtc->crtc_offset, cur_lock);
e2cdf640
KW
1825}
1826
1827static void dce_v6_0_hide_cursor(struct drm_crtc *crtc)
1828{
1829 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1830 struct amdgpu_device *adev = crtc->dev->dev_private;
1831
b00861b9
TSD
1832 WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
1833 (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
1834 (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
e2cdf640
KW
1835
1836
1837}
1838
1839static void dce_v6_0_show_cursor(struct drm_crtc *crtc)
1840{
1841 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1842 struct amdgpu_device *adev = crtc->dev->dev_private;
1843
b00861b9 1844 WREG32(mmCUR_SURFACE_ADDRESS_HIGH + amdgpu_crtc->crtc_offset,
e2cdf640 1845 upper_32_bits(amdgpu_crtc->cursor_addr));
b00861b9 1846 WREG32(mmCUR_SURFACE_ADDRESS + amdgpu_crtc->crtc_offset,
e2cdf640
KW
1847 lower_32_bits(amdgpu_crtc->cursor_addr));
1848
b00861b9
TSD
1849 WREG32_IDX(mmCUR_CONTROL + amdgpu_crtc->crtc_offset,
1850 CUR_CONTROL__CURSOR_EN_MASK |
1851 (CURSOR_24_8_PRE_MULT << CUR_CONTROL__CURSOR_MODE__SHIFT) |
1852 (CURSOR_URGENT_1_2 << CUR_CONTROL__CURSOR_URGENT_CONTROL__SHIFT));
e2cdf640
KW
1853
1854}
1855
1856static int dce_v6_0_cursor_move_locked(struct drm_crtc *crtc,
1857 int x, int y)
1858{
1859 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1860 struct amdgpu_device *adev = crtc->dev->dev_private;
1861 int xorigin = 0, yorigin = 0;
1862
1863 int w = amdgpu_crtc->cursor_width;
1864
1865 /* avivo cursor are offset into the total surface */
1866 x += crtc->x;
1867 y += crtc->y;
1868 DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
1869
1870 if (x < 0) {
1871 xorigin = min(-x, amdgpu_crtc->max_cursor_width - 1);
1872 x = 0;
1873 }
1874 if (y < 0) {
1875 yorigin = min(-y, amdgpu_crtc->max_cursor_height - 1);
1876 y = 0;
1877 }
1878
b00861b9
TSD
1879 WREG32(mmCUR_POSITION + amdgpu_crtc->crtc_offset, (x << 16) | y);
1880 WREG32(mmCUR_HOT_SPOT + amdgpu_crtc->crtc_offset, (xorigin << 16) | yorigin);
1881 WREG32(mmCUR_SIZE + amdgpu_crtc->crtc_offset,
e2cdf640
KW
1882 ((w - 1) << 16) | (amdgpu_crtc->cursor_height - 1));
1883
1884 amdgpu_crtc->cursor_x = x;
1885 amdgpu_crtc->cursor_y = y;
1886 return 0;
1887}
1888
1889static int dce_v6_0_crtc_cursor_move(struct drm_crtc *crtc,
1890 int x, int y)
1891{
1892 int ret;
1893
1894 dce_v6_0_lock_cursor(crtc, true);
1895 ret = dce_v6_0_cursor_move_locked(crtc, x, y);
1896 dce_v6_0_lock_cursor(crtc, false);
1897
1898 return ret;
1899}
1900
1901static int dce_v6_0_crtc_cursor_set2(struct drm_crtc *crtc,
1902 struct drm_file *file_priv,
1903 uint32_t handle,
1904 uint32_t width,
1905 uint32_t height,
1906 int32_t hot_x,
1907 int32_t hot_y)
1908{
1909 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1910 struct drm_gem_object *obj;
1911 struct amdgpu_bo *aobj;
1912 int ret;
1913
1914 if (!handle) {
1915 /* turn off cursor */
1916 dce_v6_0_hide_cursor(crtc);
1917 obj = NULL;
1918 goto unpin;
1919 }
1920
1921 if ((width > amdgpu_crtc->max_cursor_width) ||
1922 (height > amdgpu_crtc->max_cursor_height)) {
1923 DRM_ERROR("bad cursor width or height %d x %d\n", width, height);
1924 return -EINVAL;
1925 }
1926
1927 obj = drm_gem_object_lookup(file_priv, handle);
1928 if (!obj) {
1929 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, amdgpu_crtc->crtc_id);
1930 return -ENOENT;
1931 }
1932
1933 aobj = gem_to_amdgpu_bo(obj);
1934 ret = amdgpu_bo_reserve(aobj, false);
1935 if (ret != 0) {
1936 drm_gem_object_unreference_unlocked(obj);
1937 return ret;
1938 }
1939
1940 ret = amdgpu_bo_pin(aobj, AMDGPU_GEM_DOMAIN_VRAM, &amdgpu_crtc->cursor_addr);
1941 amdgpu_bo_unreserve(aobj);
1942 if (ret) {
1943 DRM_ERROR("Failed to pin new cursor BO (%d)\n", ret);
1944 drm_gem_object_unreference_unlocked(obj);
1945 return ret;
1946 }
1947
1948 amdgpu_crtc->cursor_width = width;
1949 amdgpu_crtc->cursor_height = height;
1950
1951 dce_v6_0_lock_cursor(crtc, true);
1952
1953 if (hot_x != amdgpu_crtc->cursor_hot_x ||
1954 hot_y != amdgpu_crtc->cursor_hot_y) {
1955 int x, y;
1956
1957 x = amdgpu_crtc->cursor_x + amdgpu_crtc->cursor_hot_x - hot_x;
1958 y = amdgpu_crtc->cursor_y + amdgpu_crtc->cursor_hot_y - hot_y;
1959
1960 dce_v6_0_cursor_move_locked(crtc, x, y);
1961
1962 amdgpu_crtc->cursor_hot_x = hot_x;
1963 amdgpu_crtc->cursor_hot_y = hot_y;
1964 }
1965
1966 dce_v6_0_show_cursor(crtc);
1967 dce_v6_0_lock_cursor(crtc, false);
1968
1969unpin:
1970 if (amdgpu_crtc->cursor_bo) {
1971 struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
1972 ret = amdgpu_bo_reserve(aobj, false);
1973 if (likely(ret == 0)) {
1974 amdgpu_bo_unpin(aobj);
1975 amdgpu_bo_unreserve(aobj);
1976 }
1977 drm_gem_object_unreference_unlocked(amdgpu_crtc->cursor_bo);
1978 }
1979
1980 amdgpu_crtc->cursor_bo = obj;
1981 return 0;
1982}
1983
1984static void dce_v6_0_cursor_reset(struct drm_crtc *crtc)
1985{
1986 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
1987
1988 if (amdgpu_crtc->cursor_bo) {
1989 dce_v6_0_lock_cursor(crtc, true);
1990
1991 dce_v6_0_cursor_move_locked(crtc, amdgpu_crtc->cursor_x,
1992 amdgpu_crtc->cursor_y);
1993
1994 dce_v6_0_show_cursor(crtc);
e2cdf640
KW
1995 dce_v6_0_lock_cursor(crtc, false);
1996 }
1997}
1998
1999static int dce_v6_0_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
2000 u16 *blue, uint32_t size)
2001{
2002 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2003 int i;
2004
2005 /* userspace palettes are always correct as is */
2006 for (i = 0; i < size; i++) {
2007 amdgpu_crtc->lut_r[i] = red[i] >> 6;
2008 amdgpu_crtc->lut_g[i] = green[i] >> 6;
2009 amdgpu_crtc->lut_b[i] = blue[i] >> 6;
2010 }
2011 dce_v6_0_crtc_load_lut(crtc);
2012
2013 return 0;
2014}
2015
2016static void dce_v6_0_crtc_destroy(struct drm_crtc *crtc)
2017{
2018 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2019
2020 drm_crtc_cleanup(crtc);
2021 kfree(amdgpu_crtc);
2022}
2023
2024static const struct drm_crtc_funcs dce_v6_0_crtc_funcs = {
2025 .cursor_set2 = dce_v6_0_crtc_cursor_set2,
2026 .cursor_move = dce_v6_0_crtc_cursor_move,
2027 .gamma_set = dce_v6_0_crtc_gamma_set,
2028 .set_config = amdgpu_crtc_set_config,
2029 .destroy = dce_v6_0_crtc_destroy,
2030 .page_flip_target = amdgpu_crtc_page_flip_target,
2031};
2032
2033static void dce_v6_0_crtc_dpms(struct drm_crtc *crtc, int mode)
2034{
2035 struct drm_device *dev = crtc->dev;
2036 struct amdgpu_device *adev = dev->dev_private;
2037 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2038 unsigned type;
2039
2040 switch (mode) {
2041 case DRM_MODE_DPMS_ON:
2042 amdgpu_crtc->enabled = true;
2043 amdgpu_atombios_crtc_enable(crtc, ATOM_ENABLE);
2044 amdgpu_atombios_crtc_blank(crtc, ATOM_DISABLE);
2045 /* Make sure VBLANK and PFLIP interrupts are still enabled */
2046 type = amdgpu_crtc_idx_to_irq_type(adev, amdgpu_crtc->crtc_id);
2047 amdgpu_irq_update(adev, &adev->crtc_irq, type);
2048 amdgpu_irq_update(adev, &adev->pageflip_irq, type);
778e1a54 2049 drm_crtc_vblank_on(crtc);
e2cdf640
KW
2050 dce_v6_0_crtc_load_lut(crtc);
2051 break;
2052 case DRM_MODE_DPMS_STANDBY:
2053 case DRM_MODE_DPMS_SUSPEND:
2054 case DRM_MODE_DPMS_OFF:
778e1a54 2055 drm_crtc_vblank_off(crtc);
e2cdf640
KW
2056 if (amdgpu_crtc->enabled)
2057 amdgpu_atombios_crtc_blank(crtc, ATOM_ENABLE);
2058 amdgpu_atombios_crtc_enable(crtc, ATOM_DISABLE);
2059 amdgpu_crtc->enabled = false;
2060 break;
2061 }
2062 /* adjust pm to dpms */
2063 amdgpu_pm_compute_clocks(adev);
2064}
2065
2066static void dce_v6_0_crtc_prepare(struct drm_crtc *crtc)
2067{
2068 /* disable crtc pair power gating before programming */
2069 amdgpu_atombios_crtc_powergate(crtc, ATOM_DISABLE);
2070 amdgpu_atombios_crtc_lock(crtc, ATOM_ENABLE);
2071 dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
2072}
2073
2074static void dce_v6_0_crtc_commit(struct drm_crtc *crtc)
2075{
2076 dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
2077 amdgpu_atombios_crtc_lock(crtc, ATOM_DISABLE);
2078}
2079
2080static void dce_v6_0_crtc_disable(struct drm_crtc *crtc)
2081{
2082
2083 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2084 struct drm_device *dev = crtc->dev;
2085 struct amdgpu_device *adev = dev->dev_private;
2086 struct amdgpu_atom_ss ss;
2087 int i;
2088
2089 dce_v6_0_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
2090 if (crtc->primary->fb) {
2091 int r;
2092 struct amdgpu_framebuffer *amdgpu_fb;
765e7fbf 2093 struct amdgpu_bo *abo;
e2cdf640
KW
2094
2095 amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
765e7fbf
CK
2096 abo = gem_to_amdgpu_bo(amdgpu_fb->obj);
2097 r = amdgpu_bo_reserve(abo, false);
e2cdf640 2098 if (unlikely(r))
765e7fbf 2099 DRM_ERROR("failed to reserve abo before unpin\n");
e2cdf640 2100 else {
765e7fbf
CK
2101 amdgpu_bo_unpin(abo);
2102 amdgpu_bo_unreserve(abo);
e2cdf640
KW
2103 }
2104 }
2105 /* disable the GRPH */
2106 dce_v6_0_grph_enable(crtc, false);
2107
2108 amdgpu_atombios_crtc_powergate(crtc, ATOM_ENABLE);
2109
2110 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2111 if (adev->mode_info.crtcs[i] &&
2112 adev->mode_info.crtcs[i]->enabled &&
2113 i != amdgpu_crtc->crtc_id &&
2114 amdgpu_crtc->pll_id == adev->mode_info.crtcs[i]->pll_id) {
2115 /* one other crtc is using this pll don't turn
2116 * off the pll
2117 */
2118 goto done;
2119 }
2120 }
2121
2122 switch (amdgpu_crtc->pll_id) {
2123 case ATOM_PPLL1:
2124 case ATOM_PPLL2:
2125 /* disable the ppll */
2126 amdgpu_atombios_crtc_program_pll(crtc, amdgpu_crtc->crtc_id, amdgpu_crtc->pll_id,
2127 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss);
2128 break;
2129 default:
2130 break;
2131 }
2132done:
2133 amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
2134 amdgpu_crtc->adjusted_clock = 0;
2135 amdgpu_crtc->encoder = NULL;
2136 amdgpu_crtc->connector = NULL;
2137}
2138
2139static int dce_v6_0_crtc_mode_set(struct drm_crtc *crtc,
2140 struct drm_display_mode *mode,
2141 struct drm_display_mode *adjusted_mode,
2142 int x, int y, struct drm_framebuffer *old_fb)
2143{
2144 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2145
2146 if (!amdgpu_crtc->adjusted_clock)
2147 return -EINVAL;
2148
2149 amdgpu_atombios_crtc_set_pll(crtc, adjusted_mode);
2150 amdgpu_atombios_crtc_set_dtd_timing(crtc, adjusted_mode);
2151 dce_v6_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
2152 amdgpu_atombios_crtc_overscan_setup(crtc, mode, adjusted_mode);
2153 amdgpu_atombios_crtc_scaler_setup(crtc);
2154 dce_v6_0_cursor_reset(crtc);
2155 /* update the hw version fpr dpm */
2156 amdgpu_crtc->hw_mode = *adjusted_mode;
2157
2158 return 0;
2159}
2160
2161static bool dce_v6_0_crtc_mode_fixup(struct drm_crtc *crtc,
2162 const struct drm_display_mode *mode,
2163 struct drm_display_mode *adjusted_mode)
2164{
2165
2166 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
2167 struct drm_device *dev = crtc->dev;
2168 struct drm_encoder *encoder;
2169
2170 /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */
2171 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2172 if (encoder->crtc == crtc) {
2173 amdgpu_crtc->encoder = encoder;
2174 amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder);
2175 break;
2176 }
2177 }
2178 if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) {
2179 amdgpu_crtc->encoder = NULL;
2180 amdgpu_crtc->connector = NULL;
2181 return false;
2182 }
2183 if (!amdgpu_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
2184 return false;
2185 if (amdgpu_atombios_crtc_prepare_pll(crtc, adjusted_mode))
2186 return false;
2187 /* pick pll */
2188 amdgpu_crtc->pll_id = dce_v6_0_pick_pll(crtc);
2189 /* if we can't get a PPLL for a non-DP encoder, fail */
2190 if ((amdgpu_crtc->pll_id == ATOM_PPLL_INVALID) &&
2191 !ENCODER_MODE_IS_DP(amdgpu_atombios_encoder_get_encoder_mode(amdgpu_crtc->encoder)))
2192 return false;
2193
2194 return true;
2195}
2196
2197static int dce_v6_0_crtc_set_base(struct drm_crtc *crtc, int x, int y,
2198 struct drm_framebuffer *old_fb)
2199{
2200 return dce_v6_0_crtc_do_set_base(crtc, old_fb, x, y, 0);
2201}
2202
2203static int dce_v6_0_crtc_set_base_atomic(struct drm_crtc *crtc,
2204 struct drm_framebuffer *fb,
2205 int x, int y, enum mode_set_atomic state)
2206{
2207 return dce_v6_0_crtc_do_set_base(crtc, fb, x, y, 1);
2208}
2209
2210static const struct drm_crtc_helper_funcs dce_v6_0_crtc_helper_funcs = {
2211 .dpms = dce_v6_0_crtc_dpms,
2212 .mode_fixup = dce_v6_0_crtc_mode_fixup,
2213 .mode_set = dce_v6_0_crtc_mode_set,
2214 .mode_set_base = dce_v6_0_crtc_set_base,
2215 .mode_set_base_atomic = dce_v6_0_crtc_set_base_atomic,
2216 .prepare = dce_v6_0_crtc_prepare,
2217 .commit = dce_v6_0_crtc_commit,
2218 .load_lut = dce_v6_0_crtc_load_lut,
2219 .disable = dce_v6_0_crtc_disable,
2220};
2221
2222static int dce_v6_0_crtc_init(struct amdgpu_device *adev, int index)
2223{
2224 struct amdgpu_crtc *amdgpu_crtc;
2225 int i;
2226
2227 amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) +
2228 (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
2229 if (amdgpu_crtc == NULL)
2230 return -ENOMEM;
2231
2232 drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_v6_0_crtc_funcs);
2233
2234 drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256);
2235 amdgpu_crtc->crtc_id = index;
2236 adev->mode_info.crtcs[index] = amdgpu_crtc;
2237
2238 amdgpu_crtc->max_cursor_width = CURSOR_WIDTH;
2239 amdgpu_crtc->max_cursor_height = CURSOR_HEIGHT;
2240 adev->ddev->mode_config.cursor_width = amdgpu_crtc->max_cursor_width;
2241 adev->ddev->mode_config.cursor_height = amdgpu_crtc->max_cursor_height;
2242
2243 for (i = 0; i < 256; i++) {
2244 amdgpu_crtc->lut_r[i] = i << 2;
2245 amdgpu_crtc->lut_g[i] = i << 2;
2246 amdgpu_crtc->lut_b[i] = i << 2;
2247 }
2248
2249 amdgpu_crtc->crtc_offset = crtc_offsets[amdgpu_crtc->crtc_id];
2250
2251 amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;
2252 amdgpu_crtc->adjusted_clock = 0;
2253 amdgpu_crtc->encoder = NULL;
2254 amdgpu_crtc->connector = NULL;
2255 drm_crtc_helper_add(&amdgpu_crtc->base, &dce_v6_0_crtc_helper_funcs);
2256
2257 return 0;
2258}
2259
2260static int dce_v6_0_early_init(void *handle)
2261{
2262 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2263
2264 adev->audio_endpt_rreg = &dce_v6_0_audio_endpt_rreg;
2265 adev->audio_endpt_wreg = &dce_v6_0_audio_endpt_wreg;
2266
2267 dce_v6_0_set_display_funcs(adev);
2268 dce_v6_0_set_irq_funcs(adev);
2269
1d160f43
AD
2270 adev->mode_info.num_crtc = dce_v6_0_get_num_crtc(adev);
2271
e2cdf640
KW
2272 switch (adev->asic_type) {
2273 case CHIP_TAHITI:
2274 case CHIP_PITCAIRN:
2275 case CHIP_VERDE:
e2cdf640
KW
2276 adev->mode_info.num_hpd = 6;
2277 adev->mode_info.num_dig = 6;
2278 break;
2279 case CHIP_OLAND:
e2cdf640
KW
2280 adev->mode_info.num_hpd = 2;
2281 adev->mode_info.num_dig = 2;
2282 break;
2283 default:
e2cdf640
KW
2284 return -EINVAL;
2285 }
2286
2287 return 0;
2288}
2289
2290static int dce_v6_0_sw_init(void *handle)
2291{
2292 int r, i;
2293 bool ret;
2294 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2295
2296 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2297 r = amdgpu_irq_add_id(adev, i + 1, &adev->crtc_irq);
2298 if (r)
2299 return r;
2300 }
2301
2302 for (i = 8; i < 20; i += 2) {
2303 r = amdgpu_irq_add_id(adev, i, &adev->pageflip_irq);
2304 if (r)
2305 return r;
2306 }
2307
2308 /* HPD hotplug */
2309 r = amdgpu_irq_add_id(adev, 42, &adev->hpd_irq);
2310 if (r)
2311 return r;
2312
2313 adev->mode_info.mode_config_initialized = true;
2314
2315 adev->ddev->mode_config.funcs = &amdgpu_mode_funcs;
e2cdf640 2316 adev->ddev->mode_config.async_page_flip = true;
e2cdf640
KW
2317 adev->ddev->mode_config.max_width = 16384;
2318 adev->ddev->mode_config.max_height = 16384;
e2cdf640
KW
2319 adev->ddev->mode_config.preferred_depth = 24;
2320 adev->ddev->mode_config.prefer_shadow = 1;
e2cdf640
KW
2321 adev->ddev->mode_config.fb_base = adev->mc.aper_base;
2322
2323 r = amdgpu_modeset_create_props(adev);
2324 if (r)
2325 return r;
2326
2327 adev->ddev->mode_config.max_width = 16384;
2328 adev->ddev->mode_config.max_height = 16384;
2329
2330 /* allocate crtcs */
2331 for (i = 0; i < adev->mode_info.num_crtc; i++) {
2332 r = dce_v6_0_crtc_init(adev, i);
2333 if (r)
2334 return r;
2335 }
2336
2337 ret = amdgpu_atombios_get_connector_info_from_object_table(adev);
2338 if (ret)
2339 amdgpu_print_display_setup(adev->ddev);
2340 else
2341 return -EINVAL;
2342
2343 /* setup afmt */
beb86f29
TSD
2344 r = dce_v6_0_afmt_init(adev);
2345 if (r)
2346 return r;
e2cdf640
KW
2347
2348 r = dce_v6_0_audio_init(adev);
2349 if (r)
2350 return r;
2351
2352 drm_kms_helper_poll_init(adev->ddev);
2353
2354 return r;
2355}
2356
2357static int dce_v6_0_sw_fini(void *handle)
2358{
2359 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2360
2361 kfree(adev->mode_info.bios_hardcoded_edid);
2362
2363 drm_kms_helper_poll_fini(adev->ddev);
2364
2365 dce_v6_0_audio_fini(adev);
e2cdf640
KW
2366 dce_v6_0_afmt_fini(adev);
2367
2368 drm_mode_config_cleanup(adev->ddev);
2369 adev->mode_info.mode_config_initialized = false;
2370
2371 return 0;
2372}
2373
2374static int dce_v6_0_hw_init(void *handle)
2375{
2376 int i;
2377 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2378
2379 /* init dig PHYs, disp eng pll */
2380 amdgpu_atombios_encoder_init_dig(adev);
2381 amdgpu_atombios_crtc_set_disp_eng_pll(adev, adev->clock.default_dispclk);
2382
2383 /* initialize hpd */
2384 dce_v6_0_hpd_init(adev);
2385
2386 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
2387 dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
2388 }
2389
2390 dce_v6_0_pageflip_interrupt_init(adev);
2391
2392 return 0;
2393}
2394
2395static int dce_v6_0_hw_fini(void *handle)
2396{
2397 int i;
2398 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2399
2400 dce_v6_0_hpd_fini(adev);
2401
2402 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
2403 dce_v6_0_audio_enable(adev, &adev->mode_info.audio.pin[i], false);
2404 }
2405
2406 dce_v6_0_pageflip_interrupt_fini(adev);
2407
2408 return 0;
2409}
2410
2411static int dce_v6_0_suspend(void *handle)
2412{
e2cdf640
KW
2413 return dce_v6_0_hw_fini(handle);
2414}
2415
2416static int dce_v6_0_resume(void *handle)
2417{
2418 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2419 int ret;
2420
2421 ret = dce_v6_0_hw_init(handle);
2422
e2cdf640
KW
2423 /* turn on the BL */
2424 if (adev->mode_info.bl_encoder) {
2425 u8 bl_level = amdgpu_display_backlight_get_level(adev,
2426 adev->mode_info.bl_encoder);
2427 amdgpu_display_backlight_set_level(adev, adev->mode_info.bl_encoder,
2428 bl_level);
2429 }
2430
2431 return ret;
2432}
2433
2434static bool dce_v6_0_is_idle(void *handle)
2435{
2436 return true;
2437}
2438
2439static int dce_v6_0_wait_for_idle(void *handle)
2440{
2441 return 0;
2442}
2443
2444static int dce_v6_0_soft_reset(void *handle)
2445{
2446 DRM_INFO("xxxx: dce_v6_0_soft_reset --- no impl!!\n");
2447 return 0;
2448}
2449
2450static void dce_v6_0_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev,
2451 int crtc,
2452 enum amdgpu_interrupt_state state)
2453{
2454 u32 reg_block, interrupt_mask;
2455
2456 if (crtc >= adev->mode_info.num_crtc) {
2457 DRM_DEBUG("invalid crtc %d\n", crtc);
2458 return;
2459 }
2460
2461 switch (crtc) {
2462 case 0:
2463 reg_block = SI_CRTC0_REGISTER_OFFSET;
2464 break;
2465 case 1:
2466 reg_block = SI_CRTC1_REGISTER_OFFSET;
2467 break;
2468 case 2:
2469 reg_block = SI_CRTC2_REGISTER_OFFSET;
2470 break;
2471 case 3:
2472 reg_block = SI_CRTC3_REGISTER_OFFSET;
2473 break;
2474 case 4:
2475 reg_block = SI_CRTC4_REGISTER_OFFSET;
2476 break;
2477 case 5:
2478 reg_block = SI_CRTC5_REGISTER_OFFSET;
2479 break;
2480 default:
2481 DRM_DEBUG("invalid crtc %d\n", crtc);
2482 return;
2483 }
2484
2485 switch (state) {
2486 case AMDGPU_IRQ_STATE_DISABLE:
b00861b9 2487 interrupt_mask = RREG32(mmINT_MASK + reg_block);
e2cdf640 2488 interrupt_mask &= ~VBLANK_INT_MASK;
b00861b9 2489 WREG32(mmINT_MASK + reg_block, interrupt_mask);
e2cdf640
KW
2490 break;
2491 case AMDGPU_IRQ_STATE_ENABLE:
b00861b9 2492 interrupt_mask = RREG32(mmINT_MASK + reg_block);
e2cdf640 2493 interrupt_mask |= VBLANK_INT_MASK;
b00861b9 2494 WREG32(mmINT_MASK + reg_block, interrupt_mask);
e2cdf640
KW
2495 break;
2496 default:
2497 break;
2498 }
2499}
2500
2501static void dce_v6_0_set_crtc_vline_interrupt_state(struct amdgpu_device *adev,
2502 int crtc,
2503 enum amdgpu_interrupt_state state)
2504{
2505
2506}
2507
2508static int dce_v6_0_set_hpd_interrupt_state(struct amdgpu_device *adev,
2509 struct amdgpu_irq_src *src,
2510 unsigned type,
2511 enum amdgpu_interrupt_state state)
2512{
34386043 2513 u32 dc_hpd_int_cntl;
e2cdf640 2514
34386043 2515 if (type >= adev->mode_info.num_hpd) {
e2cdf640
KW
2516 DRM_DEBUG("invalid hdp %d\n", type);
2517 return 0;
2518 }
2519
2520 switch (state) {
2521 case AMDGPU_IRQ_STATE_DISABLE:
b00861b9 2522 dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
46c9cc11 2523 dc_hpd_int_cntl &= ~DC_HPDx_INT_EN;
b00861b9 2524 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
e2cdf640
KW
2525 break;
2526 case AMDGPU_IRQ_STATE_ENABLE:
b00861b9 2527 dc_hpd_int_cntl = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type]);
46c9cc11 2528 dc_hpd_int_cntl |= DC_HPDx_INT_EN;
b00861b9 2529 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[type], dc_hpd_int_cntl);
e2cdf640
KW
2530 break;
2531 default:
2532 break;
2533 }
2534
2535 return 0;
2536}
2537
2538static int dce_v6_0_set_crtc_interrupt_state(struct amdgpu_device *adev,
2539 struct amdgpu_irq_src *src,
2540 unsigned type,
2541 enum amdgpu_interrupt_state state)
2542{
2543 switch (type) {
2544 case AMDGPU_CRTC_IRQ_VBLANK1:
2545 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 0, state);
2546 break;
2547 case AMDGPU_CRTC_IRQ_VBLANK2:
2548 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 1, state);
2549 break;
2550 case AMDGPU_CRTC_IRQ_VBLANK3:
2551 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 2, state);
2552 break;
2553 case AMDGPU_CRTC_IRQ_VBLANK4:
2554 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 3, state);
2555 break;
2556 case AMDGPU_CRTC_IRQ_VBLANK5:
2557 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 4, state);
2558 break;
2559 case AMDGPU_CRTC_IRQ_VBLANK6:
2560 dce_v6_0_set_crtc_vblank_interrupt_state(adev, 5, state);
2561 break;
2562 case AMDGPU_CRTC_IRQ_VLINE1:
2563 dce_v6_0_set_crtc_vline_interrupt_state(adev, 0, state);
2564 break;
2565 case AMDGPU_CRTC_IRQ_VLINE2:
2566 dce_v6_0_set_crtc_vline_interrupt_state(adev, 1, state);
2567 break;
2568 case AMDGPU_CRTC_IRQ_VLINE3:
2569 dce_v6_0_set_crtc_vline_interrupt_state(adev, 2, state);
2570 break;
2571 case AMDGPU_CRTC_IRQ_VLINE4:
2572 dce_v6_0_set_crtc_vline_interrupt_state(adev, 3, state);
2573 break;
2574 case AMDGPU_CRTC_IRQ_VLINE5:
2575 dce_v6_0_set_crtc_vline_interrupt_state(adev, 4, state);
2576 break;
2577 case AMDGPU_CRTC_IRQ_VLINE6:
2578 dce_v6_0_set_crtc_vline_interrupt_state(adev, 5, state);
2579 break;
2580 default:
2581 break;
2582 }
2583 return 0;
2584}
2585
2586static int dce_v6_0_crtc_irq(struct amdgpu_device *adev,
2587 struct amdgpu_irq_src *source,
2588 struct amdgpu_iv_entry *entry)
2589{
2590 unsigned crtc = entry->src_id - 1;
2591 uint32_t disp_int = RREG32(interrupt_status_offsets[crtc].reg);
2592 unsigned irq_type = amdgpu_crtc_idx_to_irq_type(adev, crtc);
2593
2594 switch (entry->src_data) {
2595 case 0: /* vblank */
2596 if (disp_int & interrupt_status_offsets[crtc].vblank)
b00861b9 2597 WREG32(mmVBLANK_STATUS + crtc_offsets[crtc], VBLANK_ACK);
e2cdf640
KW
2598 else
2599 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
2600
2601 if (amdgpu_irq_enabled(adev, source, irq_type)) {
2602 drm_handle_vblank(adev->ddev, crtc);
2603 }
2604 DRM_DEBUG("IH: D%d vblank\n", crtc + 1);
2605 break;
2606 case 1: /* vline */
2607 if (disp_int & interrupt_status_offsets[crtc].vline)
b00861b9 2608 WREG32(mmVLINE_STATUS + crtc_offsets[crtc], VLINE_ACK);
e2cdf640
KW
2609 else
2610 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
2611
2612 DRM_DEBUG("IH: D%d vline\n", crtc + 1);
2613 break;
2614 default:
2615 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data);
2616 break;
2617 }
2618
2619 return 0;
2620}
2621
2622static int dce_v6_0_set_pageflip_interrupt_state(struct amdgpu_device *adev,
2623 struct amdgpu_irq_src *src,
2624 unsigned type,
2625 enum amdgpu_interrupt_state state)
2626{
2627 u32 reg;
2628
2629 if (type >= adev->mode_info.num_crtc) {
2630 DRM_ERROR("invalid pageflip crtc %d\n", type);
2631 return -EINVAL;
2632 }
2633
b00861b9 2634 reg = RREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type]);
e2cdf640 2635 if (state == AMDGPU_IRQ_STATE_DISABLE)
b00861b9 2636 WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
e2cdf640
KW
2637 reg & ~GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
2638 else
b00861b9 2639 WREG32(mmGRPH_INTERRUPT_CONTROL + crtc_offsets[type],
e2cdf640
KW
2640 reg | GRPH_INTERRUPT_CONTROL__GRPH_PFLIP_INT_MASK_MASK);
2641
2642 return 0;
2643}
2644
2645static int dce_v6_0_pageflip_irq(struct amdgpu_device *adev,
2646 struct amdgpu_irq_src *source,
2647 struct amdgpu_iv_entry *entry)
2648{
2649 unsigned long flags;
2650 unsigned crtc_id;
2651 struct amdgpu_crtc *amdgpu_crtc;
2652 struct amdgpu_flip_work *works;
2653
2654 crtc_id = (entry->src_id - 8) >> 1;
2655 amdgpu_crtc = adev->mode_info.crtcs[crtc_id];
2656
2657 if (crtc_id >= adev->mode_info.num_crtc) {
2658 DRM_ERROR("invalid pageflip crtc %d\n", crtc_id);
2659 return -EINVAL;
2660 }
2661
b00861b9 2662 if (RREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id]) &
e2cdf640 2663 GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_OCCURRED_MASK)
b00861b9 2664 WREG32(mmGRPH_INTERRUPT_STATUS + crtc_offsets[crtc_id],
e2cdf640
KW
2665 GRPH_INTERRUPT_STATUS__GRPH_PFLIP_INT_CLEAR_MASK);
2666
2667 /* IRQ could occur when in initial stage */
2668 if (amdgpu_crtc == NULL)
2669 return 0;
2670
2671 spin_lock_irqsave(&adev->ddev->event_lock, flags);
2672 works = amdgpu_crtc->pflip_works;
2673 if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED){
2674 DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != "
2675 "AMDGPU_FLIP_SUBMITTED(%d)\n",
2676 amdgpu_crtc->pflip_status,
2677 AMDGPU_FLIP_SUBMITTED);
2678 spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
2679 return 0;
2680 }
2681
2682 /* page flip completed. clean up */
2683 amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
2684 amdgpu_crtc->pflip_works = NULL;
2685
2686 /* wakeup usersapce */
2687 if (works->event)
2688 drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event);
2689
2690 spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
2691
2692 drm_crtc_vblank_put(&amdgpu_crtc->base);
2693 schedule_work(&works->unpin_work);
2694
2695 return 0;
2696}
2697
2698static int dce_v6_0_hpd_irq(struct amdgpu_device *adev,
2699 struct amdgpu_irq_src *source,
2700 struct amdgpu_iv_entry *entry)
2701{
34386043 2702 uint32_t disp_int, mask, tmp;
e2cdf640
KW
2703 unsigned hpd;
2704
664a08bb 2705 if (entry->src_data >= adev->mode_info.num_hpd) {
e2cdf640
KW
2706 DRM_DEBUG("Unhandled interrupt: %d %d\n", entry->src_id, entry->src_data);
2707 return 0;
2708 }
2709
2710 hpd = entry->src_data;
2711 disp_int = RREG32(interrupt_status_offsets[hpd].reg);
2712 mask = interrupt_status_offsets[hpd].hpd;
e2cdf640
KW
2713
2714 if (disp_int & mask) {
b00861b9 2715 tmp = RREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd]);
e2cdf640 2716 tmp |= DC_HPD1_INT_CONTROL__DC_HPD1_INT_ACK_MASK;
b00861b9 2717 WREG32(mmDC_HPD1_INT_CONTROL + hpd_offsets[hpd], tmp);
e2cdf640
KW
2718 schedule_work(&adev->hotplug_work);
2719 DRM_INFO("IH: HPD%d\n", hpd + 1);
2720 }
2721
2722 return 0;
2723
2724}
2725
2726static int dce_v6_0_set_clockgating_state(void *handle,
2727 enum amd_clockgating_state state)
2728{
2729 return 0;
2730}
2731
2732static int dce_v6_0_set_powergating_state(void *handle,
2733 enum amd_powergating_state state)
2734{
2735 return 0;
2736}
2737
a1255107 2738static const struct amd_ip_funcs dce_v6_0_ip_funcs = {
e2cdf640
KW
2739 .name = "dce_v6_0",
2740 .early_init = dce_v6_0_early_init,
2741 .late_init = NULL,
2742 .sw_init = dce_v6_0_sw_init,
2743 .sw_fini = dce_v6_0_sw_fini,
2744 .hw_init = dce_v6_0_hw_init,
2745 .hw_fini = dce_v6_0_hw_fini,
2746 .suspend = dce_v6_0_suspend,
2747 .resume = dce_v6_0_resume,
2748 .is_idle = dce_v6_0_is_idle,
2749 .wait_for_idle = dce_v6_0_wait_for_idle,
2750 .soft_reset = dce_v6_0_soft_reset,
2751 .set_clockgating_state = dce_v6_0_set_clockgating_state,
2752 .set_powergating_state = dce_v6_0_set_powergating_state,
2753};
2754
2755static void
2756dce_v6_0_encoder_mode_set(struct drm_encoder *encoder,
2757 struct drm_display_mode *mode,
2758 struct drm_display_mode *adjusted_mode)
2759{
2760
2761 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2762
2763 amdgpu_encoder->pixel_clock = adjusted_mode->clock;
2764
2765 /* need to call this here rather than in prepare() since we need some crtc info */
2766 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2767
2768 /* set scaler clears this on some chips */
2769 dce_v6_0_set_interleave(encoder->crtc, mode);
2770
2771 if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
2772 dce_v6_0_afmt_enable(encoder, true);
2773 dce_v6_0_afmt_setmode(encoder, adjusted_mode);
2774 }
2775}
2776
2777static void dce_v6_0_encoder_prepare(struct drm_encoder *encoder)
2778{
2779
2780 struct amdgpu_device *adev = encoder->dev->dev_private;
2781 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2782 struct drm_connector *connector = amdgpu_get_connector_for_encoder(encoder);
2783
2784 if ((amdgpu_encoder->active_device &
2785 (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
2786 (amdgpu_encoder_get_dp_bridge_encoder_id(encoder) !=
2787 ENCODER_OBJECT_ID_NONE)) {
2788 struct amdgpu_encoder_atom_dig *dig = amdgpu_encoder->enc_priv;
2789 if (dig) {
2790 dig->dig_encoder = dce_v6_0_pick_dig_encoder(encoder);
2791 if (amdgpu_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT)
2792 dig->afmt = adev->mode_info.afmt[dig->dig_encoder];
2793 }
2794 }
2795
2796 amdgpu_atombios_scratch_regs_lock(adev, true);
2797
2798 if (connector) {
2799 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
2800
2801 /* select the clock/data port if it uses a router */
2802 if (amdgpu_connector->router.cd_valid)
2803 amdgpu_i2c_router_select_cd_port(amdgpu_connector);
2804
2805 /* turn eDP panel on for mode set */
2806 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
2807 amdgpu_atombios_encoder_set_edp_panel_power(connector,
2808 ATOM_TRANSMITTER_ACTION_POWER_ON);
2809 }
2810
2811 /* this is needed for the pll/ss setup to work correctly in some cases */
2812 amdgpu_atombios_encoder_set_crtc_source(encoder);
2813 /* set up the FMT blocks */
2814 dce_v6_0_program_fmt(encoder);
2815}
2816
2817static void dce_v6_0_encoder_commit(struct drm_encoder *encoder)
2818{
2819
2820 struct drm_device *dev = encoder->dev;
2821 struct amdgpu_device *adev = dev->dev_private;
2822
2823 /* need to call this here as we need the crtc set up */
2824 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
2825 amdgpu_atombios_scratch_regs_lock(adev, false);
2826}
2827
2828static void dce_v6_0_encoder_disable(struct drm_encoder *encoder)
2829{
2830
2831 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2832 struct amdgpu_encoder_atom_dig *dig;
2833
2834 amdgpu_atombios_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2835
2836 if (amdgpu_atombios_encoder_is_digital(encoder)) {
2837 if (amdgpu_atombios_encoder_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
2838 dce_v6_0_afmt_enable(encoder, false);
2839 dig = amdgpu_encoder->enc_priv;
2840 dig->dig_encoder = -1;
2841 }
2842 amdgpu_encoder->active_device = 0;
2843}
2844
2845/* these are handled by the primary encoders */
2846static void dce_v6_0_ext_prepare(struct drm_encoder *encoder)
2847{
2848
2849}
2850
2851static void dce_v6_0_ext_commit(struct drm_encoder *encoder)
2852{
2853
2854}
2855
2856static void
2857dce_v6_0_ext_mode_set(struct drm_encoder *encoder,
2858 struct drm_display_mode *mode,
2859 struct drm_display_mode *adjusted_mode)
2860{
2861
2862}
2863
2864static void dce_v6_0_ext_disable(struct drm_encoder *encoder)
2865{
2866
2867}
2868
2869static void
2870dce_v6_0_ext_dpms(struct drm_encoder *encoder, int mode)
2871{
2872
2873}
2874
2875static bool dce_v6_0_ext_mode_fixup(struct drm_encoder *encoder,
2876 const struct drm_display_mode *mode,
2877 struct drm_display_mode *adjusted_mode)
2878{
2879 return true;
2880}
2881
2882static const struct drm_encoder_helper_funcs dce_v6_0_ext_helper_funcs = {
2883 .dpms = dce_v6_0_ext_dpms,
2884 .mode_fixup = dce_v6_0_ext_mode_fixup,
2885 .prepare = dce_v6_0_ext_prepare,
2886 .mode_set = dce_v6_0_ext_mode_set,
2887 .commit = dce_v6_0_ext_commit,
2888 .disable = dce_v6_0_ext_disable,
2889 /* no detect for TMDS/LVDS yet */
2890};
2891
2892static const struct drm_encoder_helper_funcs dce_v6_0_dig_helper_funcs = {
2893 .dpms = amdgpu_atombios_encoder_dpms,
2894 .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
2895 .prepare = dce_v6_0_encoder_prepare,
2896 .mode_set = dce_v6_0_encoder_mode_set,
2897 .commit = dce_v6_0_encoder_commit,
2898 .disable = dce_v6_0_encoder_disable,
2899 .detect = amdgpu_atombios_encoder_dig_detect,
2900};
2901
2902static const struct drm_encoder_helper_funcs dce_v6_0_dac_helper_funcs = {
2903 .dpms = amdgpu_atombios_encoder_dpms,
2904 .mode_fixup = amdgpu_atombios_encoder_mode_fixup,
2905 .prepare = dce_v6_0_encoder_prepare,
2906 .mode_set = dce_v6_0_encoder_mode_set,
2907 .commit = dce_v6_0_encoder_commit,
2908 .detect = amdgpu_atombios_encoder_dac_detect,
2909};
2910
2911static void dce_v6_0_encoder_destroy(struct drm_encoder *encoder)
2912{
2913 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
2914 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
2915 amdgpu_atombios_encoder_fini_backlight(amdgpu_encoder);
2916 kfree(amdgpu_encoder->enc_priv);
2917 drm_encoder_cleanup(encoder);
2918 kfree(amdgpu_encoder);
2919}
2920
2921static const struct drm_encoder_funcs dce_v6_0_encoder_funcs = {
2922 .destroy = dce_v6_0_encoder_destroy,
2923};
2924
2925static void dce_v6_0_encoder_add(struct amdgpu_device *adev,
2926 uint32_t encoder_enum,
2927 uint32_t supported_device,
2928 u16 caps)
2929{
2930 struct drm_device *dev = adev->ddev;
2931 struct drm_encoder *encoder;
2932 struct amdgpu_encoder *amdgpu_encoder;
2933
2934 /* see if we already added it */
2935 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2936 amdgpu_encoder = to_amdgpu_encoder(encoder);
2937 if (amdgpu_encoder->encoder_enum == encoder_enum) {
2938 amdgpu_encoder->devices |= supported_device;
2939 return;
2940 }
2941
2942 }
2943
2944 /* add a new one */
2945 amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL);
2946 if (!amdgpu_encoder)
2947 return;
2948
2949 encoder = &amdgpu_encoder->base;
2950 switch (adev->mode_info.num_crtc) {
2951 case 1:
2952 encoder->possible_crtcs = 0x1;
2953 break;
2954 case 2:
2955 default:
2956 encoder->possible_crtcs = 0x3;
2957 break;
2958 case 4:
2959 encoder->possible_crtcs = 0xf;
2960 break;
2961 case 6:
2962 encoder->possible_crtcs = 0x3f;
2963 break;
2964 }
2965
2966 amdgpu_encoder->enc_priv = NULL;
e2cdf640
KW
2967 amdgpu_encoder->encoder_enum = encoder_enum;
2968 amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
2969 amdgpu_encoder->devices = supported_device;
2970 amdgpu_encoder->rmx_type = RMX_OFF;
2971 amdgpu_encoder->underscan_type = UNDERSCAN_OFF;
2972 amdgpu_encoder->is_ext_encoder = false;
2973 amdgpu_encoder->caps = caps;
2974
2975 switch (amdgpu_encoder->encoder_id) {
2976 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2977 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2978 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
2979 DRM_MODE_ENCODER_DAC, NULL);
2980 drm_encoder_helper_add(encoder, &dce_v6_0_dac_helper_funcs);
2981 break;
2982 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2983 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2984 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2985 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2986 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
2987 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
2988 amdgpu_encoder->rmx_type = RMX_FULL;
2989 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
2990 DRM_MODE_ENCODER_LVDS, NULL);
2991 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_lcd_info(amdgpu_encoder);
2992 } else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
2993 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
2994 DRM_MODE_ENCODER_DAC, NULL);
2995 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
2996 } else {
2997 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
2998 DRM_MODE_ENCODER_TMDS, NULL);
2999 amdgpu_encoder->enc_priv = amdgpu_atombios_encoder_get_dig_info(amdgpu_encoder);
3000 }
3001 drm_encoder_helper_add(encoder, &dce_v6_0_dig_helper_funcs);
3002 break;
3003 case ENCODER_OBJECT_ID_SI170B:
3004 case ENCODER_OBJECT_ID_CH7303:
3005 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
3006 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
3007 case ENCODER_OBJECT_ID_TITFP513:
3008 case ENCODER_OBJECT_ID_VT1623:
3009 case ENCODER_OBJECT_ID_HDMI_SI1930:
3010 case ENCODER_OBJECT_ID_TRAVIS:
3011 case ENCODER_OBJECT_ID_NUTMEG:
3012 /* these are handled by the primary encoders */
3013 amdgpu_encoder->is_ext_encoder = true;
3014 if (amdgpu_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
3015 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
3016 DRM_MODE_ENCODER_LVDS, NULL);
3017 else if (amdgpu_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
3018 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
3019 DRM_MODE_ENCODER_DAC, NULL);
3020 else
3021 drm_encoder_init(dev, encoder, &dce_v6_0_encoder_funcs,
3022 DRM_MODE_ENCODER_TMDS, NULL);
3023 drm_encoder_helper_add(encoder, &dce_v6_0_ext_helper_funcs);
3024 break;
3025 }
3026}
3027
3028static const struct amdgpu_display_funcs dce_v6_0_display_funcs = {
3029 .set_vga_render_state = &dce_v6_0_set_vga_render_state,
3030 .bandwidth_update = &dce_v6_0_bandwidth_update,
3031 .vblank_get_counter = &dce_v6_0_vblank_get_counter,
3032 .vblank_wait = &dce_v6_0_vblank_wait,
e2cdf640
KW
3033 .backlight_set_level = &amdgpu_atombios_encoder_set_backlight_level,
3034 .backlight_get_level = &amdgpu_atombios_encoder_get_backlight_level,
3035 .hpd_sense = &dce_v6_0_hpd_sense,
3036 .hpd_set_polarity = &dce_v6_0_hpd_set_polarity,
3037 .hpd_get_gpio_reg = &dce_v6_0_hpd_get_gpio_reg,
3038 .page_flip = &dce_v6_0_page_flip,
3039 .page_flip_get_scanoutpos = &dce_v6_0_crtc_get_scanoutpos,
3040 .add_encoder = &dce_v6_0_encoder_add,
3041 .add_connector = &amdgpu_connector_add,
3042 .stop_mc_access = &dce_v6_0_stop_mc_access,
3043 .resume_mc_access = &dce_v6_0_resume_mc_access,
3044};
3045
3046static void dce_v6_0_set_display_funcs(struct amdgpu_device *adev)
3047{
3048 if (adev->mode_info.funcs == NULL)
3049 adev->mode_info.funcs = &dce_v6_0_display_funcs;
3050}
3051
3052static const struct amdgpu_irq_src_funcs dce_v6_0_crtc_irq_funcs = {
3053 .set = dce_v6_0_set_crtc_interrupt_state,
3054 .process = dce_v6_0_crtc_irq,
3055};
3056
3057static const struct amdgpu_irq_src_funcs dce_v6_0_pageflip_irq_funcs = {
3058 .set = dce_v6_0_set_pageflip_interrupt_state,
3059 .process = dce_v6_0_pageflip_irq,
3060};
3061
3062static const struct amdgpu_irq_src_funcs dce_v6_0_hpd_irq_funcs = {
3063 .set = dce_v6_0_set_hpd_interrupt_state,
3064 .process = dce_v6_0_hpd_irq,
3065};
3066
3067static void dce_v6_0_set_irq_funcs(struct amdgpu_device *adev)
3068{
3069 adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_LAST;
3070 adev->crtc_irq.funcs = &dce_v6_0_crtc_irq_funcs;
3071
3072 adev->pageflip_irq.num_types = AMDGPU_PAGEFLIP_IRQ_LAST;
3073 adev->pageflip_irq.funcs = &dce_v6_0_pageflip_irq_funcs;
3074
3075 adev->hpd_irq.num_types = AMDGPU_HPD_LAST;
3076 adev->hpd_irq.funcs = &dce_v6_0_hpd_irq_funcs;
3077}
a1255107
AD
3078
3079const struct amdgpu_ip_block_version dce_v6_0_ip_block =
3080{
3081 .type = AMD_IP_BLOCK_TYPE_DCE,
3082 .major = 6,
3083 .minor = 0,
3084 .rev = 0,
3085 .funcs = &dce_v6_0_ip_funcs,
3086};
3087
3088const struct amdgpu_ip_block_version dce_v6_4_ip_block =
3089{
3090 .type = AMD_IP_BLOCK_TYPE_DCE,
3091 .major = 6,
3092 .minor = 4,
3093 .rev = 0,
3094 .funcs = &dce_v6_0_ip_funcs,
3095};