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 | |
Alex Deucher | d3d8c14 | 2014-09-18 17:26:39 -0400 | [diff] [blame^] | 41 | /* enable the audio stream */ |
| 42 | static void dce4_audio_enable(struct radeon_device *rdev, |
| 43 | struct r600_audio_pin *pin, |
| 44 | u8 enable_mask) |
| 45 | { |
| 46 | u32 tmp = RREG32(AZ_HOT_PLUG_CONTROL); |
| 47 | |
| 48 | if (!pin) |
| 49 | return; |
| 50 | |
| 51 | if (enable_mask) { |
| 52 | tmp |= AUDIO_ENABLED; |
| 53 | if (enable_mask & 1) |
| 54 | tmp |= PIN0_AUDIO_ENABLED; |
| 55 | if (enable_mask & 2) |
| 56 | tmp |= PIN1_AUDIO_ENABLED; |
| 57 | if (enable_mask & 4) |
| 58 | tmp |= PIN2_AUDIO_ENABLED; |
| 59 | if (enable_mask & 8) |
| 60 | tmp |= PIN3_AUDIO_ENABLED; |
| 61 | } else { |
| 62 | tmp &= ~(AUDIO_ENABLED | |
| 63 | PIN0_AUDIO_ENABLED | |
| 64 | PIN1_AUDIO_ENABLED | |
| 65 | PIN2_AUDIO_ENABLED | |
| 66 | PIN3_AUDIO_ENABLED); |
| 67 | } |
| 68 | |
| 69 | WREG32(AZ_HOT_PLUG_CONTROL, tmp); |
| 70 | } |
| 71 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 72 | /* |
| 73 | * update the N and CTS parameters for a given pixel clock rate |
| 74 | */ |
| 75 | static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock) |
| 76 | { |
| 77 | struct drm_device *dev = encoder->dev; |
| 78 | struct radeon_device *rdev = dev->dev_private; |
| 79 | struct radeon_hdmi_acr acr = r600_hdmi_acr(clock); |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 80 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 81 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 82 | uint32_t offset = dig->afmt->offset; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 83 | |
| 84 | WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz)); |
| 85 | WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz); |
| 86 | |
| 87 | WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz)); |
| 88 | WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz); |
| 89 | |
| 90 | WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz)); |
| 91 | WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz); |
| 92 | } |
| 93 | |
Alex Deucher | 712fd8a | 2013-10-10 17:54:51 -0400 | [diff] [blame] | 94 | static void dce4_afmt_write_latency_fields(struct drm_encoder *encoder, |
| 95 | struct drm_display_mode *mode) |
| 96 | { |
| 97 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 98 | struct drm_connector *connector; |
| 99 | struct radeon_connector *radeon_connector = NULL; |
| 100 | u32 tmp = 0; |
| 101 | |
| 102 | list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { |
| 103 | if (connector->encoder == encoder) { |
| 104 | radeon_connector = to_radeon_connector(connector); |
| 105 | break; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (!radeon_connector) { |
| 110 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 115 | if (connector->latency_present[1]) |
| 116 | tmp = VIDEO_LIPSYNC(connector->video_latency[1]) | |
| 117 | AUDIO_LIPSYNC(connector->audio_latency[1]); |
| 118 | else |
| 119 | tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255); |
| 120 | } else { |
| 121 | if (connector->latency_present[0]) |
| 122 | tmp = VIDEO_LIPSYNC(connector->video_latency[0]) | |
| 123 | AUDIO_LIPSYNC(connector->audio_latency[0]); |
| 124 | else |
| 125 | tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255); |
| 126 | } |
| 127 | WREG32(AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp); |
| 128 | } |
| 129 | |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 130 | static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder) |
| 131 | { |
| 132 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 133 | struct drm_connector *connector; |
| 134 | struct radeon_connector *radeon_connector = NULL; |
| 135 | u32 tmp; |
| 136 | u8 *sadb; |
| 137 | int sad_count; |
| 138 | |
| 139 | list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { |
Alex Deucher | 8a992ee | 2013-10-10 17:58:27 -0400 | [diff] [blame] | 140 | if (connector->encoder == encoder) { |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 141 | radeon_connector = to_radeon_connector(connector); |
Alex Deucher | 8a992ee | 2013-10-10 17:58:27 -0400 | [diff] [blame] | 142 | break; |
| 143 | } |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | if (!radeon_connector) { |
| 147 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 148 | return; |
| 149 | } |
| 150 | |
Alex Deucher | 377bd8a | 2014-07-15 11:00:47 -0400 | [diff] [blame] | 151 | sad_count = drm_edid_to_speaker_allocation(radeon_connector_edid(connector), &sadb); |
Alex Deucher | b67ce39 | 2013-12-13 09:05:49 -0500 | [diff] [blame] | 152 | if (sad_count <= 0) { |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 153 | DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | /* program the speaker allocation */ |
| 158 | tmp = RREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER); |
| 159 | tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK); |
| 160 | /* set HDMI mode */ |
| 161 | tmp |= HDMI_CONNECTION; |
| 162 | if (sad_count) |
| 163 | tmp |= SPEAKER_ALLOCATION(sadb[0]); |
| 164 | else |
| 165 | tmp |= SPEAKER_ALLOCATION(5); /* stereo */ |
| 166 | WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp); |
| 167 | |
| 168 | kfree(sadb); |
| 169 | } |
| 170 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 171 | static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder) |
| 172 | { |
| 173 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 174 | struct drm_connector *connector; |
| 175 | struct radeon_connector *radeon_connector = NULL; |
| 176 | struct cea_sad *sads; |
| 177 | int i, sad_count; |
| 178 | |
| 179 | static const u16 eld_reg_to_type[][2] = { |
| 180 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM }, |
| 181 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 }, |
| 182 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 }, |
| 183 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 }, |
| 184 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 }, |
| 185 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC }, |
| 186 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS }, |
| 187 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC }, |
| 188 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 }, |
| 189 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD }, |
| 190 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP }, |
| 191 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO }, |
| 192 | }; |
| 193 | |
| 194 | list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { |
Alex Deucher | 8a992ee | 2013-10-10 17:58:27 -0400 | [diff] [blame] | 195 | if (connector->encoder == encoder) { |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 196 | radeon_connector = to_radeon_connector(connector); |
Alex Deucher | 8a992ee | 2013-10-10 17:58:27 -0400 | [diff] [blame] | 197 | break; |
| 198 | } |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | if (!radeon_connector) { |
| 202 | DRM_ERROR("Couldn't find encoder's connector\n"); |
| 203 | return; |
| 204 | } |
| 205 | |
Alex Deucher | 377bd8a | 2014-07-15 11:00:47 -0400 | [diff] [blame] | 206 | sad_count = drm_edid_to_sad(radeon_connector_edid(connector), &sads); |
Alex Deucher | b67ce39 | 2013-12-13 09:05:49 -0500 | [diff] [blame] | 207 | if (sad_count <= 0) { |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 208 | DRM_ERROR("Couldn't read SADs: %d\n", sad_count); |
| 209 | return; |
| 210 | } |
| 211 | BUG_ON(!sads); |
| 212 | |
| 213 | for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) { |
| 214 | u32 value = 0; |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame] | 215 | u8 stereo_freqs = 0; |
| 216 | int max_channels = -1; |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 217 | int j; |
| 218 | |
| 219 | for (j = 0; j < sad_count; j++) { |
| 220 | struct cea_sad *sad = &sads[j]; |
| 221 | |
| 222 | if (sad->format == eld_reg_to_type[i][1]) { |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame] | 223 | if (sad->channels > max_channels) { |
| 224 | value = MAX_CHANNELS(sad->channels) | |
| 225 | DESCRIPTOR_BYTE_2(sad->byte2) | |
| 226 | SUPPORTED_FREQUENCIES(sad->freq); |
| 227 | max_channels = sad->channels; |
| 228 | } |
| 229 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 230 | if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM) |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame] | 231 | stereo_freqs |= sad->freq; |
| 232 | else |
| 233 | break; |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 234 | } |
| 235 | } |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame] | 236 | |
| 237 | value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs); |
| 238 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 239 | WREG32(eld_reg_to_type[i][0], value); |
| 240 | } |
| 241 | |
| 242 | kfree(sads); |
| 243 | } |
| 244 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 245 | /* |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 246 | * build a HDMI Video Info Frame |
| 247 | */ |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 248 | static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder, |
| 249 | void *buffer, size_t size) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 250 | { |
| 251 | struct drm_device *dev = encoder->dev; |
| 252 | struct radeon_device *rdev = dev->dev_private; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 253 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 254 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 255 | uint32_t offset = dig->afmt->offset; |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 256 | uint8_t *frame = buffer + 3; |
Alex Deucher | f100380 | 2013-06-07 10:41:03 -0400 | [diff] [blame] | 257 | uint8_t *header = buffer; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 258 | |
| 259 | WREG32(AFMT_AVI_INFO0 + offset, |
| 260 | frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24)); |
| 261 | WREG32(AFMT_AVI_INFO1 + offset, |
| 262 | frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24)); |
| 263 | WREG32(AFMT_AVI_INFO2 + offset, |
| 264 | frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); |
| 265 | WREG32(AFMT_AVI_INFO3 + offset, |
Alex Deucher | f100380 | 2013-06-07 10:41:03 -0400 | [diff] [blame] | 266 | frame[0xC] | (frame[0xD] << 8) | (header[1] << 24)); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 269 | static void evergreen_audio_set_dto(struct drm_encoder *encoder, u32 clock) |
| 270 | { |
| 271 | struct drm_device *dev = encoder->dev; |
| 272 | struct radeon_device *rdev = dev->dev_private; |
| 273 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 274 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 275 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
Alex Deucher | 731da21 | 2013-05-13 11:35:26 -0400 | [diff] [blame] | 276 | u32 base_rate = 24000; |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 277 | u32 max_ratio = clock / base_rate; |
| 278 | u32 dto_phase; |
| 279 | u32 dto_modulo = clock; |
| 280 | u32 wallclock_ratio; |
| 281 | u32 dto_cntl; |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 282 | |
| 283 | if (!dig || !dig->afmt) |
| 284 | return; |
| 285 | |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 286 | if (ASIC_IS_DCE6(rdev)) { |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 287 | dto_phase = 24 * 1000; |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 288 | } else { |
| 289 | if (max_ratio >= 8) { |
| 290 | dto_phase = 192 * 1000; |
| 291 | wallclock_ratio = 3; |
| 292 | } else if (max_ratio >= 4) { |
| 293 | dto_phase = 96 * 1000; |
| 294 | wallclock_ratio = 2; |
| 295 | } else if (max_ratio >= 2) { |
| 296 | dto_phase = 48 * 1000; |
| 297 | wallclock_ratio = 1; |
| 298 | } else { |
| 299 | dto_phase = 24 * 1000; |
| 300 | wallclock_ratio = 0; |
| 301 | } |
| 302 | dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK; |
| 303 | dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio); |
| 304 | WREG32(DCCG_AUDIO_DTO0_CNTL, dto_cntl); |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 305 | } |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 306 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 307 | /* XXX two dtos; generally use dto0 for hdmi */ |
| 308 | /* Express [24MHz / target pixel clock] as an exact rational |
| 309 | * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE |
| 310 | * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator |
| 311 | */ |
Alex Deucher | 7d61d83 | 2013-07-26 13:26:05 -0400 | [diff] [blame] | 312 | 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] | 313 | WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase); |
| 314 | WREG32(DCCG_AUDIO_DTO0_MODULE, dto_modulo); |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 318 | /* |
| 319 | * update the info frames with the data from the current display mode |
| 320 | */ |
| 321 | void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode) |
| 322 | { |
| 323 | struct drm_device *dev = encoder->dev; |
| 324 | struct radeon_device *rdev = dev->dev_private; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 325 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 326 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Alex Deucher | 7976691 | 2014-05-28 19:02:31 -0400 | [diff] [blame] | 327 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 328 | u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; |
| 329 | struct hdmi_avi_infoframe frame; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 330 | uint32_t offset; |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 331 | ssize_t err; |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 332 | uint32_t val; |
Alex Deucher | 7976691 | 2014-05-28 19:02:31 -0400 | [diff] [blame] | 333 | int bpc = 8; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 334 | |
Alex Deucher | c2b4cac | 2013-07-08 18:16:56 -0400 | [diff] [blame] | 335 | if (!dig || !dig->afmt) |
| 336 | return; |
| 337 | |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 338 | /* Silent, r600_hdmi_enable will raise WARN for us */ |
| 339 | if (!dig->afmt->enabled) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 340 | return; |
Rafał Miłecki | cfcbd6d | 2012-05-14 16:52:30 +0200 | [diff] [blame] | 341 | offset = dig->afmt->offset; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 342 | |
Alex Deucher | 7976691 | 2014-05-28 19:02:31 -0400 | [diff] [blame] | 343 | /* hdmi deep color mode general control packets setup, if bpc > 8 */ |
| 344 | if (encoder->crtc) { |
| 345 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
| 346 | bpc = radeon_crtc->bpc; |
| 347 | } |
| 348 | |
Alex Deucher | 832eafa | 2014-02-18 11:07:55 -0500 | [diff] [blame] | 349 | /* disable audio prior to setting up hw */ |
| 350 | if (ASIC_IS_DCE6(rdev)) { |
| 351 | dig->afmt->pin = dce6_audio_get_pin(rdev); |
Alex Deucher | d3d8c14 | 2014-09-18 17:26:39 -0400 | [diff] [blame^] | 352 | dce6_audio_enable(rdev, dig->afmt->pin, 0); |
Alex Deucher | 832eafa | 2014-02-18 11:07:55 -0500 | [diff] [blame] | 353 | } else { |
| 354 | dig->afmt->pin = r600_audio_get_pin(rdev); |
Alex Deucher | d3d8c14 | 2014-09-18 17:26:39 -0400 | [diff] [blame^] | 355 | dce4_audio_enable(rdev, dig->afmt->pin, 0); |
Alex Deucher | 832eafa | 2014-02-18 11:07:55 -0500 | [diff] [blame] | 356 | } |
| 357 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 358 | evergreen_audio_set_dto(encoder, mode->clock); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 359 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 360 | WREG32(HDMI_VBI_PACKET_CONTROL + offset, |
| 361 | HDMI_NULL_SEND); /* send null packets when required */ |
| 362 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 363 | WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 364 | |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 365 | val = RREG32(HDMI_CONTROL + offset); |
| 366 | val &= ~HDMI_DEEP_COLOR_ENABLE; |
| 367 | val &= ~HDMI_DEEP_COLOR_DEPTH_MASK; |
| 368 | |
| 369 | switch (bpc) { |
| 370 | case 0: |
| 371 | case 6: |
| 372 | case 8: |
| 373 | case 16: |
| 374 | default: |
| 375 | DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n", |
Jani Nikula | 7208209 | 2014-06-03 14:56:19 +0300 | [diff] [blame] | 376 | connector->name, bpc); |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 377 | break; |
| 378 | case 10: |
| 379 | val |= HDMI_DEEP_COLOR_ENABLE; |
| 380 | val |= HDMI_DEEP_COLOR_DEPTH(HDMI_30BIT_DEEP_COLOR); |
| 381 | DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n", |
Jani Nikula | 7208209 | 2014-06-03 14:56:19 +0300 | [diff] [blame] | 382 | connector->name); |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 383 | break; |
| 384 | case 12: |
| 385 | val |= HDMI_DEEP_COLOR_ENABLE; |
| 386 | val |= HDMI_DEEP_COLOR_DEPTH(HDMI_36BIT_DEEP_COLOR); |
| 387 | DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n", |
Jani Nikula | 7208209 | 2014-06-03 14:56:19 +0300 | [diff] [blame] | 388 | connector->name); |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 389 | break; |
| 390 | } |
| 391 | |
| 392 | WREG32(HDMI_CONTROL + offset, val); |
| 393 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 394 | WREG32(HDMI_VBI_PACKET_CONTROL + offset, |
| 395 | HDMI_NULL_SEND | /* send null packets when required */ |
| 396 | HDMI_GC_SEND | /* send general control packets */ |
| 397 | HDMI_GC_CONT); /* send general control packets every frame */ |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 398 | |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 399 | WREG32(HDMI_INFOFRAME_CONTROL0 + offset, |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 400 | HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ |
| 401 | HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */ |
| 402 | |
| 403 | WREG32(AFMT_INFOFRAME_CONTROL0 + offset, |
| 404 | AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */ |
| 405 | |
| 406 | WREG32(HDMI_INFOFRAME_CONTROL1 + offset, |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 407 | HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */ |
| 408 | |
| 409 | WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */ |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 410 | |
Rafał Miłecki | 91a4401 | 2013-04-18 09:26:08 -0400 | [diff] [blame] | 411 | WREG32(HDMI_AUDIO_PACKET_CONTROL + offset, |
| 412 | HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */ |
| 413 | HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */ |
| 414 | |
| 415 | WREG32(AFMT_AUDIO_PACKET_CONTROL + offset, |
| 416 | AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */ |
| 417 | |
| 418 | /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */ |
| 419 | |
Alex Deucher | 7976691 | 2014-05-28 19:02:31 -0400 | [diff] [blame] | 420 | if (bpc > 8) |
| 421 | WREG32(HDMI_ACR_PACKET_CONTROL + offset, |
| 422 | HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */ |
| 423 | else |
| 424 | WREG32(HDMI_ACR_PACKET_CONTROL + offset, |
| 425 | HDMI_ACR_SOURCE | /* select SW CTS value */ |
| 426 | 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] | 427 | |
| 428 | evergreen_hdmi_update_ACR(encoder, mode->clock); |
| 429 | |
Rafał Miłecki | f93e3fc | 2013-04-14 01:26:24 +0200 | [diff] [blame] | 430 | WREG32(AFMT_60958_0 + offset, |
| 431 | AFMT_60958_CS_CHANNEL_NUMBER_L(1)); |
| 432 | |
| 433 | WREG32(AFMT_60958_1 + offset, |
| 434 | AFMT_60958_CS_CHANNEL_NUMBER_R(2)); |
| 435 | |
| 436 | WREG32(AFMT_60958_2 + offset, |
| 437 | AFMT_60958_CS_CHANNEL_NUMBER_2(3) | |
| 438 | AFMT_60958_CS_CHANNEL_NUMBER_3(4) | |
| 439 | AFMT_60958_CS_CHANNEL_NUMBER_4(5) | |
| 440 | AFMT_60958_CS_CHANNEL_NUMBER_5(6) | |
| 441 | AFMT_60958_CS_CHANNEL_NUMBER_6(7) | |
| 442 | AFMT_60958_CS_CHANNEL_NUMBER_7(8)); |
| 443 | |
Rafał Miłecki | 6159b65 | 2013-08-15 11:16:30 +0200 | [diff] [blame] | 444 | if (ASIC_IS_DCE6(rdev)) { |
| 445 | dce6_afmt_write_speaker_allocation(encoder); |
| 446 | } else { |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 447 | dce4_afmt_write_speaker_allocation(encoder); |
Rafał Miłecki | 6159b65 | 2013-08-15 11:16:30 +0200 | [diff] [blame] | 448 | } |
Rafał Miłecki | f93e3fc | 2013-04-14 01:26:24 +0200 | [diff] [blame] | 449 | |
| 450 | WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset, |
| 451 | AFMT_AUDIO_CHANNEL_ENABLE(0xff)); |
| 452 | |
| 453 | /* fglrx sets 0x40 in 0x5f80 here */ |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 454 | |
| 455 | if (ASIC_IS_DCE6(rdev)) { |
| 456 | dce6_afmt_select_pin(encoder); |
| 457 | dce6_afmt_write_sad_regs(encoder); |
Alex Deucher | b188025 | 2013-10-10 18:03:06 -0400 | [diff] [blame] | 458 | dce6_afmt_write_latency_fields(encoder, mode); |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 459 | } else { |
| 460 | evergreen_hdmi_write_sad_regs(encoder); |
Alex Deucher | 712fd8a | 2013-10-10 17:54:51 -0400 | [diff] [blame] | 461 | dce4_afmt_write_latency_fields(encoder, mode); |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 462 | } |
Rafał Miłecki | f93e3fc | 2013-04-14 01:26:24 +0200 | [diff] [blame] | 463 | |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 464 | err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); |
| 465 | if (err < 0) { |
| 466 | DRM_ERROR("failed to setup AVI infoframe: %zd\n", err); |
| 467 | return; |
| 468 | } |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 469 | |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 470 | err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 471 | if (err < 0) { |
| 472 | DRM_ERROR("failed to pack AVI infoframe: %zd\n", err); |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer)); |
Rafał Miłecki | 1c3439f | 2012-05-06 17:29:45 +0200 | [diff] [blame] | 477 | |
Rafał Miłecki | d3418ea | 2013-04-18 09:23:12 -0400 | [diff] [blame] | 478 | WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset, |
| 479 | HDMI_AVI_INFO_SEND | /* enable AVI info frames */ |
| 480 | HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */ |
| 481 | |
| 482 | WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, |
| 483 | HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ |
| 484 | ~HDMI_AVI_INFO_LINE_MASK); |
| 485 | |
| 486 | WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset, |
| 487 | AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */ |
| 488 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 489 | /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */ |
| 490 | WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF); |
| 491 | WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF); |
| 492 | WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001); |
| 493 | WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001); |
Alex Deucher | 832eafa | 2014-02-18 11:07:55 -0500 | [diff] [blame] | 494 | |
| 495 | /* enable audio after to setting up hw */ |
| 496 | if (ASIC_IS_DCE6(rdev)) |
Alex Deucher | d3d8c14 | 2014-09-18 17:26:39 -0400 | [diff] [blame^] | 497 | dce6_audio_enable(rdev, dig->afmt->pin, 1); |
Alex Deucher | 832eafa | 2014-02-18 11:07:55 -0500 | [diff] [blame] | 498 | else |
Alex Deucher | d3d8c14 | 2014-09-18 17:26:39 -0400 | [diff] [blame^] | 499 | dce4_audio_enable(rdev, dig->afmt->pin, 0xf); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 500 | } |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 501 | |
| 502 | void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable) |
| 503 | { |
| 504 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 505 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 506 | |
Alex Deucher | c2b4cac | 2013-07-08 18:16:56 -0400 | [diff] [blame] | 507 | if (!dig || !dig->afmt) |
| 508 | return; |
| 509 | |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 510 | /* Silent, r600_hdmi_enable will raise WARN for us */ |
| 511 | if (enable && dig->afmt->enabled) |
| 512 | return; |
| 513 | if (!enable && !dig->afmt->enabled) |
| 514 | return; |
| 515 | |
| 516 | dig->afmt->enabled = enable; |
| 517 | |
| 518 | DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n", |
| 519 | enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id); |
| 520 | } |