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 | |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 67 | void evergreen_hdmi_update_acr(struct drm_encoder *encoder, long offset, |
| 68 | const struct radeon_hdmi_acr *acr) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 69 | { |
| 70 | struct drm_device *dev = encoder->dev; |
| 71 | struct radeon_device *rdev = dev->dev_private; |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 72 | int bpc = 8; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 73 | |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 74 | if (encoder->crtc) { |
| 75 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); |
| 76 | bpc = radeon_crtc->bpc; |
| 77 | } |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 78 | |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 79 | if (bpc > 8) |
| 80 | WREG32(HDMI_ACR_PACKET_CONTROL + offset, |
| 81 | HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */ |
| 82 | else |
| 83 | WREG32(HDMI_ACR_PACKET_CONTROL + offset, |
| 84 | HDMI_ACR_SOURCE | /* select SW CTS value */ |
| 85 | HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */ |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 86 | |
Slava Grigorev | 64424d6e | 2014-12-06 20:19:16 -0500 | [diff] [blame] | 87 | WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr->cts_32khz)); |
| 88 | WREG32(HDMI_ACR_32_1 + offset, acr->n_32khz); |
| 89 | |
| 90 | WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr->cts_44_1khz)); |
| 91 | WREG32(HDMI_ACR_44_1 + offset, acr->n_44_1khz); |
| 92 | |
| 93 | WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr->cts_48khz)); |
| 94 | WREG32(HDMI_ACR_48_1 + offset, acr->n_48khz); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 97 | void dce4_afmt_write_latency_fields(struct drm_encoder *encoder, |
| 98 | struct drm_connector *connector, struct drm_display_mode *mode) |
Alex Deucher | 712fd8a | 2013-10-10 17:54:51 -0400 | [diff] [blame] | 99 | { |
| 100 | struct radeon_device *rdev = encoder->dev->dev_private; |
Alex Deucher | 712fd8a | 2013-10-10 17:54:51 -0400 | [diff] [blame] | 101 | u32 tmp = 0; |
| 102 | |
Alex Deucher | 712fd8a | 2013-10-10 17:54:51 -0400 | [diff] [blame] | 103 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 104 | if (connector->latency_present[1]) |
| 105 | tmp = VIDEO_LIPSYNC(connector->video_latency[1]) | |
| 106 | AUDIO_LIPSYNC(connector->audio_latency[1]); |
| 107 | else |
| 108 | tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255); |
| 109 | } else { |
| 110 | if (connector->latency_present[0]) |
| 111 | tmp = VIDEO_LIPSYNC(connector->video_latency[0]) | |
| 112 | AUDIO_LIPSYNC(connector->audio_latency[0]); |
| 113 | else |
| 114 | tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255); |
| 115 | } |
Slava Grigorev | 87654f8 | 2014-12-02 11:20:48 -0500 | [diff] [blame] | 116 | WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp); |
Alex Deucher | 712fd8a | 2013-10-10 17:54:51 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 119 | void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder, |
| 120 | u8 *sadb, int sad_count) |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 121 | { |
| 122 | struct radeon_device *rdev = encoder->dev->dev_private; |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 123 | u32 tmp; |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 124 | |
| 125 | /* program the speaker allocation */ |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 126 | tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER); |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 127 | tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK); |
| 128 | /* set HDMI mode */ |
| 129 | tmp |= HDMI_CONNECTION; |
| 130 | if (sad_count) |
| 131 | tmp |= SPEAKER_ALLOCATION(sadb[0]); |
| 132 | else |
| 133 | tmp |= SPEAKER_ALLOCATION(5); /* stereo */ |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 134 | WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp); |
| 135 | } |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 136 | |
Slava Grigorev | 00a9d4b | 2014-12-01 18:02:57 -0500 | [diff] [blame] | 137 | void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder, |
| 138 | u8 *sadb, int sad_count) |
| 139 | { |
| 140 | struct radeon_device *rdev = encoder->dev->dev_private; |
| 141 | u32 tmp; |
| 142 | |
| 143 | /* program the speaker allocation */ |
| 144 | tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER); |
| 145 | tmp &= ~(HDMI_CONNECTION | SPEAKER_ALLOCATION_MASK); |
| 146 | /* set DP mode */ |
| 147 | tmp |= DP_CONNECTION; |
| 148 | if (sad_count) |
| 149 | tmp |= SPEAKER_ALLOCATION(sadb[0]); |
| 150 | else |
| 151 | tmp |= SPEAKER_ALLOCATION(5); /* stereo */ |
| 152 | WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp); |
Alex Deucher | ba7def4 | 2013-08-15 09:34:07 -0400 | [diff] [blame] | 153 | } |
| 154 | |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 155 | void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder, |
| 156 | struct cea_sad *sads, int sad_count) |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 157 | { |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 158 | int i; |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 159 | struct radeon_device *rdev = encoder->dev->dev_private; |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 160 | static const u16 eld_reg_to_type[][2] = { |
| 161 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM }, |
| 162 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 }, |
| 163 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 }, |
| 164 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 }, |
| 165 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 }, |
| 166 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC }, |
| 167 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS }, |
| 168 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC }, |
| 169 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 }, |
| 170 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD }, |
| 171 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP }, |
| 172 | { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO }, |
| 173 | }; |
| 174 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 175 | for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) { |
| 176 | u32 value = 0; |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame] | 177 | u8 stereo_freqs = 0; |
| 178 | int max_channels = -1; |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 179 | int j; |
| 180 | |
| 181 | for (j = 0; j < sad_count; j++) { |
| 182 | struct cea_sad *sad = &sads[j]; |
| 183 | |
| 184 | if (sad->format == eld_reg_to_type[i][1]) { |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame] | 185 | if (sad->channels > max_channels) { |
| 186 | value = MAX_CHANNELS(sad->channels) | |
| 187 | DESCRIPTOR_BYTE_2(sad->byte2) | |
| 188 | SUPPORTED_FREQUENCIES(sad->freq); |
| 189 | max_channels = sad->channels; |
| 190 | } |
| 191 | |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 192 | if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM) |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame] | 193 | stereo_freqs |= sad->freq; |
| 194 | else |
| 195 | break; |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 196 | } |
| 197 | } |
Anssi Hannula | 0f57bca | 2013-10-29 01:19:16 +0200 | [diff] [blame] | 198 | |
| 199 | value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs); |
| 200 | |
Alex Deucher | 070a2e6 | 2015-01-22 10:41:55 -0500 | [diff] [blame] | 201 | WREG32_ENDPOINT(0, eld_reg_to_type[i][0], value); |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 202 | } |
Rafał Miłecki | 46892ca | 2013-04-19 19:01:26 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 205 | /* |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 206 | * build a AVI Info Frame |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 207 | */ |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 208 | void evergreen_set_avi_packet(struct radeon_device *rdev, u32 offset, |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 209 | unsigned char *buffer, size_t size) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 210 | { |
Thierry Reding | e3b2e03 | 2013-01-14 13:36:30 +0100 | [diff] [blame] | 211 | uint8_t *frame = buffer + 3; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 212 | |
| 213 | WREG32(AFMT_AVI_INFO0 + offset, |
| 214 | frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24)); |
| 215 | WREG32(AFMT_AVI_INFO1 + offset, |
| 216 | frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24)); |
| 217 | WREG32(AFMT_AVI_INFO2 + offset, |
| 218 | frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); |
| 219 | WREG32(AFMT_AVI_INFO3 + offset, |
Slava Grigorev | 96ea7af | 2014-12-05 17:59:56 -0500 | [diff] [blame] | 220 | frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24)); |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 221 | |
Slava Grigorev | baa7d8e | 2014-12-08 18:28:33 -0500 | [diff] [blame] | 222 | WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, |
Alex Deucher | 304f07e | 2015-03-31 10:33:05 -0400 | [diff] [blame] | 223 | HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ |
| 224 | ~HDMI_AVI_INFO_LINE_MASK); |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 227 | void dce4_hdmi_audio_set_dto(struct radeon_device *rdev, |
| 228 | struct radeon_crtc *crtc, unsigned int clock) |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 229 | { |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 230 | unsigned int max_ratio = clock / 24000; |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 231 | u32 dto_phase; |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 232 | u32 wallclock_ratio; |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 233 | u32 value; |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 234 | |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 235 | if (max_ratio >= 8) { |
| 236 | dto_phase = 192 * 1000; |
| 237 | wallclock_ratio = 3; |
| 238 | } else if (max_ratio >= 4) { |
| 239 | dto_phase = 96 * 1000; |
| 240 | wallclock_ratio = 2; |
| 241 | } else if (max_ratio >= 2) { |
| 242 | dto_phase = 48 * 1000; |
| 243 | wallclock_ratio = 1; |
Alex Deucher | b530602 | 2013-07-31 16:51:33 -0400 | [diff] [blame] | 244 | } else { |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 245 | dto_phase = 24 * 1000; |
| 246 | wallclock_ratio = 0; |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 247 | } |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 248 | |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 249 | value = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK; |
| 250 | value |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio); |
| 251 | value &= ~DCCG_AUDIO_DTO1_USE_512FBR_DTO; |
| 252 | WREG32(DCCG_AUDIO_DTO0_CNTL, value); |
| 253 | |
| 254 | /* Two dtos; generally use dto0 for HDMI */ |
| 255 | value = 0; |
| 256 | |
| 257 | if (crtc) |
| 258 | value |= DCCG_AUDIO_DTO0_SOURCE_SEL(crtc->crtc_id); |
| 259 | |
| 260 | WREG32(DCCG_AUDIO_DTO_SOURCE, value); |
| 261 | |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 262 | /* Express [24MHz / target pixel clock] as an exact rational |
| 263 | * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE |
| 264 | * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator |
| 265 | */ |
Alex Deucher | 1518dd8 | 2013-07-30 17:31:07 -0400 | [diff] [blame] | 266 | WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase); |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 267 | WREG32(DCCG_AUDIO_DTO0_MODULE, clock); |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 268 | } |
| 269 | |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 270 | void dce4_dp_audio_set_dto(struct radeon_device *rdev, |
Alex Deucher | aeefd07 | 2015-02-27 14:43:47 -0500 | [diff] [blame] | 271 | struct radeon_crtc *crtc, unsigned int clock) |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 272 | { |
| 273 | u32 value; |
| 274 | |
| 275 | value = RREG32(DCCG_AUDIO_DTO1_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK; |
| 276 | value |= DCCG_AUDIO_DTO1_USE_512FBR_DTO; |
| 277 | WREG32(DCCG_AUDIO_DTO1_CNTL, value); |
| 278 | |
| 279 | /* Two dtos; generally use dto1 for DP */ |
| 280 | value = 0; |
| 281 | value |= DCCG_AUDIO_DTO_SEL; |
| 282 | |
| 283 | if (crtc) |
| 284 | value |= DCCG_AUDIO_DTO0_SOURCE_SEL(crtc->crtc_id); |
| 285 | |
| 286 | WREG32(DCCG_AUDIO_DTO_SOURCE, value); |
| 287 | |
| 288 | /* Express [24MHz / target pixel clock] as an exact rational |
| 289 | * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE |
| 290 | * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator |
| 291 | */ |
| 292 | WREG32(DCCG_AUDIO_DTO1_PHASE, 24000); |
Alex Deucher | aeefd07 | 2015-02-27 14:43:47 -0500 | [diff] [blame] | 293 | WREG32(DCCG_AUDIO_DTO1_MODULE, clock); |
Slava Grigorev | a85d682 | 2014-12-05 13:38:31 -0500 | [diff] [blame] | 294 | } |
Alex Deucher | b1f6f47 | 2013-04-18 10:50:55 -0400 | [diff] [blame] | 295 | |
Alex Deucher | 930a978 | 2015-01-20 19:20:52 -0500 | [diff] [blame] | 296 | void dce4_set_vbi_packet(struct drm_encoder *encoder, u32 offset) |
| 297 | { |
| 298 | struct drm_device *dev = encoder->dev; |
| 299 | struct radeon_device *rdev = dev->dev_private; |
| 300 | |
| 301 | WREG32(HDMI_VBI_PACKET_CONTROL + offset, |
| 302 | HDMI_NULL_SEND | /* send null packets when required */ |
| 303 | HDMI_GC_SEND | /* send general control packets */ |
| 304 | HDMI_GC_CONT); /* send general control packets every frame */ |
| 305 | } |
| 306 | |
Slava Grigorev | be273e58 | 2014-12-08 16:25:37 -0500 | [diff] [blame] | 307 | void dce4_hdmi_set_color_depth(struct drm_encoder *encoder, u32 offset, int bpc) |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 308 | { |
| 309 | struct drm_device *dev = encoder->dev; |
| 310 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | 7976691 | 2014-05-28 19:02:31 -0400 | [diff] [blame] | 311 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 312 | uint32_t val; |
Rafał Miłecki | e55d3e6 | 2012-05-06 17:29:44 +0200 | [diff] [blame] | 313 | |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 314 | val = RREG32(HDMI_CONTROL + offset); |
| 315 | val &= ~HDMI_DEEP_COLOR_ENABLE; |
| 316 | val &= ~HDMI_DEEP_COLOR_DEPTH_MASK; |
| 317 | |
| 318 | switch (bpc) { |
| 319 | case 0: |
| 320 | case 6: |
| 321 | case 8: |
| 322 | case 16: |
| 323 | default: |
| 324 | DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n", |
Jani Nikula | 7208209 | 2014-06-03 14:56:19 +0300 | [diff] [blame] | 325 | connector->name, bpc); |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 326 | break; |
| 327 | case 10: |
| 328 | val |= HDMI_DEEP_COLOR_ENABLE; |
| 329 | val |= HDMI_DEEP_COLOR_DEPTH(HDMI_30BIT_DEEP_COLOR); |
| 330 | DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n", |
Jani Nikula | 7208209 | 2014-06-03 14:56:19 +0300 | [diff] [blame] | 331 | connector->name); |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 332 | break; |
| 333 | case 12: |
| 334 | val |= HDMI_DEEP_COLOR_ENABLE; |
| 335 | val |= HDMI_DEEP_COLOR_DEPTH(HDMI_36BIT_DEEP_COLOR); |
| 336 | DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n", |
Jani Nikula | 7208209 | 2014-06-03 14:56:19 +0300 | [diff] [blame] | 337 | connector->name); |
Alex Deucher | 7b555e0 | 2014-05-28 19:14:36 -0400 | [diff] [blame] | 338 | break; |
| 339 | } |
| 340 | |
| 341 | WREG32(HDMI_CONTROL + offset, val); |
Slava Grigorev | be273e58 | 2014-12-08 16:25:37 -0500 | [diff] [blame] | 342 | } |
| 343 | |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 344 | void dce4_set_audio_packet(struct drm_encoder *encoder, u32 offset) |
| 345 | { |
| 346 | struct drm_device *dev = encoder->dev; |
| 347 | struct radeon_device *rdev = dev->dev_private; |
| 348 | |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 349 | WREG32(AFMT_INFOFRAME_CONTROL0 + offset, |
| 350 | AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */ |
| 351 | |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 352 | WREG32(AFMT_60958_0 + offset, |
| 353 | AFMT_60958_CS_CHANNEL_NUMBER_L(1)); |
| 354 | |
| 355 | WREG32(AFMT_60958_1 + offset, |
| 356 | AFMT_60958_CS_CHANNEL_NUMBER_R(2)); |
| 357 | |
| 358 | WREG32(AFMT_60958_2 + offset, |
| 359 | AFMT_60958_CS_CHANNEL_NUMBER_2(3) | |
| 360 | AFMT_60958_CS_CHANNEL_NUMBER_3(4) | |
| 361 | AFMT_60958_CS_CHANNEL_NUMBER_4(5) | |
| 362 | AFMT_60958_CS_CHANNEL_NUMBER_5(6) | |
| 363 | AFMT_60958_CS_CHANNEL_NUMBER_6(7) | |
| 364 | AFMT_60958_CS_CHANNEL_NUMBER_7(8)); |
| 365 | |
| 366 | WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset, |
| 367 | AFMT_AUDIO_CHANNEL_ENABLE(0xff)); |
| 368 | |
Alex Deucher | 362ff25 | 2015-03-31 11:43:12 -0400 | [diff] [blame] | 369 | WREG32(HDMI_AUDIO_PACKET_CONTROL + offset, |
| 370 | HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */ |
| 371 | HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */ |
| 372 | |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 373 | /* allow 60958 channel status and send audio packets fields to be updated */ |
Alex Deucher | 362ff25 | 2015-03-31 11:43:12 -0400 | [diff] [blame] | 374 | WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset, |
| 375 | AFMT_RESET_FIFO_WHEN_AUDIO_DIS | AFMT_60958_CS_UPDATE); |
Slava Grigorev | 1852c9a | 2014-12-09 16:44:18 -0500 | [diff] [blame] | 376 | } |
| 377 | |
Slava Grigorev | 3be2e7d | 2014-12-09 17:17:35 -0500 | [diff] [blame] | 378 | |
| 379 | void dce4_set_mute(struct drm_encoder *encoder, u32 offset, bool mute) |
| 380 | { |
| 381 | struct drm_device *dev = encoder->dev; |
| 382 | struct radeon_device *rdev = dev->dev_private; |
| 383 | |
| 384 | if (mute) |
| 385 | WREG32_OR(HDMI_GC + offset, HDMI_GC_AVMUTE); |
| 386 | else |
| 387 | WREG32_AND(HDMI_GC + offset, ~HDMI_GC_AVMUTE); |
| 388 | } |
| 389 | |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 390 | void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable) |
| 391 | { |
Alex Deucher | 4adb34e | 2014-09-18 18:07:08 -0400 | [diff] [blame] | 392 | struct drm_device *dev = encoder->dev; |
| 393 | struct radeon_device *rdev = dev->dev_private; |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 394 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 395 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
| 396 | |
Alex Deucher | c2b4cacf | 2013-07-08 18:16:56 -0400 | [diff] [blame] | 397 | if (!dig || !dig->afmt) |
| 398 | return; |
| 399 | |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 400 | if (enable) { |
Alex Deucher | 38aef15 | 2015-04-07 10:20:49 -0400 | [diff] [blame] | 401 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
| 402 | |
| 403 | if (drm_detect_monitor_audio(radeon_connector_edid(connector))) { |
| 404 | WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, |
| 405 | HDMI_AVI_INFO_SEND | /* enable AVI info frames */ |
| 406 | HDMI_AVI_INFO_CONT | /* required for audio info values to be updated */ |
| 407 | HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ |
| 408 | HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */ |
| 409 | WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, |
| 410 | AFMT_AUDIO_SAMPLE_SEND); |
| 411 | } else { |
| 412 | WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, |
| 413 | HDMI_AVI_INFO_SEND | /* enable AVI info frames */ |
| 414 | HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */ |
| 415 | WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, |
| 416 | ~AFMT_AUDIO_SAMPLE_SEND); |
| 417 | } |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 418 | } else { |
Alex Deucher | 362ff25 | 2015-03-31 11:43:12 -0400 | [diff] [blame] | 419 | WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, |
| 420 | ~AFMT_AUDIO_SAMPLE_SEND); |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 421 | WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, 0); |
Alex Deucher | 4adb34e | 2014-09-18 18:07:08 -0400 | [diff] [blame] | 422 | } |
| 423 | |
Alex Deucher | a973bea | 2013-04-18 11:32:16 -0400 | [diff] [blame] | 424 | dig->afmt->enabled = enable; |
| 425 | |
| 426 | DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n", |
| 427 | enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id); |
| 428 | } |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 429 | |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 430 | void evergreen_dp_enable(struct drm_encoder *encoder, bool enable) |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 431 | { |
| 432 | struct drm_device *dev = encoder->dev; |
| 433 | struct radeon_device *rdev = dev->dev_private; |
| 434 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 435 | struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; |
Alex Deucher | 38aef15 | 2015-04-07 10:20:49 -0400 | [diff] [blame] | 436 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 437 | |
| 438 | if (!dig || !dig->afmt) |
| 439 | return; |
| 440 | |
Alex Deucher | 38aef15 | 2015-04-07 10:20:49 -0400 | [diff] [blame] | 441 | if (enable && drm_detect_monitor_audio(radeon_connector_edid(connector))) { |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 442 | struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); |
| 443 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
| 444 | struct radeon_connector_atom_dig *dig_connector; |
| 445 | uint32_t val; |
| 446 | |
Alex Deucher | 362ff25 | 2015-03-31 11:43:12 -0400 | [diff] [blame] | 447 | WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, |
| 448 | AFMT_AUDIO_SAMPLE_SEND); |
| 449 | |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 450 | WREG32(EVERGREEN_DP_SEC_TIMESTAMP + dig->afmt->offset, |
| 451 | EVERGREEN_DP_SEC_TIMESTAMP_MODE(1)); |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 452 | |
Alex Deucher | 1242832 | 2015-03-31 11:38:48 -0400 | [diff] [blame] | 453 | if (!ASIC_IS_DCE6(rdev) && radeon_connector->con_priv) { |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 454 | dig_connector = radeon_connector->con_priv; |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 455 | val = RREG32(EVERGREEN_DP_SEC_AUD_N + dig->afmt->offset); |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 456 | val &= ~EVERGREEN_DP_SEC_N_BASE_MULTIPLE(0xf); |
| 457 | |
| 458 | if (dig_connector->dp_clock == 162000) |
| 459 | val |= EVERGREEN_DP_SEC_N_BASE_MULTIPLE(3); |
| 460 | else |
| 461 | val |= EVERGREEN_DP_SEC_N_BASE_MULTIPLE(5); |
| 462 | |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 463 | WREG32(EVERGREEN_DP_SEC_AUD_N + dig->afmt->offset, val); |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 464 | } |
| 465 | |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 466 | WREG32(EVERGREEN_DP_SEC_CNTL + dig->afmt->offset, |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 467 | EVERGREEN_DP_SEC_ASP_ENABLE | /* Audio packet transmission */ |
| 468 | EVERGREEN_DP_SEC_ATP_ENABLE | /* Audio timestamp packet transmission */ |
| 469 | EVERGREEN_DP_SEC_AIP_ENABLE | /* Audio infoframe packet transmission */ |
| 470 | EVERGREEN_DP_SEC_STREAM_ENABLE); /* Master enable for secondary stream engine */ |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 471 | } else { |
Alex Deucher | add7d75 | 2015-02-27 10:04:11 -0500 | [diff] [blame] | 472 | WREG32(EVERGREEN_DP_SEC_CNTL + dig->afmt->offset, 0); |
Alex Deucher | 362ff25 | 2015-03-31 11:43:12 -0400 | [diff] [blame] | 473 | WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, |
| 474 | ~AFMT_AUDIO_SAMPLE_SEND); |
Slava Grigorev | e55bca2 | 2014-12-12 17:01:42 -0500 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | dig->afmt->enabled = enable; |
| 478 | } |