blob: 2603f72234a178835815befc44118daabbe0e23b [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
Rafał Miłecki6159b652013-08-15 11:16:30 +020036extern void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder);
Alex Deucherb5306022013-07-31 16:51:33 -040037extern void dce6_afmt_select_pin(struct drm_encoder *encoder);
Alex Deucherb1880252013-10-10 18:03:06 -040038extern void dce6_afmt_write_latency_fields(struct drm_encoder *encoder,
39 struct drm_display_mode *mode);
Alex Deucherb5306022013-07-31 16:51:33 -040040
Alex Deucherd3d8c142014-09-18 17:26:39 -040041/* enable the audio stream */
42static void dce4_audio_enable(struct radeon_device *rdev,
43 struct r600_audio_pin *pin,
44 u8 enable_mask)
45{
46 u32 tmp = RREG32(AZ_HOT_PLUG_CONTROL);
47
48 if (!pin)
49 return;
50
51 if (enable_mask) {
52 tmp |= AUDIO_ENABLED;
53 if (enable_mask & 1)
54 tmp |= PIN0_AUDIO_ENABLED;
55 if (enable_mask & 2)
56 tmp |= PIN1_AUDIO_ENABLED;
57 if (enable_mask & 4)
58 tmp |= PIN2_AUDIO_ENABLED;
59 if (enable_mask & 8)
60 tmp |= PIN3_AUDIO_ENABLED;
61 } else {
62 tmp &= ~(AUDIO_ENABLED |
63 PIN0_AUDIO_ENABLED |
64 PIN1_AUDIO_ENABLED |
65 PIN2_AUDIO_ENABLED |
66 PIN3_AUDIO_ENABLED);
67 }
68
69 WREG32(AZ_HOT_PLUG_CONTROL, tmp);
70}
71
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020072/*
73 * update the N and CTS parameters for a given pixel clock rate
74 */
75static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
76{
77 struct drm_device *dev = encoder->dev;
78 struct radeon_device *rdev = dev->dev_private;
79 struct radeon_hdmi_acr acr = r600_hdmi_acr(clock);
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +020080 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
81 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
82 uint32_t offset = dig->afmt->offset;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020083
84 WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz));
85 WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz);
86
87 WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz));
88 WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz);
89
90 WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz));
91 WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz);
92}
93
Alex Deucher712fd8a2013-10-10 17:54:51 -040094static void dce4_afmt_write_latency_fields(struct drm_encoder *encoder,
95 struct drm_display_mode *mode)
96{
97 struct radeon_device *rdev = encoder->dev->dev_private;
98 struct drm_connector *connector;
99 struct radeon_connector *radeon_connector = NULL;
100 u32 tmp = 0;
101
102 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
103 if (connector->encoder == encoder) {
104 radeon_connector = to_radeon_connector(connector);
105 break;
106 }
107 }
108
109 if (!radeon_connector) {
110 DRM_ERROR("Couldn't find encoder's connector\n");
111 return;
112 }
113
114 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
115 if (connector->latency_present[1])
116 tmp = VIDEO_LIPSYNC(connector->video_latency[1]) |
117 AUDIO_LIPSYNC(connector->audio_latency[1]);
118 else
119 tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255);
120 } else {
121 if (connector->latency_present[0])
122 tmp = VIDEO_LIPSYNC(connector->video_latency[0]) |
123 AUDIO_LIPSYNC(connector->audio_latency[0]);
124 else
125 tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255);
126 }
127 WREG32(AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp);
128}
129
Alex Deucherba7def42013-08-15 09:34:07 -0400130static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
131{
132 struct radeon_device *rdev = encoder->dev->dev_private;
133 struct drm_connector *connector;
134 struct radeon_connector *radeon_connector = NULL;
135 u32 tmp;
Alex Deucher83d04c32014-10-13 13:23:48 -0400136 u8 *sadb = NULL;
Alex Deucherba7def42013-08-15 09:34:07 -0400137 int sad_count;
138
139 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
Alex Deucher8a992ee2013-10-10 17:58:27 -0400140 if (connector->encoder == encoder) {
Alex Deucherba7def42013-08-15 09:34:07 -0400141 radeon_connector = to_radeon_connector(connector);
Alex Deucher8a992ee2013-10-10 17:58:27 -0400142 break;
143 }
Alex Deucherba7def42013-08-15 09:34:07 -0400144 }
145
146 if (!radeon_connector) {
147 DRM_ERROR("Couldn't find encoder's connector\n");
148 return;
149 }
150
Alex Deucher377bd8a2014-07-15 11:00:47 -0400151 sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), &sadb);
Alex Deucher49104032014-10-13 11:51:50 -0400152 if (sad_count < 0) {
153 DRM_DEBUG("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
154 sad_count = 0;
Alex Deucherba7def42013-08-15 09:34:07 -0400155 }
156
157 /* program the speaker allocation */
158 tmp = RREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
159 tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
160 /* set HDMI mode */
161 tmp |= HDMI_CONNECTION;
162 if (sad_count)
163 tmp |= SPEAKER_ALLOCATION(sadb[0]);
164 else
165 tmp |= SPEAKER_ALLOCATION(5); /* stereo */
166 WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
167
168 kfree(sadb);
169}
170
Alex Deucher070a2e62015-01-22 10:41:55 -0500171void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder,
172 struct cea_sad *sads, int sad_count)
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200173{
Alex Deucher070a2e62015-01-22 10:41:55 -0500174 int i;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200175 struct radeon_device *rdev = encoder->dev->dev_private;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200176 static const u16 eld_reg_to_type[][2] = {
177 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
178 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
179 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
180 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
181 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
182 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
183 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
184 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
185 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
186 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
187 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
188 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
189 };
190
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200191 for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
192 u32 value = 0;
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200193 u8 stereo_freqs = 0;
194 int max_channels = -1;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200195 int j;
196
197 for (j = 0; j < sad_count; j++) {
198 struct cea_sad *sad = &sads[j];
199
200 if (sad->format == eld_reg_to_type[i][1]) {
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200201 if (sad->channels > max_channels) {
202 value = MAX_CHANNELS(sad->channels) |
203 DESCRIPTOR_BYTE_2(sad->byte2) |
204 SUPPORTED_FREQUENCIES(sad->freq);
205 max_channels = sad->channels;
206 }
207
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200208 if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200209 stereo_freqs |= sad->freq;
210 else
211 break;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200212 }
213 }
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200214
215 value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs);
216
Alex Deucher070a2e62015-01-22 10:41:55 -0500217 WREG32_ENDPOINT(0, eld_reg_to_type[i][0], value);
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200218 }
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200219}
220
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200221/*
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200222 * build a HDMI Video Info Frame
223 */
Thierry Redinge3b2e032013-01-14 13:36:30 +0100224static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder,
225 void *buffer, size_t size)
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200226{
227 struct drm_device *dev = encoder->dev;
228 struct radeon_device *rdev = dev->dev_private;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200229 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
230 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
231 uint32_t offset = dig->afmt->offset;
Thierry Redinge3b2e032013-01-14 13:36:30 +0100232 uint8_t *frame = buffer + 3;
Alex Deucherf1003802013-06-07 10:41:03 -0400233 uint8_t *header = buffer;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200234
235 WREG32(AFMT_AVI_INFO0 + offset,
236 frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
237 WREG32(AFMT_AVI_INFO1 + offset,
238 frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
239 WREG32(AFMT_AVI_INFO2 + offset,
240 frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
241 WREG32(AFMT_AVI_INFO3 + offset,
Alex Deucherf1003802013-06-07 10:41:03 -0400242 frame[0xC] | (frame[0xD] << 8) | (header[1] << 24));
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200243}
244
Alex Deucherb1f6f472013-04-18 10:50:55 -0400245static void evergreen_audio_set_dto(struct drm_encoder *encoder, u32 clock)
246{
247 struct drm_device *dev = encoder->dev;
248 struct radeon_device *rdev = dev->dev_private;
249 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
250 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
251 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
Alex Deucher731da212013-05-13 11:35:26 -0400252 u32 base_rate = 24000;
Alex Deucher1518dd82013-07-30 17:31:07 -0400253 u32 max_ratio = clock / base_rate;
254 u32 dto_phase;
255 u32 dto_modulo = clock;
256 u32 wallclock_ratio;
257 u32 dto_cntl;
Alex Deucherb1f6f472013-04-18 10:50:55 -0400258
259 if (!dig || !dig->afmt)
260 return;
261
Alex Deucherb5306022013-07-31 16:51:33 -0400262 if (ASIC_IS_DCE6(rdev)) {
Alex Deucher1518dd82013-07-30 17:31:07 -0400263 dto_phase = 24 * 1000;
Alex Deucherb5306022013-07-31 16:51:33 -0400264 } else {
265 if (max_ratio >= 8) {
266 dto_phase = 192 * 1000;
267 wallclock_ratio = 3;
268 } else if (max_ratio >= 4) {
269 dto_phase = 96 * 1000;
270 wallclock_ratio = 2;
271 } else if (max_ratio >= 2) {
272 dto_phase = 48 * 1000;
273 wallclock_ratio = 1;
274 } else {
275 dto_phase = 24 * 1000;
276 wallclock_ratio = 0;
277 }
278 dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK;
279 dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio);
280 WREG32(DCCG_AUDIO_DTO0_CNTL, dto_cntl);
Alex Deucher1518dd82013-07-30 17:31:07 -0400281 }
Alex Deucher1518dd82013-07-30 17:31:07 -0400282
Alex Deucherb1f6f472013-04-18 10:50:55 -0400283 /* XXX two dtos; generally use dto0 for hdmi */
284 /* Express [24MHz / target pixel clock] as an exact rational
285 * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
286 * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
287 */
Alex Deucher7d61d832013-07-26 13:26:05 -0400288 WREG32(DCCG_AUDIO_DTO_SOURCE, DCCG_AUDIO_DTO0_SOURCE_SEL(radeon_crtc->crtc_id));
Alex Deucher1518dd82013-07-30 17:31:07 -0400289 WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase);
290 WREG32(DCCG_AUDIO_DTO0_MODULE, dto_modulo);
Alex Deucherb1f6f472013-04-18 10:50:55 -0400291}
292
293
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200294/*
295 * update the info frames with the data from the current display mode
296 */
297void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
298{
299 struct drm_device *dev = encoder->dev;
300 struct radeon_device *rdev = dev->dev_private;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200301 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
302 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Alex Deucher79766912014-05-28 19:02:31 -0400303 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
Thierry Redinge3b2e032013-01-14 13:36:30 +0100304 u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
305 struct hdmi_avi_infoframe frame;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200306 uint32_t offset;
Thierry Redinge3b2e032013-01-14 13:36:30 +0100307 ssize_t err;
Alex Deucher7b555e02014-05-28 19:14:36 -0400308 uint32_t val;
Alex Deucher79766912014-05-28 19:02:31 -0400309 int bpc = 8;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200310
Alex Deucherc2b4cacf2013-07-08 18:16:56 -0400311 if (!dig || !dig->afmt)
312 return;
313
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200314 /* Silent, r600_hdmi_enable will raise WARN for us */
315 if (!dig->afmt->enabled)
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200316 return;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200317 offset = dig->afmt->offset;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200318
Alex Deucher79766912014-05-28 19:02:31 -0400319 /* hdmi deep color mode general control packets setup, if bpc > 8 */
320 if (encoder->crtc) {
321 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
322 bpc = radeon_crtc->bpc;
323 }
324
Alex Deucher832eafa2014-02-18 11:07:55 -0500325 /* disable audio prior to setting up hw */
326 if (ASIC_IS_DCE6(rdev)) {
327 dig->afmt->pin = dce6_audio_get_pin(rdev);
Alex Deucherd3d8c142014-09-18 17:26:39 -0400328 dce6_audio_enable(rdev, dig->afmt->pin, 0);
Alex Deucher832eafa2014-02-18 11:07:55 -0500329 } else {
330 dig->afmt->pin = r600_audio_get_pin(rdev);
Alex Deucherd3d8c142014-09-18 17:26:39 -0400331 dce4_audio_enable(rdev, dig->afmt->pin, 0);
Alex Deucher832eafa2014-02-18 11:07:55 -0500332 }
333
Alex Deucherb1f6f472013-04-18 10:50:55 -0400334 evergreen_audio_set_dto(encoder, mode->clock);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200335
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200336 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
337 HDMI_NULL_SEND); /* send null packets when required */
338
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200339 WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200340
Alex Deucher7b555e02014-05-28 19:14:36 -0400341 val = RREG32(HDMI_CONTROL + offset);
342 val &= ~HDMI_DEEP_COLOR_ENABLE;
343 val &= ~HDMI_DEEP_COLOR_DEPTH_MASK;
344
345 switch (bpc) {
346 case 0:
347 case 6:
348 case 8:
349 case 16:
350 default:
351 DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300352 connector->name, bpc);
Alex Deucher7b555e02014-05-28 19:14:36 -0400353 break;
354 case 10:
355 val |= HDMI_DEEP_COLOR_ENABLE;
356 val |= HDMI_DEEP_COLOR_DEPTH(HDMI_30BIT_DEEP_COLOR);
357 DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300358 connector->name);
Alex Deucher7b555e02014-05-28 19:14:36 -0400359 break;
360 case 12:
361 val |= HDMI_DEEP_COLOR_ENABLE;
362 val |= HDMI_DEEP_COLOR_DEPTH(HDMI_36BIT_DEEP_COLOR);
363 DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300364 connector->name);
Alex Deucher7b555e02014-05-28 19:14:36 -0400365 break;
366 }
367
368 WREG32(HDMI_CONTROL + offset, val);
369
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200370 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
371 HDMI_NULL_SEND | /* send null packets when required */
372 HDMI_GC_SEND | /* send general control packets */
373 HDMI_GC_CONT); /* send general control packets every frame */
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200374
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200375 WREG32(HDMI_INFOFRAME_CONTROL0 + offset,
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200376 HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
377 HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */
378
379 WREG32(AFMT_INFOFRAME_CONTROL0 + offset,
380 AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */
381
382 WREG32(HDMI_INFOFRAME_CONTROL1 + offset,
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200383 HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */
384
385 WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200386
Rafał Miłecki91a44012013-04-18 09:26:08 -0400387 WREG32(HDMI_AUDIO_PACKET_CONTROL + offset,
388 HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */
389 HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
390
391 WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
392 AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
393
394 /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
395
Alex Deucher79766912014-05-28 19:02:31 -0400396 if (bpc > 8)
397 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
398 HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */
399 else
400 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
401 HDMI_ACR_SOURCE | /* select SW CTS value */
402 HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */
Rafał Miłecki91a44012013-04-18 09:26:08 -0400403
404 evergreen_hdmi_update_ACR(encoder, mode->clock);
405
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200406 WREG32(AFMT_60958_0 + offset,
407 AFMT_60958_CS_CHANNEL_NUMBER_L(1));
408
409 WREG32(AFMT_60958_1 + offset,
410 AFMT_60958_CS_CHANNEL_NUMBER_R(2));
411
412 WREG32(AFMT_60958_2 + offset,
413 AFMT_60958_CS_CHANNEL_NUMBER_2(3) |
414 AFMT_60958_CS_CHANNEL_NUMBER_3(4) |
415 AFMT_60958_CS_CHANNEL_NUMBER_4(5) |
416 AFMT_60958_CS_CHANNEL_NUMBER_5(6) |
417 AFMT_60958_CS_CHANNEL_NUMBER_6(7) |
418 AFMT_60958_CS_CHANNEL_NUMBER_7(8));
419
Rafał Miłecki6159b652013-08-15 11:16:30 +0200420 if (ASIC_IS_DCE6(rdev)) {
421 dce6_afmt_write_speaker_allocation(encoder);
422 } else {
Alex Deucherba7def42013-08-15 09:34:07 -0400423 dce4_afmt_write_speaker_allocation(encoder);
Rafał Miłecki6159b652013-08-15 11:16:30 +0200424 }
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200425
426 WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset,
427 AFMT_AUDIO_CHANNEL_ENABLE(0xff));
428
429 /* fglrx sets 0x40 in 0x5f80 here */
Alex Deucherb5306022013-07-31 16:51:33 -0400430
431 if (ASIC_IS_DCE6(rdev)) {
432 dce6_afmt_select_pin(encoder);
Alex Deucherb1880252013-10-10 18:03:06 -0400433 dce6_afmt_write_latency_fields(encoder, mode);
Alex Deucherb5306022013-07-31 16:51:33 -0400434 } else {
Alex Deucher712fd8a2013-10-10 17:54:51 -0400435 dce4_afmt_write_latency_fields(encoder, mode);
Alex Deucherb5306022013-07-31 16:51:33 -0400436 }
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200437
Alex Deucher070a2e62015-01-22 10:41:55 -0500438 radeon_audio_write_sad_regs(encoder);
439
Thierry Redinge3b2e032013-01-14 13:36:30 +0100440 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
441 if (err < 0) {
442 DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
443 return;
444 }
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200445
Thierry Redinge3b2e032013-01-14 13:36:30 +0100446 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
447 if (err < 0) {
448 DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
449 return;
450 }
451
452 evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer));
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200453
Rafał Miłeckid3418ea2013-04-18 09:23:12 -0400454 WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset,
455 HDMI_AVI_INFO_SEND | /* enable AVI info frames */
456 HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */
457
458 WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset,
459 HDMI_AVI_INFO_LINE(2), /* anything other than 0 */
460 ~HDMI_AVI_INFO_LINE_MASK);
461
462 WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset,
463 AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */
464
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200465 /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
466 WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
467 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
468 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
469 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
Alex Deucher832eafa2014-02-18 11:07:55 -0500470
471 /* enable audio after to setting up hw */
472 if (ASIC_IS_DCE6(rdev))
Alex Deucherd3d8c142014-09-18 17:26:39 -0400473 dce6_audio_enable(rdev, dig->afmt->pin, 1);
Alex Deucher832eafa2014-02-18 11:07:55 -0500474 else
Alex Deucherd3d8c142014-09-18 17:26:39 -0400475 dce4_audio_enable(rdev, dig->afmt->pin, 0xf);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200476}
Alex Deuchera973bea2013-04-18 11:32:16 -0400477
478void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
479{
Alex Deucher4adb34e2014-09-18 18:07:08 -0400480 struct drm_device *dev = encoder->dev;
481 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera973bea2013-04-18 11:32:16 -0400482 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
483 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
484
Alex Deucherc2b4cacf2013-07-08 18:16:56 -0400485 if (!dig || !dig->afmt)
486 return;
487
Alex Deuchera973bea2013-04-18 11:32:16 -0400488 /* Silent, r600_hdmi_enable will raise WARN for us */
489 if (enable && dig->afmt->enabled)
490 return;
491 if (!enable && !dig->afmt->enabled)
492 return;
493
Alex Deucher4adb34e2014-09-18 18:07:08 -0400494 if (!enable && dig->afmt->pin) {
495 if (ASIC_IS_DCE6(rdev))
496 dce6_audio_enable(rdev, dig->afmt->pin, 0);
497 else
498 dce4_audio_enable(rdev, dig->afmt->pin, 0);
499 dig->afmt->pin = NULL;
500 }
501
Alex Deuchera973bea2013-04-18 11:32:16 -0400502 dig->afmt->enabled = enable;
503
504 DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
505 enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id);
506}