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