blob: 5c805f7fea39500142ba790a6f173919ba883afd [file] [log] [blame]
Christian Koenigdafc3bd2009-10-11 23:49:13 +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 */
26#include "drmP.h"
27#include "radeon_drm.h"
28#include "radeon.h"
Daniel Vetter3574dda2011-02-18 17:59:19 +010029#include "radeon_asic.h"
Christian Koenigdafc3bd2009-10-11 23:49:13 +020030#include "atom.h"
31
32/*
33 * HDMI color format
34 */
35enum r600_hdmi_color_format {
36 RGB = 0,
37 YCC_422 = 1,
38 YCC_444 = 2
39};
40
41/*
42 * IEC60958 status bits
43 */
44enum r600_hdmi_iec_status_bits {
45 AUDIO_STATUS_DIG_ENABLE = 0x01,
Rafał Miłecki3fe373d2010-03-06 13:03:38 +000046 AUDIO_STATUS_V = 0x02,
47 AUDIO_STATUS_VCFG = 0x04,
Christian Koenigdafc3bd2009-10-11 23:49:13 +020048 AUDIO_STATUS_EMPHASIS = 0x08,
49 AUDIO_STATUS_COPYRIGHT = 0x10,
50 AUDIO_STATUS_NONAUDIO = 0x20,
51 AUDIO_STATUS_PROFESSIONAL = 0x40,
Rafał Miłecki3fe373d2010-03-06 13:03:38 +000052 AUDIO_STATUS_LEVEL = 0x80
Christian Koenigdafc3bd2009-10-11 23:49:13 +020053};
54
55struct {
56 uint32_t Clock;
57
58 int N_32kHz;
59 int CTS_32kHz;
60
61 int N_44_1kHz;
62 int CTS_44_1kHz;
63
64 int N_48kHz;
65 int CTS_48kHz;
66
67} r600_hdmi_ACR[] = {
68 /* 32kHz 44.1kHz 48kHz */
69 /* Clock N CTS N CTS N CTS */
70 { 25174, 4576, 28125, 7007, 31250, 6864, 28125 }, /* 25,20/1.001 MHz */
71 { 25200, 4096, 25200, 6272, 28000, 6144, 25200 }, /* 25.20 MHz */
72 { 27000, 4096, 27000, 6272, 30000, 6144, 27000 }, /* 27.00 MHz */
73 { 27027, 4096, 27027, 6272, 30030, 6144, 27027 }, /* 27.00*1.001 MHz */
74 { 54000, 4096, 54000, 6272, 60000, 6144, 54000 }, /* 54.00 MHz */
75 { 54054, 4096, 54054, 6272, 60060, 6144, 54054 }, /* 54.00*1.001 MHz */
76 { 74175, 11648, 210937, 17836, 234375, 11648, 140625 }, /* 74.25/1.001 MHz */
77 { 74250, 4096, 74250, 6272, 82500, 6144, 74250 }, /* 74.25 MHz */
78 { 148351, 11648, 421875, 8918, 234375, 5824, 140625 }, /* 148.50/1.001 MHz */
79 { 148500, 4096, 148500, 6272, 165000, 6144, 148500 }, /* 148.50 MHz */
80 { 0, 4096, 0, 6272, 0, 6144, 0 } /* Other */
81};
82
83/*
84 * calculate CTS value if it's not found in the table
85 */
86static void r600_hdmi_calc_CTS(uint32_t clock, int *CTS, int N, int freq)
87{
88 if (*CTS == 0)
Rafał Miłecki3fe373d2010-03-06 13:03:38 +000089 *CTS = clock * N / (128 * freq) * 1000;
Christian Koenigdafc3bd2009-10-11 23:49:13 +020090 DRM_DEBUG("Using ACR timing N=%d CTS=%d for frequency %d\n",
91 N, *CTS, freq);
92}
93
94/*
95 * update the N and CTS parameters for a given pixel clock rate
96 */
97static void r600_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
98{
99 struct drm_device *dev = encoder->dev;
100 struct radeon_device *rdev = dev->dev_private;
101 uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
102 int CTS;
103 int N;
104 int i;
105
106 for (i = 0; r600_hdmi_ACR[i].Clock != clock && r600_hdmi_ACR[i].Clock != 0; i++);
107
108 CTS = r600_hdmi_ACR[i].CTS_32kHz;
109 N = r600_hdmi_ACR[i].N_32kHz;
110 r600_hdmi_calc_CTS(clock, &CTS, N, 32000);
111 WREG32(offset+R600_HDMI_32kHz_CTS, CTS << 12);
112 WREG32(offset+R600_HDMI_32kHz_N, N);
113
114 CTS = r600_hdmi_ACR[i].CTS_44_1kHz;
115 N = r600_hdmi_ACR[i].N_44_1kHz;
116 r600_hdmi_calc_CTS(clock, &CTS, N, 44100);
117 WREG32(offset+R600_HDMI_44_1kHz_CTS, CTS << 12);
118 WREG32(offset+R600_HDMI_44_1kHz_N, N);
119
120 CTS = r600_hdmi_ACR[i].CTS_48kHz;
121 N = r600_hdmi_ACR[i].N_48kHz;
122 r600_hdmi_calc_CTS(clock, &CTS, N, 48000);
123 WREG32(offset+R600_HDMI_48kHz_CTS, CTS << 12);
124 WREG32(offset+R600_HDMI_48kHz_N, N);
125}
126
127/*
128 * calculate the crc for a given info frame
129 */
130static void r600_hdmi_infoframe_checksum(uint8_t packetType,
131 uint8_t versionNumber,
132 uint8_t length,
133 uint8_t *frame)
134{
Rafał Miłecki3fe373d2010-03-06 13:03:38 +0000135 int i;
136 frame[0] = packetType + versionNumber + length;
137 for (i = 1; i <= length; i++)
138 frame[0] += frame[i];
139 frame[0] = 0x100 - frame[0];
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200140}
141
142/*
143 * build a HDMI Video Info Frame
144 */
145static void r600_hdmi_videoinfoframe(
146 struct drm_encoder *encoder,
147 enum r600_hdmi_color_format color_format,
148 int active_information_present,
149 uint8_t active_format_aspect_ratio,
150 uint8_t scan_information,
151 uint8_t colorimetry,
152 uint8_t ex_colorimetry,
153 uint8_t quantization,
154 int ITC,
155 uint8_t picture_aspect_ratio,
156 uint8_t video_format_identification,
157 uint8_t pixel_repetition,
158 uint8_t non_uniform_picture_scaling,
159 uint8_t bar_info_data_valid,
160 uint16_t top_bar,
161 uint16_t bottom_bar,
162 uint16_t left_bar,
163 uint16_t right_bar
164)
165{
166 struct drm_device *dev = encoder->dev;
167 struct radeon_device *rdev = dev->dev_private;
168 uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
169
170 uint8_t frame[14];
171
172 frame[0x0] = 0;
173 frame[0x1] =
174 (scan_information & 0x3) |
175 ((bar_info_data_valid & 0x3) << 2) |
176 ((active_information_present & 0x1) << 4) |
177 ((color_format & 0x3) << 5);
178 frame[0x2] =
179 (active_format_aspect_ratio & 0xF) |
180 ((picture_aspect_ratio & 0x3) << 4) |
181 ((colorimetry & 0x3) << 6);
182 frame[0x3] =
183 (non_uniform_picture_scaling & 0x3) |
184 ((quantization & 0x3) << 2) |
185 ((ex_colorimetry & 0x7) << 4) |
186 ((ITC & 0x1) << 7);
187 frame[0x4] = (video_format_identification & 0x7F);
188 frame[0x5] = (pixel_repetition & 0xF);
189 frame[0x6] = (top_bar & 0xFF);
190 frame[0x7] = (top_bar >> 8);
191 frame[0x8] = (bottom_bar & 0xFF);
192 frame[0x9] = (bottom_bar >> 8);
193 frame[0xA] = (left_bar & 0xFF);
194 frame[0xB] = (left_bar >> 8);
195 frame[0xC] = (right_bar & 0xFF);
196 frame[0xD] = (right_bar >> 8);
197
198 r600_hdmi_infoframe_checksum(0x82, 0x02, 0x0D, frame);
199
200 WREG32(offset+R600_HDMI_VIDEOINFOFRAME_0,
201 frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
202 WREG32(offset+R600_HDMI_VIDEOINFOFRAME_1,
203 frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
204 WREG32(offset+R600_HDMI_VIDEOINFOFRAME_2,
205 frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
206 WREG32(offset+R600_HDMI_VIDEOINFOFRAME_3,
207 frame[0xC] | (frame[0xD] << 8));
208}
209
210/*
211 * build a Audio Info Frame
212 */
213static void r600_hdmi_audioinfoframe(
214 struct drm_encoder *encoder,
215 uint8_t channel_count,
216 uint8_t coding_type,
217 uint8_t sample_size,
218 uint8_t sample_frequency,
219 uint8_t format,
220 uint8_t channel_allocation,
221 uint8_t level_shift,
222 int downmix_inhibit
223)
224{
225 struct drm_device *dev = encoder->dev;
226 struct radeon_device *rdev = dev->dev_private;
227 uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
228
229 uint8_t frame[11];
230
231 frame[0x0] = 0;
232 frame[0x1] = (channel_count & 0x7) | ((coding_type & 0xF) << 4);
233 frame[0x2] = (sample_size & 0x3) | ((sample_frequency & 0x7) << 2);
234 frame[0x3] = format;
235 frame[0x4] = channel_allocation;
236 frame[0x5] = ((level_shift & 0xF) << 3) | ((downmix_inhibit & 0x1) << 7);
237 frame[0x6] = 0;
238 frame[0x7] = 0;
239 frame[0x8] = 0;
240 frame[0x9] = 0;
241 frame[0xA] = 0;
242
243 r600_hdmi_infoframe_checksum(0x84, 0x01, 0x0A, frame);
244
245 WREG32(offset+R600_HDMI_AUDIOINFOFRAME_0,
246 frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
247 WREG32(offset+R600_HDMI_AUDIOINFOFRAME_1,
248 frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x8] << 24));
249}
250
251/*
252 * test if audio buffer is filled enough to start playing
253 */
254static int r600_hdmi_is_audio_buffer_filled(struct drm_encoder *encoder)
255{
256 struct drm_device *dev = encoder->dev;
257 struct radeon_device *rdev = dev->dev_private;
258 uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
259
260 return (RREG32(offset+R600_HDMI_STATUS) & 0x10) != 0;
261}
262
263/*
264 * have buffer status changed since last call?
265 */
266int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder)
267{
268 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
269 int status, result;
270
271 if (!radeon_encoder->hdmi_offset)
272 return 0;
273
274 status = r600_hdmi_is_audio_buffer_filled(encoder);
275 result = radeon_encoder->hdmi_buffer_status != status;
276 radeon_encoder->hdmi_buffer_status = status;
277
278 return result;
279}
280
281/*
282 * write the audio workaround status to the hardware
283 */
284void r600_hdmi_audio_workaround(struct drm_encoder *encoder)
285{
286 struct drm_device *dev = encoder->dev;
287 struct radeon_device *rdev = dev->dev_private;
288 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
289 uint32_t offset = radeon_encoder->hdmi_offset;
290
291 if (!offset)
292 return;
293
Christian Koenigf2594932010-04-10 03:13:16 +0200294 if (!radeon_encoder->hdmi_audio_workaround ||
295 r600_hdmi_is_audio_buffer_filled(encoder)) {
296
297 /* disable audio workaround */
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200298 WREG32_P(offset+R600_HDMI_CNTL, 0x00000001, ~0x00001001);
299
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200300 } else {
Christian Koenigf2594932010-04-10 03:13:16 +0200301 /* enable audio workaround */
302 WREG32_P(offset+R600_HDMI_CNTL, 0x00001001, ~0x00001001);
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200303 }
304}
305
306
307/*
308 * update the info frames with the data from the current display mode
309 */
310void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
311{
312 struct drm_device *dev = encoder->dev;
313 struct radeon_device *rdev = dev->dev_private;
314 uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
315
Rafał Miłeckif83d9262011-12-23 20:36:06 +0100316 if (ASIC_IS_DCE5(rdev))
Alex Deucher16823d12010-04-16 11:35:30 -0400317 return;
318
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200319 if (!offset)
320 return;
321
322 r600_audio_set_clock(encoder, mode->clock);
323
324 WREG32(offset+R600_HDMI_UNKNOWN_0, 0x1000);
325 WREG32(offset+R600_HDMI_UNKNOWN_1, 0x0);
326 WREG32(offset+R600_HDMI_UNKNOWN_2, 0x1000);
327
328 r600_hdmi_update_ACR(encoder, mode->clock);
329
330 WREG32(offset+R600_HDMI_VIDEOCNTL, 0x13);
331
332 WREG32(offset+R600_HDMI_VERSION, 0x202);
333
334 r600_hdmi_videoinfoframe(encoder, RGB, 0, 0, 0, 0,
335 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
336
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300337 /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200338 WREG32(offset+R600_HDMI_AUDIO_DEBUG_0, 0x00FFFFFF);
339 WREG32(offset+R600_HDMI_AUDIO_DEBUG_1, 0x007FFFFF);
340 WREG32(offset+R600_HDMI_AUDIO_DEBUG_2, 0x00000001);
341 WREG32(offset+R600_HDMI_AUDIO_DEBUG_3, 0x00000001);
342
343 r600_hdmi_audio_workaround(encoder);
344
345 /* audio packets per line, does anyone know how to calc this ? */
346 WREG32_P(offset+R600_HDMI_CNTL, 0x00040000, ~0x001F0000);
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200347}
348
349/*
350 * update settings with current parameters from audio engine
351 */
Christian König58bd0862010-04-05 22:14:55 +0200352void r600_hdmi_update_audio_settings(struct drm_encoder *encoder)
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200353{
354 struct drm_device *dev = encoder->dev;
355 struct radeon_device *rdev = dev->dev_private;
356 uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
357
Christian König58bd0862010-04-05 22:14:55 +0200358 int channels = r600_audio_channels(rdev);
359 int rate = r600_audio_rate(rdev);
360 int bps = r600_audio_bits_per_sample(rdev);
361 uint8_t status_bits = r600_audio_status_bits(rdev);
362 uint8_t category_code = r600_audio_category_code(rdev);
363
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200364 uint32_t iec;
365
366 if (!offset)
367 return;
368
369 DRM_DEBUG("%s with %d channels, %d Hz sampling rate, %d bits per sample,\n",
370 r600_hdmi_is_audio_buffer_filled(encoder) ? "playing" : "stopped",
371 channels, rate, bps);
372 DRM_DEBUG("0x%02X IEC60958 status bits and 0x%02X category code\n",
373 (int)status_bits, (int)category_code);
374
375 iec = 0;
376 if (status_bits & AUDIO_STATUS_PROFESSIONAL)
377 iec |= 1 << 0;
378 if (status_bits & AUDIO_STATUS_NONAUDIO)
379 iec |= 1 << 1;
380 if (status_bits & AUDIO_STATUS_COPYRIGHT)
381 iec |= 1 << 2;
382 if (status_bits & AUDIO_STATUS_EMPHASIS)
383 iec |= 1 << 3;
384
385 iec |= category_code << 8;
386
387 switch (rate) {
388 case 32000: iec |= 0x3 << 24; break;
389 case 44100: iec |= 0x0 << 24; break;
390 case 88200: iec |= 0x8 << 24; break;
391 case 176400: iec |= 0xc << 24; break;
392 case 48000: iec |= 0x2 << 24; break;
393 case 96000: iec |= 0xa << 24; break;
394 case 192000: iec |= 0xe << 24; break;
395 }
396
397 WREG32(offset+R600_HDMI_IEC60958_1, iec);
398
399 iec = 0;
400 switch (bps) {
401 case 16: iec |= 0x2; break;
402 case 20: iec |= 0x3; break;
403 case 24: iec |= 0xb; break;
404 }
405 if (status_bits & AUDIO_STATUS_V)
406 iec |= 0x5 << 16;
407
408 WREG32_P(offset+R600_HDMI_IEC60958_2, iec, ~0x5000f);
409
410 /* 0x021 or 0x031 sets the audio frame length */
411 WREG32(offset+R600_HDMI_AUDIOCNTL, 0x31);
412 r600_hdmi_audioinfoframe(encoder, channels-1, 0, 0, 0, 0, 0, 0, 0);
413
414 r600_hdmi_audio_workaround(encoder);
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200415}
416
Rafał Miłecki5715f672010-03-06 13:03:35 +0000417static int r600_hdmi_find_free_block(struct drm_device *dev)
418{
419 struct radeon_device *rdev = dev->dev_private;
420 struct drm_encoder *encoder;
421 struct radeon_encoder *radeon_encoder;
422 bool free_blocks[3] = { true, true, true };
423
424 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
425 radeon_encoder = to_radeon_encoder(encoder);
426 switch (radeon_encoder->hdmi_offset) {
427 case R600_HDMI_BLOCK1:
428 free_blocks[0] = false;
429 break;
430 case R600_HDMI_BLOCK2:
431 free_blocks[1] = false;
432 break;
433 case R600_HDMI_BLOCK3:
434 free_blocks[2] = false;
435 break;
436 }
437 }
438
Rafał Miłeckife50ac72010-06-19 12:24:57 +0200439 if (rdev->family == CHIP_RS600 || rdev->family == CHIP_RS690 ||
440 rdev->family == CHIP_RS740) {
Rafał Miłecki5715f672010-03-06 13:03:35 +0000441 return free_blocks[0] ? R600_HDMI_BLOCK1 : 0;
442 } else if (rdev->family >= CHIP_R600) {
443 if (free_blocks[0])
444 return R600_HDMI_BLOCK1;
445 else if (free_blocks[1])
446 return R600_HDMI_BLOCK2;
447 }
448 return 0;
449}
450
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000451static void r600_hdmi_assign_block(struct drm_encoder *encoder)
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200452{
453 struct drm_device *dev = encoder->dev;
454 struct radeon_device *rdev = dev->dev_private;
455 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000456 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200457
Rafał Miłeckif83d9262011-12-23 20:36:06 +0100458 u16 eg_offsets[] = {
459 EVERGREEN_CRTC0_REGISTER_OFFSET,
460 EVERGREEN_CRTC1_REGISTER_OFFSET,
461 EVERGREEN_CRTC2_REGISTER_OFFSET,
462 EVERGREEN_CRTC3_REGISTER_OFFSET,
463 EVERGREEN_CRTC4_REGISTER_OFFSET,
464 EVERGREEN_CRTC5_REGISTER_OFFSET,
465 };
466
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000467 if (!dig) {
468 dev_err(rdev->dev, "Enabling HDMI on non-dig encoder\n");
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200469 return;
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000470 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200471
Rafał Miłeckiebcb7962011-12-04 11:23:51 +0100472 if (ASIC_IS_DCE5(rdev)) {
473 /* TODO */
474 } else if (ASIC_IS_DCE4(rdev)) {
Rafał Miłeckif83d9262011-12-23 20:36:06 +0100475 if (dig->dig_encoder >= ARRAY_SIZE(eg_offsets)) {
476 dev_err(rdev->dev, "Enabling HDMI on unknown dig\n");
477 return;
478 }
479 radeon_encoder->hdmi_offset = EVERGREEN_HDMI_BASE +
480 eg_offsets[dig->dig_encoder];
481 radeon_encoder->hdmi_config_offset = radeon_encoder->hdmi_offset
482 + EVERGREEN_HDMI_CONFIG_OFFSET;
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000483 } else if (ASIC_IS_DCE3(rdev)) {
484 radeon_encoder->hdmi_offset = dig->dig_encoder ?
485 R600_HDMI_BLOCK3 : R600_HDMI_BLOCK1;
486 if (ASIC_IS_DCE32(rdev))
487 radeon_encoder->hdmi_config_offset = dig->dig_encoder ?
488 R600_HDMI_CONFIG2 : R600_HDMI_CONFIG1;
Rafał Miłeckife50ac72010-06-19 12:24:57 +0200489 } else if (rdev->family >= CHIP_R600 || rdev->family == CHIP_RS600 ||
490 rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) {
Rafał Miłecki5715f672010-03-06 13:03:35 +0000491 radeon_encoder->hdmi_offset = r600_hdmi_find_free_block(dev);
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200492 }
493}
494
495/*
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000496 * enable the HDMI engine
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200497 */
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000498void r600_hdmi_enable(struct drm_encoder *encoder)
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200499{
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000500 struct drm_device *dev = encoder->dev;
501 struct radeon_device *rdev = dev->dev_private;
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200502 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Christian Koenigf2594932010-04-10 03:13:16 +0200503 uint32_t offset;
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200504
Rafał Miłeckif83d9262011-12-23 20:36:06 +0100505 if (ASIC_IS_DCE5(rdev))
Alex Deucher16823d12010-04-16 11:35:30 -0400506 return;
507
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000508 if (!radeon_encoder->hdmi_offset) {
509 r600_hdmi_assign_block(encoder);
510 if (!radeon_encoder->hdmi_offset) {
511 dev_warn(rdev->dev, "Could not find HDMI block for "
512 "0x%x encoder\n", radeon_encoder->encoder_id);
513 return;
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200514 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200515 }
516
Christian Koenigf2594932010-04-10 03:13:16 +0200517 offset = radeon_encoder->hdmi_offset;
Rafał Miłeckiebcb7962011-12-04 11:23:51 +0100518 if (ASIC_IS_DCE5(rdev)) {
519 /* TODO */
520 } else if (ASIC_IS_DCE4(rdev)) {
Rafał Miłeckif83d9262011-12-23 20:36:06 +0100521 WREG32_P(radeon_encoder->hdmi_config_offset + 0xc, 0x1, ~0x1);
Rafał Miłeckiebcb7962011-12-04 11:23:51 +0100522 } else if (ASIC_IS_DCE32(rdev)) {
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000523 WREG32_P(radeon_encoder->hdmi_config_offset + 0x4, 0x1, ~0x1);
Rafał Miłeckiebcb7962011-12-04 11:23:51 +0100524 } else if (ASIC_IS_DCE3(rdev)) {
525 /* TODO */
526 } else if (rdev->family >= CHIP_R600) {
Rafał Miłecki5715f672010-03-06 13:03:35 +0000527 switch (radeon_encoder->encoder_id) {
528 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
529 WREG32_P(AVIVO_TMDSA_CNTL, 0x4, ~0x4);
530 WREG32(offset + R600_HDMI_ENABLE, 0x101);
531 break;
532 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
533 WREG32_P(AVIVO_LVTMA_CNTL, 0x4, ~0x4);
534 WREG32(offset + R600_HDMI_ENABLE, 0x105);
535 break;
536 default:
537 dev_err(rdev->dev, "Unknown HDMI output type\n");
538 break;
539 }
540 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200541
Christian Koenigf2594932010-04-10 03:13:16 +0200542 if (rdev->irq.installed
543 && rdev->family != CHIP_RS600
544 && rdev->family != CHIP_RS690
Rafał Miłeckif83d9262011-12-23 20:36:06 +0100545 && rdev->family != CHIP_RS740
546 && !ASIC_IS_DCE4(rdev)) {
Christian Koenigf2594932010-04-10 03:13:16 +0200547 /* if irq is available use it */
548 rdev->irq.hdmi[offset == R600_HDMI_BLOCK1 ? 0 : 1] = true;
549 radeon_irq_set(rdev);
550
551 r600_audio_disable_polling(encoder);
552 } else {
553 /* if not fallback to polling */
554 r600_audio_enable_polling(encoder);
555 }
Christian König58bd0862010-04-05 22:14:55 +0200556
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000557 DRM_DEBUG("Enabling HDMI interface @ 0x%04X for encoder 0x%x\n",
558 radeon_encoder->hdmi_offset, radeon_encoder->encoder_id);
559}
560
561/*
562 * disable the HDMI engine
563 */
564void r600_hdmi_disable(struct drm_encoder *encoder)
565{
566 struct drm_device *dev = encoder->dev;
567 struct radeon_device *rdev = dev->dev_private;
568 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Dave Airlie66989982010-05-19 10:35:02 +1000569 uint32_t offset;
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000570
Rafał Miłeckif83d9262011-12-23 20:36:06 +0100571 if (ASIC_IS_DCE5(rdev))
Alex Deucher16823d12010-04-16 11:35:30 -0400572 return;
573
Christian Koenigf2594932010-04-10 03:13:16 +0200574 offset = radeon_encoder->hdmi_offset;
575 if (!offset) {
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000576 dev_err(rdev->dev, "Disabling not enabled HDMI\n");
577 return;
578 }
579
580 DRM_DEBUG("Disabling HDMI interface @ 0x%04X for encoder 0x%x\n",
Christian Koenigf2594932010-04-10 03:13:16 +0200581 offset, radeon_encoder->encoder_id);
582
583 /* disable irq */
584 rdev->irq.hdmi[offset == R600_HDMI_BLOCK1 ? 0 : 1] = false;
585 radeon_irq_set(rdev);
586
587 /* disable polling */
588 r600_audio_disable_polling(encoder);
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000589
Rafał Miłeckif83d9262011-12-23 20:36:06 +0100590 if (ASIC_IS_DCE5(rdev)) {
591 /* TODO */
592 } else if (ASIC_IS_DCE4(rdev)) {
593 WREG32_P(radeon_encoder->hdmi_config_offset + 0xc, 0, ~0x1);
594 } else if (ASIC_IS_DCE32(rdev)) {
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000595 WREG32_P(radeon_encoder->hdmi_config_offset + 0x4, 0, ~0x1);
Rafał Miłecki5715f672010-03-06 13:03:35 +0000596 } else if (rdev->family >= CHIP_R600 && !ASIC_IS_DCE3(rdev)) {
Rafał Miłecki5715f672010-03-06 13:03:35 +0000597 switch (radeon_encoder->encoder_id) {
598 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
599 WREG32_P(AVIVO_TMDSA_CNTL, 0, ~0x4);
600 WREG32(offset + R600_HDMI_ENABLE, 0);
601 break;
602 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
603 WREG32_P(AVIVO_LVTMA_CNTL, 0, ~0x4);
604 WREG32(offset + R600_HDMI_ENABLE, 0);
605 break;
606 default:
607 dev_err(rdev->dev, "Unknown HDMI output type\n");
608 break;
609 }
610 }
Rafał Miłecki2cd62182010-03-08 22:14:01 +0000611
612 radeon_encoder->hdmi_offset = 0;
613 radeon_encoder->hdmi_config_offset = 0;
Christian Koenigdafc3bd2009-10-11 23:49:13 +0200614}