Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 1 | /* |
| 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 Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 27 | #include <linux/hdmi.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 28 | #include <drm/drmP.h> |
| 29 | #include <drm/radeon_drm.h> |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 30 | #include "radeon.h" |
| 31 | #include "radeon_asic.h" |
| 32 | #include "evergreend.h" |
| 33 | #include "atom.h" |
| 34 | |
Rafał Miłecki | 6159b65 | 2013-08-15 11:16:30 +0200 | [diff] [blame] | 35 | extern void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder); |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 36 | extern void dce6_afmt_write_sad_regs(struct drm_encoder *encoder); |
| 37 | extern void dce6_afmt_select_pin(struct drm_encoder *encoder); |
Alex Deucher | b188025 | 2013-10-10 18:03:06 -0400 | [diff] [blame] | 38 | extern void dce6_afmt_write_latency_fields(struct drm_encoder *encoder, |
| 39 | struct drm_display_mode *mode); |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 40 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 41 | /* |
| 42 | * update the N and CTS parameters for a given pixel clock rate |
| 43 | */ |
| 44 | static 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łecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 49 | 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łecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 52 | |
| 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 Deucher | 712fd8a | 2013-10-10 17:54:51 -0400 | [diff] [blame] | 63 | static 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 Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 99 | static 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 | |
Alex Deucher | 555b1b651 | 2013-10-18 20:00:09 -0400 | [diff] [blame] | 108 | /* XXX: setting this register causes hangs on some asics */ |
| 109 | return; |
| 110 | |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 111 | list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { |
Alex Deucher | 8a992ee | 2013-10-10 17:58:27 -0400 | [diff] [blame] | 112 | if (connector->encoder == encoder) { |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 113 | radeon_connector = to_radeon_connector(connector); |
Alex Deucher | 8a992ee | 2013-10-10 17:58:27 -0400 | [diff] [blame] | 114 | break; |
| 115 | } |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (!radeon_connector) { |
| 119 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | sad_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb); |
| 124 | if (sad_count < 0) { |
| 125 | DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | /* program the speaker allocation */ |
| 130 | tmp = RREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER); |
| 131 | tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK); |
| 132 | /* set HDMI mode */ |
| 133 | tmp |= HDMI_CONNECTION; |
| 134 | if (sad_count) |
| 135 | tmp |= SPEAKER_ALLOCATION(sadb[0]); |
| 136 | else |
| 137 | tmp |= SPEAKER_ALLOCATION(5); /* stereo */ |
| 138 | WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp); |
| 139 | |
| 140 | kfree(sadb); |
| 141 | } |
| 142 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 143 | static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder) |
| 144 | { |
| 145 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 146 | struct drm_connector *connector; |
| 147 | struct radeon_connector *radeon_connector = NULL; |
| 148 | struct cea_sad *sads; |
| 149 | int i, sad_count; |
| 150 | |
| 151 | static const u16 eld_reg_to_type[][2] = { |
| 152 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM }, |
| 153 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 }, |
| 154 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 }, |
| 155 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 }, |
| 156 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 }, |
| 157 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC }, |
| 158 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS }, |
| 159 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC }, |
| 160 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 }, |
| 161 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD }, |
| 162 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP }, |
| 163 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO }, |
| 164 | }; |
| 165 | |
| 166 | list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { |
Alex Deucher | 8a992ee | 2013-10-10 17:58:27 -0400 | [diff] [blame] | 167 | if (connector->encoder == encoder) { |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 168 | radeon_connector = to_radeon_connector(connector); |
Alex Deucher | 8a992ee | 2013-10-10 17:58:27 -0400 | [diff] [blame] | 169 | break; |
| 170 | } |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | if (!radeon_connector) { |
| 174 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | sad_count = drm_edid_to_sad(radeon_connector->edid, &sads); |
| 179 | if (sad_count < 0) { |
| 180 | DRM_ERROR("Couldn't read SADs: %d\n", sad_count); |
| 181 | return; |
| 182 | } |
| 183 | BUG_ON(!sads); |
| 184 | |
| 185 | for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) { |
| 186 | u32 value = 0; |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame^] | 187 | u8 stereo_freqs = 0; |
| 188 | int max_channels = -1; |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 189 | int j; |
| 190 | |
| 191 | for (j = 0; j < sad_count; j++) { |
| 192 | struct cea_sad *sad = &sads[j]; |
| 193 | |
| 194 | if (sad->format == eld_reg_to_type[i][1]) { |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame^] | 195 | if (sad->channels > max_channels) { |
| 196 | value = MAX_CHANNELS(sad->channels) | |
| 197 | DESCRIPTOR_BYTE_2(sad->byte2) | |
| 198 | SUPPORTED_FREQUENCIES(sad->freq); |
| 199 | max_channels = sad->channels; |
| 200 | } |
| 201 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 202 | if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM) |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame^] | 203 | stereo_freqs |= sad->freq; |
| 204 | else |
| 205 | break; |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 206 | } |
| 207 | } |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame^] | 208 | |
| 209 | value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs); |
| 210 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 211 | WREG32(eld_reg_to_type[i][0], value); |
| 212 | } |
| 213 | |
| 214 | kfree(sads); |
| 215 | } |
| 216 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 217 | /* |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 218 | * build a HDMI Video Info Frame |
| 219 | */ |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 220 | static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder, |
| 221 | void *buffer, size_t size) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 222 | { |
| 223 | struct drm_device *dev = encoder->dev; |
| 224 | struct radeon_device *rdev = dev->dev_private; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 225 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 226 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 227 | uint32_t offset = dig->afmt->offset; |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 228 | uint8_t *frame = buffer + 3; |
Alex Deucher | f100380 | 2013-06-07 10:41:03 -0400 | [diff] [blame] | 229 | uint8_t *header = buffer; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 230 | |
| 231 | WREG32(AFMT_AVI_INFO0 + offset, |
| 232 | frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24)); |
| 233 | WREG32(AFMT_AVI_INFO1 + offset, |
| 234 | frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24)); |
| 235 | WREG32(AFMT_AVI_INFO2 + offset, |
| 236 | frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); |
| 237 | WREG32(AFMT_AVI_INFO3 + offset, |
Alex Deucher | f100380 | 2013-06-07 10:41:03 -0400 | [diff] [blame] | 238 | frame[0xC] | (frame[0xD] << 8) | (header[1] << 24)); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 241 | static void evergreen_audio_set_dto(struct drm_encoder *encoder, u32 clock) |
| 242 | { |
| 243 | struct drm_device *dev = encoder->dev; |
| 244 | struct radeon_device *rdev = dev->dev_private; |
| 245 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 246 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 247 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
Alex Deucher | 731da21 | 2013-05-13 11:35:26 -0400 | [diff] [blame] | 248 | u32 base_rate = 24000; |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 249 | u32 max_ratio = clock / base_rate; |
| 250 | u32 dto_phase; |
| 251 | u32 dto_modulo = clock; |
| 252 | u32 wallclock_ratio; |
| 253 | u32 dto_cntl; |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 254 | |
| 255 | if (!dig || !dig->afmt) |
| 256 | return; |
| 257 | |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 258 | if (ASIC_IS_DCE6(rdev)) { |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 259 | dto_phase = 24 * 1000; |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 260 | } else { |
| 261 | if (max_ratio >= 8) { |
| 262 | dto_phase = 192 * 1000; |
| 263 | wallclock_ratio = 3; |
| 264 | } else if (max_ratio >= 4) { |
| 265 | dto_phase = 96 * 1000; |
| 266 | wallclock_ratio = 2; |
| 267 | } else if (max_ratio >= 2) { |
| 268 | dto_phase = 48 * 1000; |
| 269 | wallclock_ratio = 1; |
| 270 | } else { |
| 271 | dto_phase = 24 * 1000; |
| 272 | wallclock_ratio = 0; |
| 273 | } |
| 274 | dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK; |
| 275 | dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio); |
| 276 | WREG32(DCCG_AUDIO_DTO0_CNTL, dto_cntl); |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 277 | } |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 278 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 279 | /* XXX two dtos; generally use dto0 for hdmi */ |
| 280 | /* Express [24MHz / target pixel clock] as an exact rational |
| 281 | * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE |
| 282 | * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator |
| 283 | */ |
Alex Deucher | 7d61d83 | 2013-07-26 13:26:05 -0400 | [diff] [blame] | 284 | WREG32(DCCG_AUDIO_DTO_SOURCE, DCCG_AUDIO_DTO0_SOURCE_SEL(radeon_crtc->crtc_id)); |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 285 | WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase); |
| 286 | WREG32(DCCG_AUDIO_DTO0_MODULE, dto_modulo); |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 290 | /* |
| 291 | * update the info frames with the data from the current display mode |
| 292 | */ |
| 293 | void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode) |
| 294 | { |
| 295 | struct drm_device *dev = encoder->dev; |
| 296 | struct radeon_device *rdev = dev->dev_private; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 297 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 298 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 299 | u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; |
| 300 | struct hdmi_avi_infoframe frame; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 301 | uint32_t offset; |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 302 | ssize_t err; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 303 | |
Alex Deucher | c2b4cacf | 2013-07-08 18:16:56 -0400 | [diff] [blame] | 304 | if (!dig || !dig->afmt) |
| 305 | return; |
| 306 | |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 307 | /* Silent, r600_hdmi_enable will raise WARN for us */ |
| 308 | if (!dig->afmt->enabled) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 309 | return; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 310 | offset = dig->afmt->offset; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 311 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 312 | evergreen_audio_set_dto(encoder, mode->clock); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 313 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 314 | WREG32(HDMI_VBI_PACKET_CONTROL + offset, |
| 315 | HDMI_NULL_SEND); /* send null packets when required */ |
| 316 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 317 | WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 318 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 319 | WREG32(HDMI_VBI_PACKET_CONTROL + offset, |
| 320 | HDMI_NULL_SEND | /* send null packets when required */ |
| 321 | HDMI_GC_SEND | /* send general control packets */ |
| 322 | HDMI_GC_CONT); /* send general control packets every frame */ |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 323 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 324 | WREG32(HDMI_INFOFRAME_CONTROL0 + offset, |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 325 | HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ |
| 326 | HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */ |
| 327 | |
| 328 | WREG32(AFMT_INFOFRAME_CONTROL0 + offset, |
| 329 | AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */ |
| 330 | |
| 331 | WREG32(HDMI_INFOFRAME_CONTROL1 + offset, |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 332 | HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */ |
| 333 | |
| 334 | WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */ |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 335 | |
Rafał Miłecki | 91a4401 | 2013-04-18 09:26:08 -0400 | [diff] [blame] | 336 | WREG32(HDMI_AUDIO_PACKET_CONTROL + offset, |
| 337 | HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */ |
| 338 | HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */ |
| 339 | |
| 340 | WREG32(AFMT_AUDIO_PACKET_CONTROL + offset, |
| 341 | AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */ |
| 342 | |
| 343 | /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */ |
| 344 | |
| 345 | WREG32(HDMI_ACR_PACKET_CONTROL + offset, |
Alex Deucher | de92680 | 2013-10-22 10:46:59 -0400 | [diff] [blame] | 346 | HDMI_ACR_SOURCE | /* select SW CTS value */ |
Alex Deucher | ee0fec3 | 2013-09-27 18:22:15 -0400 | [diff] [blame] | 347 | HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */ |
Rafał Miłecki | 91a4401 | 2013-04-18 09:26:08 -0400 | [diff] [blame] | 348 | |
| 349 | evergreen_hdmi_update_ACR(encoder, mode->clock); |
| 350 | |
Rafał Miłecki | f93e3fc | 2013-04-14 01:26:24 +0200 | [diff] [blame] | 351 | WREG32(AFMT_60958_0 + offset, |
| 352 | AFMT_60958_CS_CHANNEL_NUMBER_L(1)); |
| 353 | |
| 354 | WREG32(AFMT_60958_1 + offset, |
| 355 | AFMT_60958_CS_CHANNEL_NUMBER_R(2)); |
| 356 | |
| 357 | WREG32(AFMT_60958_2 + offset, |
| 358 | AFMT_60958_CS_CHANNEL_NUMBER_2(3) | |
| 359 | AFMT_60958_CS_CHANNEL_NUMBER_3(4) | |
| 360 | AFMT_60958_CS_CHANNEL_NUMBER_4(5) | |
| 361 | AFMT_60958_CS_CHANNEL_NUMBER_5(6) | |
| 362 | AFMT_60958_CS_CHANNEL_NUMBER_6(7) | |
| 363 | AFMT_60958_CS_CHANNEL_NUMBER_7(8)); |
| 364 | |
Rafał Miłecki | 6159b65 | 2013-08-15 11:16:30 +0200 | [diff] [blame] | 365 | if (ASIC_IS_DCE6(rdev)) { |
| 366 | dce6_afmt_write_speaker_allocation(encoder); |
| 367 | } else { |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 368 | dce4_afmt_write_speaker_allocation(encoder); |
Rafał Miłecki | 6159b65 | 2013-08-15 11:16:30 +0200 | [diff] [blame] | 369 | } |
Rafał Miłecki | f93e3fc | 2013-04-14 01:26:24 +0200 | [diff] [blame] | 370 | |
| 371 | WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset, |
| 372 | AFMT_AUDIO_CHANNEL_ENABLE(0xff)); |
| 373 | |
| 374 | /* fglrx sets 0x40 in 0x5f80 here */ |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 375 | |
| 376 | if (ASIC_IS_DCE6(rdev)) { |
| 377 | dce6_afmt_select_pin(encoder); |
| 378 | dce6_afmt_write_sad_regs(encoder); |
Alex Deucher | b188025 | 2013-10-10 18:03:06 -0400 | [diff] [blame] | 379 | dce6_afmt_write_latency_fields(encoder, mode); |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 380 | } else { |
| 381 | evergreen_hdmi_write_sad_regs(encoder); |
Alex Deucher | 712fd8a | 2013-10-10 17:54:51 -0400 | [diff] [blame] | 382 | dce4_afmt_write_latency_fields(encoder, mode); |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 383 | } |
Rafał Miłecki | f93e3fc | 2013-04-14 01:26:24 +0200 | [diff] [blame] | 384 | |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 385 | err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); |
| 386 | if (err < 0) { |
| 387 | DRM_ERROR("failed to setup AVI infoframe: %zd\n", err); |
| 388 | return; |
| 389 | } |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 390 | |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 391 | err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 392 | if (err < 0) { |
| 393 | DRM_ERROR("failed to pack AVI infoframe: %zd\n", err); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer)); |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 398 | |
Rafał Miłecki | d3418ea | 2013-04-18 09:23:12 -0400 | [diff] [blame] | 399 | WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset, |
| 400 | HDMI_AVI_INFO_SEND | /* enable AVI info frames */ |
| 401 | HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */ |
| 402 | |
| 403 | WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, |
| 404 | HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ |
| 405 | ~HDMI_AVI_INFO_LINE_MASK); |
| 406 | |
| 407 | WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset, |
| 408 | AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */ |
| 409 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 410 | /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */ |
| 411 | WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF); |
| 412 | WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF); |
| 413 | WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001); |
| 414 | WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 415 | } |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 416 | |
| 417 | void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable) |
| 418 | { |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 419 | struct drm_device *dev = encoder->dev; |
| 420 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 421 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 422 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 423 | |
Alex Deucher | c2b4cacf | 2013-07-08 18:16:56 -0400 | [diff] [blame] | 424 | if (!dig || !dig->afmt) |
| 425 | return; |
| 426 | |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 427 | /* Silent, r600_hdmi_enable will raise WARN for us */ |
| 428 | if (enable && dig->afmt->enabled) |
| 429 | return; |
| 430 | if (!enable && !dig->afmt->enabled) |
| 431 | return; |
| 432 | |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 433 | if (enable) { |
| 434 | if (ASIC_IS_DCE6(rdev)) |
| 435 | dig->afmt->pin = dce6_audio_get_pin(rdev); |
| 436 | else |
| 437 | dig->afmt->pin = r600_audio_get_pin(rdev); |
| 438 | } else { |
| 439 | dig->afmt->pin = NULL; |
| 440 | } |
| 441 | |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 442 | dig->afmt->enabled = enable; |
| 443 | |
| 444 | DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n", |
| 445 | enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id); |
| 446 | } |