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 | |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame^] | 35 | extern void dce6_afmt_write_sad_regs(struct drm_encoder *encoder); |
| 36 | extern void dce6_afmt_select_pin(struct drm_encoder *encoder); |
| 37 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 38 | /* |
| 39 | * update the N and CTS parameters for a given pixel clock rate |
| 40 | */ |
| 41 | static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock) |
| 42 | { |
| 43 | struct drm_device *dev = encoder->dev; |
| 44 | struct radeon_device *rdev = dev->dev_private; |
| 45 | struct radeon_hdmi_acr acr = r600_hdmi_acr(clock); |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 46 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 47 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 48 | uint32_t offset = dig->afmt->offset; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 49 | |
| 50 | WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz)); |
| 51 | WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz); |
| 52 | |
| 53 | WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz)); |
| 54 | WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz); |
| 55 | |
| 56 | WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz)); |
| 57 | WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz); |
| 58 | } |
| 59 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 60 | static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder) |
| 61 | { |
| 62 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 63 | struct drm_connector *connector; |
| 64 | struct radeon_connector *radeon_connector = NULL; |
| 65 | struct cea_sad *sads; |
| 66 | int i, sad_count; |
| 67 | |
| 68 | static const u16 eld_reg_to_type[][2] = { |
| 69 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM }, |
| 70 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 }, |
| 71 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 }, |
| 72 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 }, |
| 73 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 }, |
| 74 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC }, |
| 75 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS }, |
| 76 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC }, |
| 77 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 }, |
| 78 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD }, |
| 79 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP }, |
| 80 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO }, |
| 81 | }; |
| 82 | |
| 83 | list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { |
| 84 | if (connector->encoder == encoder) |
| 85 | radeon_connector = to_radeon_connector(connector); |
| 86 | } |
| 87 | |
| 88 | if (!radeon_connector) { |
| 89 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | sad_count = drm_edid_to_sad(radeon_connector->edid, &sads); |
| 94 | if (sad_count < 0) { |
| 95 | DRM_ERROR("Couldn't read SADs: %d\n", sad_count); |
| 96 | return; |
| 97 | } |
| 98 | BUG_ON(!sads); |
| 99 | |
| 100 | for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) { |
| 101 | u32 value = 0; |
| 102 | int j; |
| 103 | |
| 104 | for (j = 0; j < sad_count; j++) { |
| 105 | struct cea_sad *sad = &sads[j]; |
| 106 | |
| 107 | if (sad->format == eld_reg_to_type[i][1]) { |
| 108 | value = MAX_CHANNELS(sad->channels) | |
| 109 | DESCRIPTOR_BYTE_2(sad->byte2) | |
| 110 | SUPPORTED_FREQUENCIES(sad->freq); |
| 111 | if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM) |
| 112 | value |= SUPPORTED_FREQUENCIES_STEREO(sad->freq); |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | WREG32(eld_reg_to_type[i][0], value); |
| 117 | } |
| 118 | |
| 119 | kfree(sads); |
| 120 | } |
| 121 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 122 | /* |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 123 | * build a HDMI Video Info Frame |
| 124 | */ |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 125 | static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder, |
| 126 | void *buffer, size_t size) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 127 | { |
| 128 | struct drm_device *dev = encoder->dev; |
| 129 | struct radeon_device *rdev = dev->dev_private; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 130 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 131 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 132 | uint32_t offset = dig->afmt->offset; |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 133 | uint8_t *frame = buffer + 3; |
Alex Deucher | f100380 | 2013-06-07 10:41:03 -0400 | [diff] [blame] | 134 | uint8_t *header = buffer; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 135 | |
| 136 | WREG32(AFMT_AVI_INFO0 + offset, |
| 137 | frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24)); |
| 138 | WREG32(AFMT_AVI_INFO1 + offset, |
| 139 | frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24)); |
| 140 | WREG32(AFMT_AVI_INFO2 + offset, |
| 141 | frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); |
| 142 | WREG32(AFMT_AVI_INFO3 + offset, |
Alex Deucher | f100380 | 2013-06-07 10:41:03 -0400 | [diff] [blame] | 143 | frame[0xC] | (frame[0xD] << 8) | (header[1] << 24)); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 146 | static void evergreen_audio_set_dto(struct drm_encoder *encoder, u32 clock) |
| 147 | { |
| 148 | struct drm_device *dev = encoder->dev; |
| 149 | struct radeon_device *rdev = dev->dev_private; |
| 150 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 151 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 152 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
Alex Deucher | 731da21 | 2013-05-13 11:35:26 -0400 | [diff] [blame] | 153 | u32 base_rate = 24000; |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 154 | u32 max_ratio = clock / base_rate; |
| 155 | u32 dto_phase; |
| 156 | u32 dto_modulo = clock; |
| 157 | u32 wallclock_ratio; |
| 158 | u32 dto_cntl; |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 159 | |
| 160 | if (!dig || !dig->afmt) |
| 161 | return; |
| 162 | |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame^] | 163 | if (ASIC_IS_DCE6(rdev)) { |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 164 | dto_phase = 24 * 1000; |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame^] | 165 | } else { |
| 166 | if (max_ratio >= 8) { |
| 167 | dto_phase = 192 * 1000; |
| 168 | wallclock_ratio = 3; |
| 169 | } else if (max_ratio >= 4) { |
| 170 | dto_phase = 96 * 1000; |
| 171 | wallclock_ratio = 2; |
| 172 | } else if (max_ratio >= 2) { |
| 173 | dto_phase = 48 * 1000; |
| 174 | wallclock_ratio = 1; |
| 175 | } else { |
| 176 | dto_phase = 24 * 1000; |
| 177 | wallclock_ratio = 0; |
| 178 | } |
| 179 | dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK; |
| 180 | dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio); |
| 181 | WREG32(DCCG_AUDIO_DTO0_CNTL, dto_cntl); |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 182 | } |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 183 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 184 | /* XXX two dtos; generally use dto0 for hdmi */ |
| 185 | /* Express [24MHz / target pixel clock] as an exact rational |
| 186 | * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE |
| 187 | * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator |
| 188 | */ |
Alex Deucher | 7d61d83 | 2013-07-26 13:26:05 -0400 | [diff] [blame] | 189 | 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] | 190 | WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase); |
| 191 | WREG32(DCCG_AUDIO_DTO0_MODULE, dto_modulo); |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 195 | /* |
| 196 | * update the info frames with the data from the current display mode |
| 197 | */ |
| 198 | void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode) |
| 199 | { |
| 200 | struct drm_device *dev = encoder->dev; |
| 201 | struct radeon_device *rdev = dev->dev_private; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 202 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 203 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 204 | u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; |
| 205 | struct hdmi_avi_infoframe frame; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 206 | uint32_t offset; |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 207 | ssize_t err; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 208 | |
Alex Deucher | c2b4cacf | 2013-07-08 18:16:56 -0400 | [diff] [blame] | 209 | if (!dig || !dig->afmt) |
| 210 | return; |
| 211 | |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 212 | /* Silent, r600_hdmi_enable will raise WARN for us */ |
| 213 | if (!dig->afmt->enabled) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 214 | return; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 215 | offset = dig->afmt->offset; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 216 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 217 | evergreen_audio_set_dto(encoder, mode->clock); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 218 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 219 | WREG32(HDMI_VBI_PACKET_CONTROL + offset, |
| 220 | HDMI_NULL_SEND); /* send null packets when required */ |
| 221 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 222 | WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 223 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 224 | WREG32(HDMI_VBI_PACKET_CONTROL + offset, |
| 225 | HDMI_NULL_SEND | /* send null packets when required */ |
| 226 | HDMI_GC_SEND | /* send general control packets */ |
| 227 | HDMI_GC_CONT); /* send general control packets every frame */ |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 228 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 229 | WREG32(HDMI_INFOFRAME_CONTROL0 + offset, |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 230 | HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ |
| 231 | HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */ |
| 232 | |
| 233 | WREG32(AFMT_INFOFRAME_CONTROL0 + offset, |
| 234 | AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */ |
| 235 | |
| 236 | WREG32(HDMI_INFOFRAME_CONTROL1 + offset, |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 237 | HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */ |
| 238 | |
| 239 | WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */ |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 240 | |
Rafał Miłecki | 91a4401 | 2013-04-18 09:26:08 -0400 | [diff] [blame] | 241 | WREG32(HDMI_AUDIO_PACKET_CONTROL + offset, |
| 242 | HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */ |
| 243 | HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */ |
| 244 | |
| 245 | WREG32(AFMT_AUDIO_PACKET_CONTROL + offset, |
| 246 | AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */ |
| 247 | |
| 248 | /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */ |
| 249 | |
| 250 | WREG32(HDMI_ACR_PACKET_CONTROL + offset, |
| 251 | HDMI_ACR_AUTO_SEND | /* allow hw to sent ACR packets when required */ |
| 252 | HDMI_ACR_SOURCE); /* select SW CTS value */ |
| 253 | |
| 254 | evergreen_hdmi_update_ACR(encoder, mode->clock); |
| 255 | |
Rafał Miłecki | f93e3fc | 2013-04-14 01:26:24 +0200 | [diff] [blame] | 256 | WREG32(AFMT_60958_0 + offset, |
| 257 | AFMT_60958_CS_CHANNEL_NUMBER_L(1)); |
| 258 | |
| 259 | WREG32(AFMT_60958_1 + offset, |
| 260 | AFMT_60958_CS_CHANNEL_NUMBER_R(2)); |
| 261 | |
| 262 | WREG32(AFMT_60958_2 + offset, |
| 263 | AFMT_60958_CS_CHANNEL_NUMBER_2(3) | |
| 264 | AFMT_60958_CS_CHANNEL_NUMBER_3(4) | |
| 265 | AFMT_60958_CS_CHANNEL_NUMBER_4(5) | |
| 266 | AFMT_60958_CS_CHANNEL_NUMBER_5(6) | |
| 267 | AFMT_60958_CS_CHANNEL_NUMBER_6(7) | |
| 268 | AFMT_60958_CS_CHANNEL_NUMBER_7(8)); |
| 269 | |
| 270 | /* fglrx sets 0x0001005f | (x & 0x00fc0000) in 0x5f78 here */ |
| 271 | |
| 272 | WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset, |
| 273 | AFMT_AUDIO_CHANNEL_ENABLE(0xff)); |
| 274 | |
| 275 | /* fglrx sets 0x40 in 0x5f80 here */ |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame^] | 276 | |
| 277 | if (ASIC_IS_DCE6(rdev)) { |
| 278 | dce6_afmt_select_pin(encoder); |
| 279 | dce6_afmt_write_sad_regs(encoder); |
| 280 | } else { |
| 281 | evergreen_hdmi_write_sad_regs(encoder); |
| 282 | } |
Rafał Miłecki | f93e3fc | 2013-04-14 01:26:24 +0200 | [diff] [blame] | 283 | |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 284 | err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); |
| 285 | if (err < 0) { |
| 286 | DRM_ERROR("failed to setup AVI infoframe: %zd\n", err); |
| 287 | return; |
| 288 | } |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 289 | |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 290 | err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 291 | if (err < 0) { |
| 292 | DRM_ERROR("failed to pack AVI infoframe: %zd\n", err); |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer)); |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 297 | |
Rafał Miłecki | d3418ea | 2013-04-18 09:23:12 -0400 | [diff] [blame] | 298 | WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset, |
| 299 | HDMI_AVI_INFO_SEND | /* enable AVI info frames */ |
| 300 | HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */ |
| 301 | |
| 302 | WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, |
| 303 | HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ |
| 304 | ~HDMI_AVI_INFO_LINE_MASK); |
| 305 | |
| 306 | WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset, |
| 307 | AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */ |
| 308 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 309 | /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */ |
| 310 | WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF); |
| 311 | WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF); |
| 312 | WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001); |
| 313 | WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 314 | } |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 315 | |
| 316 | void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable) |
| 317 | { |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame^] | 318 | struct drm_device *dev = encoder->dev; |
| 319 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 320 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 321 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 322 | |
Alex Deucher | c2b4cacf | 2013-07-08 18:16:56 -0400 | [diff] [blame] | 323 | if (!dig || !dig->afmt) |
| 324 | return; |
| 325 | |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 326 | /* Silent, r600_hdmi_enable will raise WARN for us */ |
| 327 | if (enable && dig->afmt->enabled) |
| 328 | return; |
| 329 | if (!enable && !dig->afmt->enabled) |
| 330 | return; |
| 331 | |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame^] | 332 | if (enable) { |
| 333 | if (ASIC_IS_DCE6(rdev)) |
| 334 | dig->afmt->pin = dce6_audio_get_pin(rdev); |
| 335 | else |
| 336 | dig->afmt->pin = r600_audio_get_pin(rdev); |
| 337 | } else { |
| 338 | dig->afmt->pin = NULL; |
| 339 | } |
| 340 | |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 341 | dig->afmt->enabled = enable; |
| 342 | |
| 343 | DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n", |
| 344 | enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id); |
| 345 | } |