blob: abdc893318a4e256531d19beba585000f9260e06 [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);
38
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020039/*
40 * update the N and CTS parameters for a given pixel clock rate
41 */
42static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
43{
44 struct drm_device *dev = encoder->dev;
45 struct radeon_device *rdev = dev->dev_private;
46 struct radeon_hdmi_acr acr = r600_hdmi_acr(clock);
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +020047 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
48 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
49 uint32_t offset = dig->afmt->offset;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +020050
51 WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz));
52 WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz);
53
54 WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz));
55 WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz);
56
57 WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz));
58 WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz);
59}
60
Alex Deucher712fd8a2013-10-10 17:54:51 -040061static void dce4_afmt_write_latency_fields(struct drm_encoder *encoder,
62 struct drm_display_mode *mode)
63{
64 struct radeon_device *rdev = encoder->dev->dev_private;
65 struct drm_connector *connector;
66 struct radeon_connector *radeon_connector = NULL;
67 u32 tmp = 0;
68
69 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
70 if (connector->encoder == encoder) {
71 radeon_connector = to_radeon_connector(connector);
72 break;
73 }
74 }
75
76 if (!radeon_connector) {
77 DRM_ERROR("Couldn't find encoder's connector\n");
78 return;
79 }
80
81 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
82 if (connector->latency_present[1])
83 tmp = VIDEO_LIPSYNC(connector->video_latency[1]) |
84 AUDIO_LIPSYNC(connector->audio_latency[1]);
85 else
86 tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255);
87 } else {
88 if (connector->latency_present[0])
89 tmp = VIDEO_LIPSYNC(connector->video_latency[0]) |
90 AUDIO_LIPSYNC(connector->audio_latency[0]);
91 else
92 tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255);
93 }
94 WREG32(AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp);
95}
96
Alex Deucherba7def42013-08-15 09:34:07 -040097static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
98{
99 struct radeon_device *rdev = encoder->dev->dev_private;
100 struct drm_connector *connector;
101 struct radeon_connector *radeon_connector = NULL;
102 u32 tmp;
103 u8 *sadb;
104 int sad_count;
105
106 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
Alex Deucher8a992ee2013-10-10 17:58:27 -0400107 if (connector->encoder == encoder) {
Alex Deucherba7def42013-08-15 09:34:07 -0400108 radeon_connector = to_radeon_connector(connector);
Alex Deucher8a992ee2013-10-10 17:58:27 -0400109 break;
110 }
Alex Deucherba7def42013-08-15 09:34:07 -0400111 }
112
113 if (!radeon_connector) {
114 DRM_ERROR("Couldn't find encoder's connector\n");
115 return;
116 }
117
118 sad_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb);
119 if (sad_count < 0) {
120 DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count);
121 return;
122 }
123
124 /* program the speaker allocation */
125 tmp = RREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
126 tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
127 /* set HDMI mode */
128 tmp |= HDMI_CONNECTION;
129 if (sad_count)
130 tmp |= SPEAKER_ALLOCATION(sadb[0]);
131 else
132 tmp |= SPEAKER_ALLOCATION(5); /* stereo */
133 WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
134
135 kfree(sadb);
136}
137
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200138static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder)
139{
140 struct radeon_device *rdev = encoder->dev->dev_private;
141 struct drm_connector *connector;
142 struct radeon_connector *radeon_connector = NULL;
143 struct cea_sad *sads;
144 int i, sad_count;
145
146 static const u16 eld_reg_to_type[][2] = {
147 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
148 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
149 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
150 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
151 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
152 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
153 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
154 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
155 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
156 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
157 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
158 { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
159 };
160
161 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
Alex Deucher8a992ee2013-10-10 17:58:27 -0400162 if (connector->encoder == encoder) {
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200163 radeon_connector = to_radeon_connector(connector);
Alex Deucher8a992ee2013-10-10 17:58:27 -0400164 break;
165 }
Rafał Miłecki46892ca2013-04-19 19:01:26 +0200166 }
167
168 if (!radeon_connector) {
169 DRM_ERROR("Couldn't find encoder's connector\n");
170 return;
171 }
172
173 sad_count = drm_edid_to_sad(radeon_connector->edid, &sads);
174 if (sad_count < 0) {
175 DRM_ERROR("Couldn't read SADs: %d\n", sad_count);
176 return;
177 }
178 BUG_ON(!sads);
179
180 for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
181 u32 value = 0;
182 int j;
183
184 for (j = 0; j < sad_count; j++) {
185 struct cea_sad *sad = &sads[j];
186
187 if (sad->format == eld_reg_to_type[i][1]) {
188 value = MAX_CHANNELS(sad->channels) |
189 DESCRIPTOR_BYTE_2(sad->byte2) |
190 SUPPORTED_FREQUENCIES(sad->freq);
191 if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
192 value |= SUPPORTED_FREQUENCIES_STEREO(sad->freq);
193 break;
194 }
195 }
196 WREG32(eld_reg_to_type[i][0], value);
197 }
198
199 kfree(sads);
200}
201
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200202/*
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200203 * build a HDMI Video Info Frame
204 */
Thierry Redinge3b2e032013-01-14 13:36:30 +0100205static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder,
206 void *buffer, size_t size)
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200207{
208 struct drm_device *dev = encoder->dev;
209 struct radeon_device *rdev = dev->dev_private;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200210 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
211 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
212 uint32_t offset = dig->afmt->offset;
Thierry Redinge3b2e032013-01-14 13:36:30 +0100213 uint8_t *frame = buffer + 3;
Alex Deucherf1003802013-06-07 10:41:03 -0400214 uint8_t *header = buffer;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200215
216 WREG32(AFMT_AVI_INFO0 + offset,
217 frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
218 WREG32(AFMT_AVI_INFO1 + offset,
219 frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
220 WREG32(AFMT_AVI_INFO2 + offset,
221 frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
222 WREG32(AFMT_AVI_INFO3 + offset,
Alex Deucherf1003802013-06-07 10:41:03 -0400223 frame[0xC] | (frame[0xD] << 8) | (header[1] << 24));
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200224}
225
Alex Deucherb1f6f472013-04-18 10:50:55 -0400226static void evergreen_audio_set_dto(struct drm_encoder *encoder, u32 clock)
227{
228 struct drm_device *dev = encoder->dev;
229 struct radeon_device *rdev = dev->dev_private;
230 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
231 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
232 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
Alex Deucher731da212013-05-13 11:35:26 -0400233 u32 base_rate = 24000;
Alex Deucher1518dd82013-07-30 17:31:07 -0400234 u32 max_ratio = clock / base_rate;
235 u32 dto_phase;
236 u32 dto_modulo = clock;
237 u32 wallclock_ratio;
238 u32 dto_cntl;
Alex Deucherb1f6f472013-04-18 10:50:55 -0400239
240 if (!dig || !dig->afmt)
241 return;
242
Alex Deucherb5306022013-07-31 16:51:33 -0400243 if (ASIC_IS_DCE6(rdev)) {
Alex Deucher1518dd82013-07-30 17:31:07 -0400244 dto_phase = 24 * 1000;
Alex Deucherb5306022013-07-31 16:51:33 -0400245 } else {
246 if (max_ratio >= 8) {
247 dto_phase = 192 * 1000;
248 wallclock_ratio = 3;
249 } else if (max_ratio >= 4) {
250 dto_phase = 96 * 1000;
251 wallclock_ratio = 2;
252 } else if (max_ratio >= 2) {
253 dto_phase = 48 * 1000;
254 wallclock_ratio = 1;
255 } else {
256 dto_phase = 24 * 1000;
257 wallclock_ratio = 0;
258 }
259 dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK;
260 dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio);
261 WREG32(DCCG_AUDIO_DTO0_CNTL, dto_cntl);
Alex Deucher1518dd82013-07-30 17:31:07 -0400262 }
Alex Deucher1518dd82013-07-30 17:31:07 -0400263
Alex Deucherb1f6f472013-04-18 10:50:55 -0400264 /* XXX two dtos; generally use dto0 for hdmi */
265 /* Express [24MHz / target pixel clock] as an exact rational
266 * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
267 * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
268 */
Alex Deucher7d61d832013-07-26 13:26:05 -0400269 WREG32(DCCG_AUDIO_DTO_SOURCE, DCCG_AUDIO_DTO0_SOURCE_SEL(radeon_crtc->crtc_id));
Alex Deucher1518dd82013-07-30 17:31:07 -0400270 WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase);
271 WREG32(DCCG_AUDIO_DTO0_MODULE, dto_modulo);
Alex Deucherb1f6f472013-04-18 10:50:55 -0400272}
273
274
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200275/*
276 * update the info frames with the data from the current display mode
277 */
278void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
279{
280 struct drm_device *dev = encoder->dev;
281 struct radeon_device *rdev = dev->dev_private;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200282 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
283 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Thierry Redinge3b2e032013-01-14 13:36:30 +0100284 u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
285 struct hdmi_avi_infoframe frame;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200286 uint32_t offset;
Thierry Redinge3b2e032013-01-14 13:36:30 +0100287 ssize_t err;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200288
Alex Deucherc2b4cacf2013-07-08 18:16:56 -0400289 if (!dig || !dig->afmt)
290 return;
291
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200292 /* Silent, r600_hdmi_enable will raise WARN for us */
293 if (!dig->afmt->enabled)
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200294 return;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +0200295 offset = dig->afmt->offset;
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200296
Alex Deucherb1f6f472013-04-18 10:50:55 -0400297 evergreen_audio_set_dto(encoder, mode->clock);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200298
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200299 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
300 HDMI_NULL_SEND); /* send null packets when required */
301
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200302 WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200303
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200304 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
305 HDMI_NULL_SEND | /* send null packets when required */
306 HDMI_GC_SEND | /* send general control packets */
307 HDMI_GC_CONT); /* send general control packets every frame */
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200308
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200309 WREG32(HDMI_INFOFRAME_CONTROL0 + offset,
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200310 HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
311 HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */
312
313 WREG32(AFMT_INFOFRAME_CONTROL0 + offset,
314 AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */
315
316 WREG32(HDMI_INFOFRAME_CONTROL1 + offset,
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200317 HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */
318
319 WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200320
Rafał Miłecki91a44012013-04-18 09:26:08 -0400321 WREG32(HDMI_AUDIO_PACKET_CONTROL + offset,
322 HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */
323 HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
324
325 WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
326 AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
327
328 /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
329
330 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
331 HDMI_ACR_AUTO_SEND | /* allow hw to sent ACR packets when required */
332 HDMI_ACR_SOURCE); /* select SW CTS value */
333
334 evergreen_hdmi_update_ACR(encoder, mode->clock);
335
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200336 WREG32(AFMT_60958_0 + offset,
337 AFMT_60958_CS_CHANNEL_NUMBER_L(1));
338
339 WREG32(AFMT_60958_1 + offset,
340 AFMT_60958_CS_CHANNEL_NUMBER_R(2));
341
342 WREG32(AFMT_60958_2 + offset,
343 AFMT_60958_CS_CHANNEL_NUMBER_2(3) |
344 AFMT_60958_CS_CHANNEL_NUMBER_3(4) |
345 AFMT_60958_CS_CHANNEL_NUMBER_4(5) |
346 AFMT_60958_CS_CHANNEL_NUMBER_5(6) |
347 AFMT_60958_CS_CHANNEL_NUMBER_6(7) |
348 AFMT_60958_CS_CHANNEL_NUMBER_7(8));
349
Rafał Miłecki6159b652013-08-15 11:16:30 +0200350 if (ASIC_IS_DCE6(rdev)) {
351 dce6_afmt_write_speaker_allocation(encoder);
352 } else {
Alex Deucherba7def42013-08-15 09:34:07 -0400353 dce4_afmt_write_speaker_allocation(encoder);
Rafał Miłecki6159b652013-08-15 11:16:30 +0200354 }
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200355
356 WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset,
357 AFMT_AUDIO_CHANNEL_ENABLE(0xff));
358
359 /* fglrx sets 0x40 in 0x5f80 here */
Alex Deucherb5306022013-07-31 16:51:33 -0400360
361 if (ASIC_IS_DCE6(rdev)) {
362 dce6_afmt_select_pin(encoder);
363 dce6_afmt_write_sad_regs(encoder);
364 } else {
365 evergreen_hdmi_write_sad_regs(encoder);
Alex Deucher712fd8a2013-10-10 17:54:51 -0400366 dce4_afmt_write_latency_fields(encoder, mode);
Alex Deucherb5306022013-07-31 16:51:33 -0400367 }
Rafał Miłeckif93e3fc2013-04-14 01:26:24 +0200368
Thierry Redinge3b2e032013-01-14 13:36:30 +0100369 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
370 if (err < 0) {
371 DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
372 return;
373 }
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200374
Thierry Redinge3b2e032013-01-14 13:36:30 +0100375 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
376 if (err < 0) {
377 DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
378 return;
379 }
380
381 evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer));
Rafał Miłecki1c3439f2012-05-06 17:29:45 +0200382
Rafał Miłeckid3418ea2013-04-18 09:23:12 -0400383 WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset,
384 HDMI_AVI_INFO_SEND | /* enable AVI info frames */
385 HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */
386
387 WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset,
388 HDMI_AVI_INFO_LINE(2), /* anything other than 0 */
389 ~HDMI_AVI_INFO_LINE_MASK);
390
391 WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset,
392 AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */
393
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200394 /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
395 WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
396 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
397 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
398 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
Rafał Miłeckie55d3e62012-05-06 17:29:44 +0200399}
Alex Deuchera973bea2013-04-18 11:32:16 -0400400
401void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
402{
Alex Deucherb5306022013-07-31 16:51:33 -0400403 struct drm_device *dev = encoder->dev;
404 struct radeon_device *rdev = dev->dev_private;
Alex Deuchera973bea2013-04-18 11:32:16 -0400405 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
406 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
407
Alex Deucherc2b4cacf2013-07-08 18:16:56 -0400408 if (!dig || !dig->afmt)
409 return;
410
Alex Deuchera973bea2013-04-18 11:32:16 -0400411 /* Silent, r600_hdmi_enable will raise WARN for us */
412 if (enable && dig->afmt->enabled)
413 return;
414 if (!enable && !dig->afmt->enabled)
415 return;
416
Alex Deucherb5306022013-07-31 16:51:33 -0400417 if (enable) {
418 if (ASIC_IS_DCE6(rdev))
419 dig->afmt->pin = dce6_audio_get_pin(rdev);
420 else
421 dig->afmt->pin = r600_audio_get_pin(rdev);
422 } else {
423 dig->afmt->pin = NULL;
424 }
425
Alex Deuchera973bea2013-04-18 11:32:16 -0400426 dig->afmt->enabled = enable;
427
428 DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
429 enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id);
430}