blob: f2896e5ff05558d95e5d80a8f46e87f1a9fc2871 [file] [log] [blame]
Rafał Miłeckie55d3e62012-05-06 17:29:44 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Christian König.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Christian König
25 * Rafał Miłecki
26 */
Thierry Redinge3b2e032013-01-14 13:36:30 +010027#include <linux/hdmi.h>
David Howells760285e2012-10-02 18:01:07 +010028#include <drm/drmP.h>
29#include <drm/radeon_drm.h>
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020030#include "radeon.h"
31#include "radeon_asic.h"
Alex Deucher070a2e62015-01-22 10:41:55 -050032#include "radeon_audio.h"
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020033#include "evergreend.h"
34#include "atom.h"
35
Alex Deucherd3d8c142014-09-18 17:26:39 -040036/* enable the audio stream */
Slava Grigorev8bf59822014-12-03 15:29:53 -050037void dce4_audio_enable(struct radeon_device *rdev,
Alex Deucherd3d8c142014-09-18 17:26:39 -040038 struct r600_audio_pin *pin,
39 u8 enable_mask)
40{
41 u32 tmp = RREG32(AZ_HOT_PLUG_CONTROL);
42
43 if (!pin)
44 return;
45
46 if (enable_mask) {
47 tmp |= AUDIO_ENABLED;
48 if (enable_mask & 1)
49 tmp |= PIN0_AUDIO_ENABLED;
50 if (enable_mask & 2)
51 tmp |= PIN1_AUDIO_ENABLED;
52 if (enable_mask & 4)
53 tmp |= PIN2_AUDIO_ENABLED;
54 if (enable_mask & 8)
55 tmp |= PIN3_AUDIO_ENABLED;
56 } else {
57 tmp &= ~(AUDIO_ENABLED |
58 PIN0_AUDIO_ENABLED |
59 PIN1_AUDIO_ENABLED |
60 PIN2_AUDIO_ENABLED |
61 PIN3_AUDIO_ENABLED);
62 }
63
64 WREG32(AZ_HOT_PLUG_CONTROL, tmp);
65}
66
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020067/*
68 * update the N and CTS parameters for a given pixel clock rate
69 */
70static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
71{
72 struct drm_device *dev = encoder->dev;
73 struct radeon_device *rdev = dev->dev_private;
74 struct radeon_hdmi_acr acr = r600_hdmi_acr(clock);
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +020075 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
76 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
77 uint32_t offset = dig->afmt->offset;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020078
79 WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz));
80 WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz);
81
82 WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz));
83 WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz);
84
85 WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz));
86 WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz);
87}
88
Slava Grigorev87654f82014-12-02 11:20:48 -050089void dce4_afmt_write_latency_fields(struct drm_encoder *encoder,
90 struct drm_connector *connector, struct drm_display_mode *mode)
Alex Deucher712fd8a2013-10-10 17:54:51 -040091{
92 struct radeon_device *rdev = encoder->dev->dev_private;
Alex Deucher712fd8a2013-10-10 17:54:51 -040093 u32 tmp = 0;
94
Alex Deucher712fd8a2013-10-10 17:54:51 -040095 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
96 if (connector->latency_present[1])
97 tmp = VIDEO_LIPSYNC(connector->video_latency[1]) |
98 AUDIO_LIPSYNC(connector->audio_latency[1]);
99 else
100 tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255);
101 } else {
102 if (connector->latency_present[0])
103 tmp = VIDEO_LIPSYNC(connector->video_latency[0]) |
104 AUDIO_LIPSYNC(connector->audio_latency[0]);
105 else
106 tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255);
107 }
Slava Grigorev87654f82014-12-02 11:20:48 -0500108 WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp);
Alex Deucher712fd8a2013-10-10 17:54:51 -0400109}
110
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500111void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
112 u8 *sadb, int sad_count)
Alex Deucherba7def42013-08-15 09:34:07 -0400113{
114 struct radeon_device *rdev = encoder->dev->dev_private;
Alex Deucherba7def42013-08-15 09:34:07 -0400115 u32 tmp;
Alex Deucherba7def42013-08-15 09:34:07 -0400116
117 /* program the speaker allocation */
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500118 tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
Alex Deucherba7def42013-08-15 09:34:07 -0400119 tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
120 /* set HDMI mode */
121 tmp |= HDMI_CONNECTION;
122 if (sad_count)
123 tmp |= SPEAKER_ALLOCATION(sadb[0]);
124 else
125 tmp |= SPEAKER_ALLOCATION(5); /* stereo */
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500126 WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
127}
Alex Deucherba7def42013-08-15 09:34:07 -0400128
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500129void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
130 u8 *sadb, int sad_count)
131{
132 struct radeon_device *rdev = encoder->dev->dev_private;
133 u32 tmp;
134
135 /* program the speaker allocation */
136 tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
137 tmp &= ~(HDMI_CONNECTION | SPEAKER_ALLOCATION_MASK);
138 /* set DP mode */
139 tmp |= DP_CONNECTION;
140 if (sad_count)
141 tmp |= SPEAKER_ALLOCATION(sadb[0]);
142 else
143 tmp |= SPEAKER_ALLOCATION(5); /* stereo */
144 WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
Alex Deucherba7def42013-08-15 09:34:07 -0400145}
146
Alex Deucher070a2e62015-01-22 10:41:55 -0500147void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder,
148 struct cea_sad *sads, int sad_count)
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200149{
Alex Deucher070a2e62015-01-22 10:41:55 -0500150 int i;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200151 struct radeon_device *rdev = encoder->dev->dev_private;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200152 static const u16 eld_reg_to_type[][2] = {
153 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
154 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
155 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
156 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
157 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
158 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
159 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
160 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
161 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
162 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
163 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
164 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
165 };
166
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200167 for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
168 u32 value = 0;
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200169 u8 stereo_freqs = 0;
170 int max_channels = -1;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200171 int j;
172
173 for (j = 0; j < sad_count; j++) {
174 struct cea_sad *sad = &sads[j];
175
176 if (sad->format == eld_reg_to_type[i][1]) {
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200177 if (sad->channels > max_channels) {
178 value = MAX_CHANNELS(sad->channels) |
179 DESCRIPTOR_BYTE_2(sad->byte2) |
180 SUPPORTED_FREQUENCIES(sad->freq);
181 max_channels = sad->channels;
182 }
183
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200184 if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200185 stereo_freqs |= sad->freq;
186 else
187 break;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200188 }
189 }
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200190
191 value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs);
192
Alex Deucher070a2e62015-01-22 10:41:55 -0500193 WREG32_ENDPOINT(0, eld_reg_to_type[i][0], value);
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200194 }
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200195}
196
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200197/*
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500198 * build a AVI Info Frame
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200199 */
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500200void evergreen_update_avi_infoframe(struct radeon_device *rdev, u32 offset,
201 unsigned char *buffer, size_t size)
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200202{
Thierry Redinge3b2e032013-01-14 13:36:30 +0100203 uint8_t *frame = buffer + 3;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200204
205 WREG32(AFMT_AVI_INFO0 + offset,
206 frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
207 WREG32(AFMT_AVI_INFO1 + offset,
208 frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
209 WREG32(AFMT_AVI_INFO2 + offset,
210 frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
211 WREG32(AFMT_AVI_INFO3 + offset,
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500212 frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24));
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200213}
214
Slava Grigoreva85d6822014-12-05 13:38:31 -0500215void dce4_hdmi_audio_set_dto(struct radeon_device *rdev,
216 struct radeon_crtc *crtc, unsigned int clock)
Alex Deucherb1f6f472013-04-18 10:50:55 -0400217{
Slava Grigoreva85d6822014-12-05 13:38:31 -0500218 unsigned int max_ratio = clock / 24000;
Alex Deucher1518dd82013-07-30 17:31:07 -0400219 u32 dto_phase;
Alex Deucher1518dd82013-07-30 17:31:07 -0400220 u32 wallclock_ratio;
Slava Grigoreva85d6822014-12-05 13:38:31 -0500221 u32 value;
Alex Deucherb1f6f472013-04-18 10:50:55 -0400222
Slava Grigoreva85d6822014-12-05 13:38:31 -0500223 if (max_ratio >= 8) {
224 dto_phase = 192 * 1000;
225 wallclock_ratio = 3;
226 } else if (max_ratio >= 4) {
227 dto_phase = 96 * 1000;
228 wallclock_ratio = 2;
229 } else if (max_ratio >= 2) {
230 dto_phase = 48 * 1000;
231 wallclock_ratio = 1;
Alex Deucherb5306022013-07-31 16:51:33 -0400232 } else {
Slava Grigoreva85d6822014-12-05 13:38:31 -0500233 dto_phase = 24 * 1000;
234 wallclock_ratio = 0;
Alex Deucher1518dd82013-07-30 17:31:07 -0400235 }
Alex Deucher1518dd82013-07-30 17:31:07 -0400236
Slava Grigoreva85d6822014-12-05 13:38:31 -0500237 value = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK;
238 value |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio);
239 value &= ~DCCG_AUDIO_DTO1_USE_512FBR_DTO;
240 WREG32(DCCG_AUDIO_DTO0_CNTL, value);
241
242 /* Two dtos; generally use dto0 for HDMI */
243 value = 0;
244
245 if (crtc)
246 value |= DCCG_AUDIO_DTO0_SOURCE_SEL(crtc->crtc_id);
247
248 WREG32(DCCG_AUDIO_DTO_SOURCE, value);
249
Alex Deucherb1f6f472013-04-18 10:50:55 -0400250 /* Express [24MHz / target pixel clock] as an exact rational
251 * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
252 * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
253 */
Alex Deucher1518dd82013-07-30 17:31:07 -0400254 WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase);
Slava Grigoreva85d6822014-12-05 13:38:31 -0500255 WREG32(DCCG_AUDIO_DTO0_MODULE, clock);
Alex Deucherb1f6f472013-04-18 10:50:55 -0400256}
257
Slava Grigoreva85d6822014-12-05 13:38:31 -0500258void dce4_dp_audio_set_dto(struct radeon_device *rdev,
259 struct radeon_crtc *crtc, unsigned int clock)
260{
261 u32 value;
262
263 value = RREG32(DCCG_AUDIO_DTO1_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK;
264 value |= DCCG_AUDIO_DTO1_USE_512FBR_DTO;
265 WREG32(DCCG_AUDIO_DTO1_CNTL, value);
266
267 /* Two dtos; generally use dto1 for DP */
268 value = 0;
269 value |= DCCG_AUDIO_DTO_SEL;
270
271 if (crtc)
272 value |= DCCG_AUDIO_DTO0_SOURCE_SEL(crtc->crtc_id);
273
274 WREG32(DCCG_AUDIO_DTO_SOURCE, value);
275
276 /* Express [24MHz / target pixel clock] as an exact rational
277 * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
278 * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
279 */
280 WREG32(DCCG_AUDIO_DTO1_PHASE, 24000);
281 WREG32(DCCG_AUDIO_DTO1_MODULE, rdev->clock.max_pixel_clock * 10);
282}
Alex Deucherb1f6f472013-04-18 10:50:55 -0400283
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200284/*
285 * update the info frames with the data from the current display mode
286 */
287void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
288{
289 struct drm_device *dev = encoder->dev;
290 struct radeon_device *rdev = dev->dev_private;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200291 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
292 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Alex Deucher79766912014-05-28 19:02:31 -0400293 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
Thierry Redinge3b2e032013-01-14 13:36:30 +0100294 u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
295 struct hdmi_avi_infoframe frame;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200296 uint32_t offset;
Thierry Redinge3b2e032013-01-14 13:36:30 +0100297 ssize_t err;
Alex Deucher7b555e02014-05-28 19:14:36 -0400298 uint32_t val;
Alex Deucher79766912014-05-28 19:02:31 -0400299 int bpc = 8;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200300
Alex Deucherc2b4cacf2013-07-08 18:16:56 -0400301 if (!dig || !dig->afmt)
302 return;
303
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200304 /* Silent, r600_hdmi_enable will raise WARN for us */
305 if (!dig->afmt->enabled)
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200306 return;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200307 offset = dig->afmt->offset;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200308
Alex Deucher79766912014-05-28 19:02:31 -0400309 /* hdmi deep color mode general control packets setup, if bpc > 8 */
310 if (encoder->crtc) {
311 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
312 bpc = radeon_crtc->bpc;
313 }
314
Alex Deucher832eafa2014-02-18 11:07:55 -0500315 /* disable audio prior to setting up hw */
Slava Grigorev3cdde022014-12-02 15:22:43 -0500316 dig->afmt->pin = radeon_audio_get_pin(encoder);
Slava Grigorev8bf59822014-12-03 15:29:53 -0500317 radeon_audio_enable(rdev, dig->afmt->pin, 0);
Alex Deucher832eafa2014-02-18 11:07:55 -0500318
Slava Grigoreva85d6822014-12-05 13:38:31 -0500319 radeon_audio_set_dto(encoder, mode->clock);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200320
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200321 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
322 HDMI_NULL_SEND); /* send null packets when required */
323
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200324 WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200325
Alex Deucher7b555e02014-05-28 19:14:36 -0400326 val = RREG32(HDMI_CONTROL + offset);
327 val &= ~HDMI_DEEP_COLOR_ENABLE;
328 val &= ~HDMI_DEEP_COLOR_DEPTH_MASK;
329
330 switch (bpc) {
331 case 0:
332 case 6:
333 case 8:
334 case 16:
335 default:
336 DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300337 connector->name, bpc);
Alex Deucher7b555e02014-05-28 19:14:36 -0400338 break;
339 case 10:
340 val |= HDMI_DEEP_COLOR_ENABLE;
341 val |= HDMI_DEEP_COLOR_DEPTH(HDMI_30BIT_DEEP_COLOR);
342 DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300343 connector->name);
Alex Deucher7b555e02014-05-28 19:14:36 -0400344 break;
345 case 12:
346 val |= HDMI_DEEP_COLOR_ENABLE;
347 val |= HDMI_DEEP_COLOR_DEPTH(HDMI_36BIT_DEEP_COLOR);
348 DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300349 connector->name);
Alex Deucher7b555e02014-05-28 19:14:36 -0400350 break;
351 }
352
353 WREG32(HDMI_CONTROL + offset, val);
354
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200355 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
356 HDMI_NULL_SEND | /* send null packets when required */
357 HDMI_GC_SEND | /* send general control packets */
358 HDMI_GC_CONT); /* send general control packets every frame */
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200359
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200360 WREG32(HDMI_INFOFRAME_CONTROL0 + offset,
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200361 HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
362 HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */
363
364 WREG32(AFMT_INFOFRAME_CONTROL0 + offset,
365 AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */
366
367 WREG32(HDMI_INFOFRAME_CONTROL1 + offset,
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200368 HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */
369
370 WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200371
Rafał Miłecki91a44012013-04-18 09:26:08 -0400372 WREG32(HDMI_AUDIO_PACKET_CONTROL + offset,
373 HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */
374 HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
375
376 WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
377 AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
378
379 /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
380
Alex Deucher79766912014-05-28 19:02:31 -0400381 if (bpc > 8)
382 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
383 HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */
384 else
385 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
386 HDMI_ACR_SOURCE | /* select SW CTS value */
387 HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */
Rafał Miłecki91a44012013-04-18 09:26:08 -0400388
389 evergreen_hdmi_update_ACR(encoder, mode->clock);
390
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200391 WREG32(AFMT_60958_0 + offset,
392 AFMT_60958_CS_CHANNEL_NUMBER_L(1));
393
394 WREG32(AFMT_60958_1 + offset,
395 AFMT_60958_CS_CHANNEL_NUMBER_R(2));
396
397 WREG32(AFMT_60958_2 + offset,
398 AFMT_60958_CS_CHANNEL_NUMBER_2(3) |
399 AFMT_60958_CS_CHANNEL_NUMBER_3(4) |
400 AFMT_60958_CS_CHANNEL_NUMBER_4(5) |
401 AFMT_60958_CS_CHANNEL_NUMBER_5(6) |
402 AFMT_60958_CS_CHANNEL_NUMBER_6(7) |
403 AFMT_60958_CS_CHANNEL_NUMBER_7(8));
404
Slava Grigorev00a9d4b2014-12-01 18:02:57 -0500405 radeon_audio_write_speaker_allocation(encoder);
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200406
407 WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset,
408 AFMT_AUDIO_CHANNEL_ENABLE(0xff));
409
410 /* fglrx sets 0x40 in 0x5f80 here */
Alex Deucherb5306022013-07-31 16:51:33 -0400411
Slava Grigorev88252d72014-12-02 17:27:29 -0500412 radeon_audio_select_pin(encoder);
Alex Deucher070a2e62015-01-22 10:41:55 -0500413 radeon_audio_write_sad_regs(encoder);
Slava Grigorev87654f82014-12-02 11:20:48 -0500414 radeon_audio_write_latency_fields(encoder, mode);
Alex Deucher070a2e62015-01-22 10:41:55 -0500415
Thierry Redinge3b2e032013-01-14 13:36:30 +0100416 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
417 if (err < 0) {
418 DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
419 return;
420 }
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200421
Thierry Redinge3b2e032013-01-14 13:36:30 +0100422 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
423 if (err < 0) {
424 DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
425 return;
426 }
427
Slava Grigorev96ea7af2014-12-05 17:59:56 -0500428 radeon_update_avi_infoframe(encoder, buffer, sizeof(buffer));
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200429
Rafał Miłeckid3418ea2013-04-18 09:23:12 -0400430 WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset,
431 HDMI_AVI_INFO_SEND | /* enable AVI info frames */
432 HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */
433
434 WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset,
435 HDMI_AVI_INFO_LINE(2), /* anything other than 0 */
436 ~HDMI_AVI_INFO_LINE_MASK);
437
438 WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset,
439 AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */
440
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200441 /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
442 WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
443 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
444 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
445 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
Alex Deucher832eafa2014-02-18 11:07:55 -0500446
447 /* enable audio after to setting up hw */
Slava Grigorev8bf59822014-12-03 15:29:53 -0500448 radeon_audio_enable(rdev, dig->afmt->pin, 0xf);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200449}
Alex Deuchera973bea2013-04-18 11:32:16 -0400450
451void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
452{
Alex Deucher4adb34e2014-09-18 18:07:08 -0400453 struct drm_device *dev = encoder->dev;
454 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera973bea2013-04-18 11:32:16 -0400455 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
456 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
457
Alex Deucherc2b4cacf2013-07-08 18:16:56 -0400458 if (!dig || !dig->afmt)
459 return;
460
Alex Deuchera973bea2013-04-18 11:32:16 -0400461 /* Silent, r600_hdmi_enable will raise WARN for us */
462 if (enable && dig->afmt->enabled)
463 return;
464 if (!enable && !dig->afmt->enabled)
465 return;
466
Alex Deucher4adb34e2014-09-18 18:07:08 -0400467 if (!enable && dig->afmt->pin) {
Slava Grigorev8bf59822014-12-03 15:29:53 -0500468 radeon_audio_enable(rdev, dig->afmt->pin, 0);
Alex Deucher4adb34e2014-09-18 18:07:08 -0400469 dig->afmt->pin = NULL;
470 }
471
Alex Deuchera973bea2013-04-18 11:32:16 -0400472 dig->afmt->enabled = enable;
473
474 DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
475 enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id);
476}