blob: 1ec0e6e83f9f3492151d097c839251029996d6f6 [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"
32#include "evergreend.h"
33#include "atom.h"
34
Rafał Miłecki6159b652013-08-15 11:16:30 +020035extern void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder);
Alex Deucherb5306022013-07-31 16:51:33 -040036extern void dce6_afmt_write_sad_regs(struct drm_encoder *encoder);
37extern 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
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020041/*
42 * update the N and CTS parameters for a given pixel clock rate
43 */
44static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
45{
46 struct drm_device *dev = encoder->dev;
47 struct radeon_device *rdev = dev->dev_private;
48 struct radeon_hdmi_acr acr = r600_hdmi_acr(clock);
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +020049 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
50 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
51 uint32_t offset = dig->afmt->offset;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020052
53 WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz));
54 WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz);
55
56 WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz));
57 WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz);
58
59 WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz));
60 WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz);
61}
62
Alex Deucher712fd8a2013-10-10 17:54:51 -040063static void dce4_afmt_write_latency_fields(struct drm_encoder *encoder,
64 struct drm_display_mode *mode)
65{
66 struct radeon_device *rdev = encoder->dev->dev_private;
67 struct drm_connector *connector;
68 struct radeon_connector *radeon_connector = NULL;
69 u32 tmp = 0;
70
71 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
72 if (connector->encoder == encoder) {
73 radeon_connector = to_radeon_connector(connector);
74 break;
75 }
76 }
77
78 if (!radeon_connector) {
79 DRM_ERROR("Couldn't find encoder's connector\n");
80 return;
81 }
82
83 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
84 if (connector->latency_present[1])
85 tmp = VIDEO_LIPSYNC(connector->video_latency[1]) |
86 AUDIO_LIPSYNC(connector->audio_latency[1]);
87 else
88 tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255);
89 } else {
90 if (connector->latency_present[0])
91 tmp = VIDEO_LIPSYNC(connector->video_latency[0]) |
92 AUDIO_LIPSYNC(connector->audio_latency[0]);
93 else
94 tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255);
95 }
96 WREG32(AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp);
97}
98
Alex Deucherba7def42013-08-15 09:34:07 -040099static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
100{
101 struct radeon_device *rdev = encoder->dev->dev_private;
102 struct drm_connector *connector;
103 struct radeon_connector *radeon_connector = NULL;
104 u32 tmp;
105 u8 *sadb;
106 int sad_count;
107
108 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
Alex Deucher8a992ee2013-10-10 17:58:27 -0400109 if (connector->encoder == encoder) {
Alex Deucherba7def42013-08-15 09:34:07 -0400110 radeon_connector = to_radeon_connector(connector);
Alex Deucher8a992ee2013-10-10 17:58:27 -0400111 break;
112 }
Alex Deucherba7def42013-08-15 09:34:07 -0400113 }
114
115 if (!radeon_connector) {
116 DRM_ERROR("Couldn't find encoder's connector\n");
117 return;
118 }
119
120 sad_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb);
Alex Deucherb67ce392013-12-13 09:05:49 -0500121 if (sad_count <= 0) {
Alex Deucherba7def42013-08-15 09:34:07 -0400122 DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
123 return;
124 }
125
126 /* program the speaker allocation */
127 tmp = RREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
128 tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
129 /* set HDMI mode */
130 tmp |= HDMI_CONNECTION;
131 if (sad_count)
132 tmp |= SPEAKER_ALLOCATION(sadb[0]);
133 else
134 tmp |= SPEAKER_ALLOCATION(5); /* stereo */
135 WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
136
137 kfree(sadb);
138}
139
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200140static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder)
141{
142 struct radeon_device *rdev = encoder->dev->dev_private;
143 struct drm_connector *connector;
144 struct radeon_connector *radeon_connector = NULL;
145 struct cea_sad *sads;
146 int i, sad_count;
147
148 static const u16 eld_reg_to_type[][2] = {
149 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
150 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
151 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
152 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
153 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
154 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
155 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
156 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
157 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
158 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
159 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
160 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
161 };
162
163 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
Alex Deucher8a992ee2013-10-10 17:58:27 -0400164 if (connector->encoder == encoder) {
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200165 radeon_connector = to_radeon_connector(connector);
Alex Deucher8a992ee2013-10-10 17:58:27 -0400166 break;
167 }
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200168 }
169
170 if (!radeon_connector) {
171 DRM_ERROR("Couldn't find encoder's connector\n");
172 return;
173 }
174
175 sad_count = drm_edid_to_sad(radeon_connector->edid, &sads);
Alex Deucherb67ce392013-12-13 09:05:49 -0500176 if (sad_count <= 0) {
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200177 DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
178 return;
179 }
180 BUG_ON(!sads);
181
182 for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
183 u32 value = 0;
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200184 u8 stereo_freqs = 0;
185 int max_channels = -1;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200186 int j;
187
188 for (j = 0; j < sad_count; j++) {
189 struct cea_sad *sad = &sads[j];
190
191 if (sad->format == eld_reg_to_type[i][1]) {
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200192 if (sad->channels > max_channels) {
193 value = MAX_CHANNELS(sad->channels) |
194 DESCRIPTOR_BYTE_2(sad->byte2) |
195 SUPPORTED_FREQUENCIES(sad->freq);
196 max_channels = sad->channels;
197 }
198
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200199 if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200200 stereo_freqs |= sad->freq;
201 else
202 break;
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200203 }
204 }
Anssi Hannula0f57bca2013-10-29 01:19:16 +0200205
206 value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs);
207
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200208 WREG32(eld_reg_to_type[i][0], value);
209 }
210
211 kfree(sads);
212}
213
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200214/*
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200215 * build a HDMI Video Info Frame
216 */
Thierry Redinge3b2e032013-01-14 13:36:30 +0100217static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder,
218 void *buffer, size_t size)
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200219{
220 struct drm_device *dev = encoder->dev;
221 struct radeon_device *rdev = dev->dev_private;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200222 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
223 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
224 uint32_t offset = dig->afmt->offset;
Thierry Redinge3b2e032013-01-14 13:36:30 +0100225 uint8_t *frame = buffer + 3;
Alex Deucherf1003802013-06-07 10:41:03 -0400226 uint8_t *header = buffer;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200227
228 WREG32(AFMT_AVI_INFO0 + offset,
229 frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
230 WREG32(AFMT_AVI_INFO1 + offset,
231 frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
232 WREG32(AFMT_AVI_INFO2 + offset,
233 frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
234 WREG32(AFMT_AVI_INFO3 + offset,
Alex Deucherf1003802013-06-07 10:41:03 -0400235 frame[0xC] | (frame[0xD] << 8) | (header[1] << 24));
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200236}
237
Alex Deucherb1f6f472013-04-18 10:50:55 -0400238static void evergreen_audio_set_dto(struct drm_encoder *encoder, u32 clock)
239{
240 struct drm_device *dev = encoder->dev;
241 struct radeon_device *rdev = dev->dev_private;
242 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
243 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
244 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
Alex Deucher731da212013-05-13 11:35:26 -0400245 u32 base_rate = 24000;
Alex Deucher1518dd82013-07-30 17:31:07 -0400246 u32 max_ratio = clock / base_rate;
247 u32 dto_phase;
248 u32 dto_modulo = clock;
249 u32 wallclock_ratio;
250 u32 dto_cntl;
Alex Deucherb1f6f472013-04-18 10:50:55 -0400251
252 if (!dig || !dig->afmt)
253 return;
254
Alex Deucherb5306022013-07-31 16:51:33 -0400255 if (ASIC_IS_DCE6(rdev)) {
Alex Deucher1518dd82013-07-30 17:31:07 -0400256 dto_phase = 24 * 1000;
Alex Deucherb5306022013-07-31 16:51:33 -0400257 } else {
258 if (max_ratio >= 8) {
259 dto_phase = 192 * 1000;
260 wallclock_ratio = 3;
261 } else if (max_ratio >= 4) {
262 dto_phase = 96 * 1000;
263 wallclock_ratio = 2;
264 } else if (max_ratio >= 2) {
265 dto_phase = 48 * 1000;
266 wallclock_ratio = 1;
267 } else {
268 dto_phase = 24 * 1000;
269 wallclock_ratio = 0;
270 }
271 dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK;
272 dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio);
273 WREG32(DCCG_AUDIO_DTO0_CNTL, dto_cntl);
Alex Deucher1518dd82013-07-30 17:31:07 -0400274 }
Alex Deucher1518dd82013-07-30 17:31:07 -0400275
Alex Deucherb1f6f472013-04-18 10:50:55 -0400276 /* XXX two dtos; generally use dto0 for hdmi */
277 /* Express [24MHz / target pixel clock] as an exact rational
278 * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
279 * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
280 */
Alex Deucher7d61d832013-07-26 13:26:05 -0400281 WREG32(DCCG_AUDIO_DTO_SOURCE, DCCG_AUDIO_DTO0_SOURCE_SEL(radeon_crtc->crtc_id));
Alex Deucher1518dd82013-07-30 17:31:07 -0400282 WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase);
283 WREG32(DCCG_AUDIO_DTO0_MODULE, dto_modulo);
Alex Deucherb1f6f472013-04-18 10:50:55 -0400284}
285
286
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200287/*
288 * update the info frames with the data from the current display mode
289 */
290void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
291{
292 struct drm_device *dev = encoder->dev;
293 struct radeon_device *rdev = dev->dev_private;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200294 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
295 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Alex Deucher79766912014-05-28 19:02:31 -0400296 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
Thierry Redinge3b2e032013-01-14 13:36:30 +0100297 u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
298 struct hdmi_avi_infoframe frame;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200299 uint32_t offset;
Thierry Redinge3b2e032013-01-14 13:36:30 +0100300 ssize_t err;
Alex Deucher7b555e02014-05-28 19:14:36 -0400301 uint32_t val;
Alex Deucher79766912014-05-28 19:02:31 -0400302 int bpc = 8;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200303
Alex Deucherc2b4cac2013-07-08 18:16:56 -0400304 if (!dig || !dig->afmt)
305 return;
306
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200307 /* Silent, r600_hdmi_enable will raise WARN for us */
308 if (!dig->afmt->enabled)
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200309 return;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200310 offset = dig->afmt->offset;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200311
Alex Deucher79766912014-05-28 19:02:31 -0400312 /* hdmi deep color mode general control packets setup, if bpc > 8 */
313 if (encoder->crtc) {
314 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
315 bpc = radeon_crtc->bpc;
316 }
317
Alex Deucher832eafa2014-02-18 11:07:55 -0500318 /* disable audio prior to setting up hw */
319 if (ASIC_IS_DCE6(rdev)) {
320 dig->afmt->pin = dce6_audio_get_pin(rdev);
321 dce6_audio_enable(rdev, dig->afmt->pin, false);
322 } else {
323 dig->afmt->pin = r600_audio_get_pin(rdev);
324 r600_audio_enable(rdev, dig->afmt->pin, false);
325 }
326
Alex Deucherb1f6f472013-04-18 10:50:55 -0400327 evergreen_audio_set_dto(encoder, mode->clock);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200328
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200329 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
330 HDMI_NULL_SEND); /* send null packets when required */
331
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200332 WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200333
Alex Deucher7b555e02014-05-28 19:14:36 -0400334 val = RREG32(HDMI_CONTROL + offset);
335 val &= ~HDMI_DEEP_COLOR_ENABLE;
336 val &= ~HDMI_DEEP_COLOR_DEPTH_MASK;
337
338 switch (bpc) {
339 case 0:
340 case 6:
341 case 8:
342 case 16:
343 default:
344 DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300345 connector->name, bpc);
Alex Deucher7b555e02014-05-28 19:14:36 -0400346 break;
347 case 10:
348 val |= HDMI_DEEP_COLOR_ENABLE;
349 val |= HDMI_DEEP_COLOR_DEPTH(HDMI_30BIT_DEEP_COLOR);
350 DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300351 connector->name);
Alex Deucher7b555e02014-05-28 19:14:36 -0400352 break;
353 case 12:
354 val |= HDMI_DEEP_COLOR_ENABLE;
355 val |= HDMI_DEEP_COLOR_DEPTH(HDMI_36BIT_DEEP_COLOR);
356 DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n",
Jani Nikula72082092014-06-03 14:56:19 +0300357 connector->name);
Alex Deucher7b555e02014-05-28 19:14:36 -0400358 break;
359 }
360
361 WREG32(HDMI_CONTROL + offset, val);
362
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200363 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
364 HDMI_NULL_SEND | /* send null packets when required */
365 HDMI_GC_SEND | /* send general control packets */
366 HDMI_GC_CONT); /* send general control packets every frame */
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200367
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200368 WREG32(HDMI_INFOFRAME_CONTROL0 + offset,
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200369 HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
370 HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */
371
372 WREG32(AFMT_INFOFRAME_CONTROL0 + offset,
373 AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */
374
375 WREG32(HDMI_INFOFRAME_CONTROL1 + offset,
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200376 HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */
377
378 WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200379
Rafał Miłecki91a44012013-04-18 09:26:08 -0400380 WREG32(HDMI_AUDIO_PACKET_CONTROL + offset,
381 HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */
382 HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
383
384 WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
385 AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
386
387 /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
388
Alex Deucher79766912014-05-28 19:02:31 -0400389 if (bpc > 8)
390 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
391 HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */
392 else
393 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
394 HDMI_ACR_SOURCE | /* select SW CTS value */
395 HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */
Rafał Miłecki91a44012013-04-18 09:26:08 -0400396
397 evergreen_hdmi_update_ACR(encoder, mode->clock);
398
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200399 WREG32(AFMT_60958_0 + offset,
400 AFMT_60958_CS_CHANNEL_NUMBER_L(1));
401
402 WREG32(AFMT_60958_1 + offset,
403 AFMT_60958_CS_CHANNEL_NUMBER_R(2));
404
405 WREG32(AFMT_60958_2 + offset,
406 AFMT_60958_CS_CHANNEL_NUMBER_2(3) |
407 AFMT_60958_CS_CHANNEL_NUMBER_3(4) |
408 AFMT_60958_CS_CHANNEL_NUMBER_4(5) |
409 AFMT_60958_CS_CHANNEL_NUMBER_5(6) |
410 AFMT_60958_CS_CHANNEL_NUMBER_6(7) |
411 AFMT_60958_CS_CHANNEL_NUMBER_7(8));
412
Rafał Miłecki6159b652013-08-15 11:16:30 +0200413 if (ASIC_IS_DCE6(rdev)) {
414 dce6_afmt_write_speaker_allocation(encoder);
415 } else {
Alex Deucherba7def42013-08-15 09:34:07 -0400416 dce4_afmt_write_speaker_allocation(encoder);
Rafał Miłecki6159b652013-08-15 11:16:30 +0200417 }
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200418
419 WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset,
420 AFMT_AUDIO_CHANNEL_ENABLE(0xff));
421
422 /* fglrx sets 0x40 in 0x5f80 here */
Alex Deucherb5306022013-07-31 16:51:33 -0400423
424 if (ASIC_IS_DCE6(rdev)) {
425 dce6_afmt_select_pin(encoder);
426 dce6_afmt_write_sad_regs(encoder);
Alex Deucherb1880252013-10-10 18:03:06 -0400427 dce6_afmt_write_latency_fields(encoder, mode);
Alex Deucherb5306022013-07-31 16:51:33 -0400428 } else {
429 evergreen_hdmi_write_sad_regs(encoder);
Alex Deucher712fd8a2013-10-10 17:54:51 -0400430 dce4_afmt_write_latency_fields(encoder, mode);
Alex Deucherb5306022013-07-31 16:51:33 -0400431 }
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200432
Thierry Redinge3b2e032013-01-14 13:36:30 +0100433 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
434 if (err < 0) {
435 DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
436 return;
437 }
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200438
Thierry Redinge3b2e032013-01-14 13:36:30 +0100439 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
440 if (err < 0) {
441 DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
442 return;
443 }
444
445 evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer));
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200446
Rafał Miłeckid3418ea2013-04-18 09:23:12 -0400447 WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset,
448 HDMI_AVI_INFO_SEND | /* enable AVI info frames */
449 HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */
450
451 WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset,
452 HDMI_AVI_INFO_LINE(2), /* anything other than 0 */
453 ~HDMI_AVI_INFO_LINE_MASK);
454
455 WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset,
456 AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */
457
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200458 /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
459 WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
460 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
461 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
462 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
Alex Deucher832eafa2014-02-18 11:07:55 -0500463
464 /* enable audio after to setting up hw */
465 if (ASIC_IS_DCE6(rdev))
466 dce6_audio_enable(rdev, dig->afmt->pin, true);
467 else
468 r600_audio_enable(rdev, dig->afmt->pin, true);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200469}
Alex Deuchera973bea2013-04-18 11:32:16 -0400470
471void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
472{
473 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
474 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
475
Alex Deucherc2b4cac2013-07-08 18:16:56 -0400476 if (!dig || !dig->afmt)
477 return;
478
Alex Deuchera973bea2013-04-18 11:32:16 -0400479 /* Silent, r600_hdmi_enable will raise WARN for us */
480 if (enable && dig->afmt->enabled)
481 return;
482 if (!enable && !dig->afmt->enabled)
483 return;
484
485 dig->afmt->enabled = enable;
486
487 DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
488 enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id);
489}