1 1.1 riastrad /* $NetBSD: radeon_evergreen_hdmi.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2008 Advanced Micro Devices, Inc. 5 1.1 riastrad * Copyright 2008 Red Hat Inc. 6 1.1 riastrad * Copyright 2009 Christian Knig. 7 1.1 riastrad * 8 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 9 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 10 1.1 riastrad * to deal in the Software without restriction, including without limitation 11 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 13 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 14 1.1 riastrad * 15 1.1 riastrad * The above copyright notice and this permission notice shall be included in 16 1.1 riastrad * all copies or substantial portions of the Software. 17 1.1 riastrad * 18 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 25 1.1 riastrad * 26 1.1 riastrad * Authors: Christian Knig 27 1.1 riastrad * Rafa Miecki 28 1.1 riastrad */ 29 1.1 riastrad #include <sys/cdefs.h> 30 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_evergreen_hdmi.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $"); 31 1.1 riastrad 32 1.1 riastrad #include <linux/hdmi.h> 33 1.2 riastrad 34 1.1 riastrad #include <drm/radeon_drm.h> 35 1.1 riastrad #include "radeon.h" 36 1.1 riastrad #include "radeon_asic.h" 37 1.1 riastrad #include "radeon_audio.h" 38 1.1 riastrad #include "evergreend.h" 39 1.1 riastrad #include "atom.h" 40 1.1 riastrad 41 1.1 riastrad /* enable the audio stream */ 42 1.1 riastrad void dce4_audio_enable(struct radeon_device *rdev, 43 1.1 riastrad struct r600_audio_pin *pin, 44 1.1 riastrad u8 enable_mask) 45 1.1 riastrad { 46 1.1 riastrad u32 tmp = RREG32(AZ_HOT_PLUG_CONTROL); 47 1.1 riastrad 48 1.1 riastrad if (!pin) 49 1.1 riastrad return; 50 1.1 riastrad 51 1.1 riastrad if (enable_mask) { 52 1.1 riastrad tmp |= AUDIO_ENABLED; 53 1.1 riastrad if (enable_mask & 1) 54 1.1 riastrad tmp |= PIN0_AUDIO_ENABLED; 55 1.1 riastrad if (enable_mask & 2) 56 1.1 riastrad tmp |= PIN1_AUDIO_ENABLED; 57 1.1 riastrad if (enable_mask & 4) 58 1.1 riastrad tmp |= PIN2_AUDIO_ENABLED; 59 1.1 riastrad if (enable_mask & 8) 60 1.1 riastrad tmp |= PIN3_AUDIO_ENABLED; 61 1.1 riastrad } else { 62 1.1 riastrad tmp &= ~(AUDIO_ENABLED | 63 1.1 riastrad PIN0_AUDIO_ENABLED | 64 1.1 riastrad PIN1_AUDIO_ENABLED | 65 1.1 riastrad PIN2_AUDIO_ENABLED | 66 1.1 riastrad PIN3_AUDIO_ENABLED); 67 1.1 riastrad } 68 1.1 riastrad 69 1.1 riastrad WREG32(AZ_HOT_PLUG_CONTROL, tmp); 70 1.1 riastrad } 71 1.1 riastrad 72 1.1 riastrad void evergreen_hdmi_update_acr(struct drm_encoder *encoder, long offset, 73 1.1 riastrad const struct radeon_hdmi_acr *acr) 74 1.1 riastrad { 75 1.1 riastrad struct drm_device *dev = encoder->dev; 76 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 77 1.1 riastrad int bpc = 8; 78 1.1 riastrad 79 1.1 riastrad if (encoder->crtc) { 80 1.1 riastrad struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 81 1.1 riastrad bpc = radeon_crtc->bpc; 82 1.1 riastrad } 83 1.1 riastrad 84 1.1 riastrad if (bpc > 8) 85 1.1 riastrad WREG32(HDMI_ACR_PACKET_CONTROL + offset, 86 1.1 riastrad HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */ 87 1.1 riastrad else 88 1.1 riastrad WREG32(HDMI_ACR_PACKET_CONTROL + offset, 89 1.1 riastrad HDMI_ACR_SOURCE | /* select SW CTS value */ 90 1.1 riastrad HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */ 91 1.1 riastrad 92 1.1 riastrad WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr->cts_32khz)); 93 1.1 riastrad WREG32(HDMI_ACR_32_1 + offset, acr->n_32khz); 94 1.1 riastrad 95 1.1 riastrad WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr->cts_44_1khz)); 96 1.1 riastrad WREG32(HDMI_ACR_44_1 + offset, acr->n_44_1khz); 97 1.1 riastrad 98 1.1 riastrad WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr->cts_48khz)); 99 1.1 riastrad WREG32(HDMI_ACR_48_1 + offset, acr->n_48khz); 100 1.1 riastrad } 101 1.1 riastrad 102 1.1 riastrad void dce4_afmt_write_latency_fields(struct drm_encoder *encoder, 103 1.1 riastrad struct drm_connector *connector, struct drm_display_mode *mode) 104 1.1 riastrad { 105 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 106 1.1 riastrad u32 tmp = 0; 107 1.1 riastrad 108 1.1 riastrad if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 109 1.1 riastrad if (connector->latency_present[1]) 110 1.1 riastrad tmp = VIDEO_LIPSYNC(connector->video_latency[1]) | 111 1.1 riastrad AUDIO_LIPSYNC(connector->audio_latency[1]); 112 1.1 riastrad else 113 1.1 riastrad tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255); 114 1.1 riastrad } else { 115 1.1 riastrad if (connector->latency_present[0]) 116 1.1 riastrad tmp = VIDEO_LIPSYNC(connector->video_latency[0]) | 117 1.1 riastrad AUDIO_LIPSYNC(connector->audio_latency[0]); 118 1.1 riastrad else 119 1.1 riastrad tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255); 120 1.1 riastrad } 121 1.1 riastrad WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp); 122 1.1 riastrad } 123 1.1 riastrad 124 1.1 riastrad void dce4_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder, 125 1.1 riastrad u8 *sadb, int sad_count) 126 1.1 riastrad { 127 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 128 1.1 riastrad u32 tmp; 129 1.1 riastrad 130 1.1 riastrad /* program the speaker allocation */ 131 1.1 riastrad tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER); 132 1.1 riastrad tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK); 133 1.1 riastrad /* set HDMI mode */ 134 1.1 riastrad tmp |= HDMI_CONNECTION; 135 1.1 riastrad if (sad_count) 136 1.1 riastrad tmp |= SPEAKER_ALLOCATION(sadb[0]); 137 1.1 riastrad else 138 1.1 riastrad tmp |= SPEAKER_ALLOCATION(5); /* stereo */ 139 1.1 riastrad WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp); 140 1.1 riastrad } 141 1.1 riastrad 142 1.1 riastrad void dce4_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder, 143 1.1 riastrad u8 *sadb, int sad_count) 144 1.1 riastrad { 145 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 146 1.1 riastrad u32 tmp; 147 1.1 riastrad 148 1.1 riastrad /* program the speaker allocation */ 149 1.1 riastrad tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER); 150 1.1 riastrad tmp &= ~(HDMI_CONNECTION | SPEAKER_ALLOCATION_MASK); 151 1.1 riastrad /* set DP mode */ 152 1.1 riastrad tmp |= DP_CONNECTION; 153 1.1 riastrad if (sad_count) 154 1.1 riastrad tmp |= SPEAKER_ALLOCATION(sadb[0]); 155 1.1 riastrad else 156 1.1 riastrad tmp |= SPEAKER_ALLOCATION(5); /* stereo */ 157 1.1 riastrad WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp); 158 1.1 riastrad } 159 1.1 riastrad 160 1.1 riastrad void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder, 161 1.1 riastrad struct cea_sad *sads, int sad_count) 162 1.1 riastrad { 163 1.1 riastrad int i; 164 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 165 1.1 riastrad static const u16 eld_reg_to_type[][2] = { 166 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM }, 167 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 }, 168 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 }, 169 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 }, 170 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 }, 171 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC }, 172 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS }, 173 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC }, 174 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 }, 175 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD }, 176 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP }, 177 1.1 riastrad { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO }, 178 1.1 riastrad }; 179 1.1 riastrad 180 1.1 riastrad for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) { 181 1.1 riastrad u32 value = 0; 182 1.1 riastrad u8 stereo_freqs = 0; 183 1.1 riastrad int max_channels = -1; 184 1.1 riastrad int j; 185 1.1 riastrad 186 1.1 riastrad for (j = 0; j < sad_count; j++) { 187 1.1 riastrad struct cea_sad *sad = &sads[j]; 188 1.1 riastrad 189 1.1 riastrad if (sad->format == eld_reg_to_type[i][1]) { 190 1.1 riastrad if (sad->channels > max_channels) { 191 1.1 riastrad value = MAX_CHANNELS(sad->channels) | 192 1.1 riastrad DESCRIPTOR_BYTE_2(sad->byte2) | 193 1.1 riastrad SUPPORTED_FREQUENCIES(sad->freq); 194 1.1 riastrad max_channels = sad->channels; 195 1.1 riastrad } 196 1.1 riastrad 197 1.1 riastrad if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM) 198 1.1 riastrad stereo_freqs |= sad->freq; 199 1.1 riastrad else 200 1.1 riastrad break; 201 1.1 riastrad } 202 1.1 riastrad } 203 1.1 riastrad 204 1.1 riastrad value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs); 205 1.1 riastrad 206 1.1 riastrad WREG32_ENDPOINT(0, eld_reg_to_type[i][0], value); 207 1.1 riastrad } 208 1.1 riastrad } 209 1.1 riastrad 210 1.1 riastrad /* 211 1.1 riastrad * build a AVI Info Frame 212 1.1 riastrad */ 213 1.1 riastrad void evergreen_set_avi_packet(struct radeon_device *rdev, u32 offset, 214 1.2 riastrad unsigned char *buffer, size_t size) 215 1.1 riastrad { 216 1.1 riastrad uint8_t *frame = buffer + 3; 217 1.1 riastrad 218 1.1 riastrad WREG32(AFMT_AVI_INFO0 + offset, 219 1.1 riastrad frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24)); 220 1.1 riastrad WREG32(AFMT_AVI_INFO1 + offset, 221 1.1 riastrad frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24)); 222 1.1 riastrad WREG32(AFMT_AVI_INFO2 + offset, 223 1.1 riastrad frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); 224 1.1 riastrad WREG32(AFMT_AVI_INFO3 + offset, 225 1.1 riastrad frame[0xC] | (frame[0xD] << 8) | (buffer[1] << 24)); 226 1.1 riastrad 227 1.1 riastrad WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, 228 1.1 riastrad HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ 229 1.1 riastrad ~HDMI_AVI_INFO_LINE_MASK); 230 1.1 riastrad } 231 1.1 riastrad 232 1.1 riastrad void dce4_hdmi_audio_set_dto(struct radeon_device *rdev, 233 1.1 riastrad struct radeon_crtc *crtc, unsigned int clock) 234 1.1 riastrad { 235 1.1 riastrad unsigned int max_ratio = clock / 24000; 236 1.1 riastrad u32 dto_phase; 237 1.1 riastrad u32 wallclock_ratio; 238 1.1 riastrad u32 value; 239 1.1 riastrad 240 1.1 riastrad if (max_ratio >= 8) { 241 1.1 riastrad dto_phase = 192 * 1000; 242 1.1 riastrad wallclock_ratio = 3; 243 1.1 riastrad } else if (max_ratio >= 4) { 244 1.1 riastrad dto_phase = 96 * 1000; 245 1.1 riastrad wallclock_ratio = 2; 246 1.1 riastrad } else if (max_ratio >= 2) { 247 1.1 riastrad dto_phase = 48 * 1000; 248 1.1 riastrad wallclock_ratio = 1; 249 1.1 riastrad } else { 250 1.1 riastrad dto_phase = 24 * 1000; 251 1.1 riastrad wallclock_ratio = 0; 252 1.1 riastrad } 253 1.1 riastrad 254 1.1 riastrad value = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK; 255 1.1 riastrad value |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio); 256 1.1 riastrad value &= ~DCCG_AUDIO_DTO1_USE_512FBR_DTO; 257 1.1 riastrad WREG32(DCCG_AUDIO_DTO0_CNTL, value); 258 1.1 riastrad 259 1.1 riastrad /* Two dtos; generally use dto0 for HDMI */ 260 1.1 riastrad value = 0; 261 1.1 riastrad 262 1.1 riastrad if (crtc) 263 1.1 riastrad value |= DCCG_AUDIO_DTO0_SOURCE_SEL(crtc->crtc_id); 264 1.1 riastrad 265 1.1 riastrad WREG32(DCCG_AUDIO_DTO_SOURCE, value); 266 1.1 riastrad 267 1.1 riastrad /* Express [24MHz / target pixel clock] as an exact rational 268 1.1 riastrad * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE 269 1.1 riastrad * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator 270 1.1 riastrad */ 271 1.1 riastrad WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase); 272 1.1 riastrad WREG32(DCCG_AUDIO_DTO0_MODULE, clock); 273 1.1 riastrad } 274 1.1 riastrad 275 1.1 riastrad void dce4_dp_audio_set_dto(struct radeon_device *rdev, 276 1.1 riastrad struct radeon_crtc *crtc, unsigned int clock) 277 1.1 riastrad { 278 1.1 riastrad u32 value; 279 1.1 riastrad 280 1.1 riastrad value = RREG32(DCCG_AUDIO_DTO1_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK; 281 1.1 riastrad value |= DCCG_AUDIO_DTO1_USE_512FBR_DTO; 282 1.1 riastrad WREG32(DCCG_AUDIO_DTO1_CNTL, value); 283 1.1 riastrad 284 1.1 riastrad /* Two dtos; generally use dto1 for DP */ 285 1.1 riastrad value = 0; 286 1.1 riastrad value |= DCCG_AUDIO_DTO_SEL; 287 1.1 riastrad 288 1.1 riastrad if (crtc) 289 1.1 riastrad value |= DCCG_AUDIO_DTO0_SOURCE_SEL(crtc->crtc_id); 290 1.1 riastrad 291 1.1 riastrad WREG32(DCCG_AUDIO_DTO_SOURCE, value); 292 1.1 riastrad 293 1.1 riastrad /* Express [24MHz / target pixel clock] as an exact rational 294 1.1 riastrad * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE 295 1.1 riastrad * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator 296 1.1 riastrad */ 297 1.1 riastrad if (ASIC_IS_DCE41(rdev)) { 298 1.1 riastrad unsigned int div = (RREG32(DCE41_DENTIST_DISPCLK_CNTL) & 299 1.1 riastrad DENTIST_DPREFCLK_WDIVIDER_MASK) >> 300 1.1 riastrad DENTIST_DPREFCLK_WDIVIDER_SHIFT; 301 1.1 riastrad div = radeon_audio_decode_dfs_div(div); 302 1.1 riastrad 303 1.1 riastrad if (div) 304 1.1 riastrad clock = 100 * clock / div; 305 1.1 riastrad } 306 1.1 riastrad 307 1.1 riastrad WREG32(DCCG_AUDIO_DTO1_PHASE, 24000); 308 1.1 riastrad WREG32(DCCG_AUDIO_DTO1_MODULE, clock); 309 1.1 riastrad } 310 1.1 riastrad 311 1.1 riastrad void dce4_set_vbi_packet(struct drm_encoder *encoder, u32 offset) 312 1.1 riastrad { 313 1.1 riastrad struct drm_device *dev = encoder->dev; 314 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 315 1.1 riastrad 316 1.1 riastrad WREG32(HDMI_VBI_PACKET_CONTROL + offset, 317 1.1 riastrad HDMI_NULL_SEND | /* send null packets when required */ 318 1.1 riastrad HDMI_GC_SEND | /* send general control packets */ 319 1.1 riastrad HDMI_GC_CONT); /* send general control packets every frame */ 320 1.1 riastrad } 321 1.1 riastrad 322 1.1 riastrad void dce4_hdmi_set_color_depth(struct drm_encoder *encoder, u32 offset, int bpc) 323 1.1 riastrad { 324 1.1 riastrad struct drm_device *dev = encoder->dev; 325 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 326 1.1 riastrad struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 327 1.1 riastrad uint32_t val; 328 1.1 riastrad 329 1.1 riastrad val = RREG32(HDMI_CONTROL + offset); 330 1.1 riastrad val &= ~HDMI_DEEP_COLOR_ENABLE; 331 1.1 riastrad val &= ~HDMI_DEEP_COLOR_DEPTH_MASK; 332 1.1 riastrad 333 1.1 riastrad switch (bpc) { 334 1.1 riastrad case 0: 335 1.1 riastrad case 6: 336 1.1 riastrad case 8: 337 1.1 riastrad case 16: 338 1.1 riastrad default: 339 1.1 riastrad DRM_DEBUG("%s: Disabling hdmi deep color for %d bpc.\n", 340 1.1 riastrad connector->name, bpc); 341 1.1 riastrad break; 342 1.1 riastrad case 10: 343 1.1 riastrad val |= HDMI_DEEP_COLOR_ENABLE; 344 1.1 riastrad val |= HDMI_DEEP_COLOR_DEPTH(HDMI_30BIT_DEEP_COLOR); 345 1.1 riastrad DRM_DEBUG("%s: Enabling hdmi deep color 30 for 10 bpc.\n", 346 1.1 riastrad connector->name); 347 1.1 riastrad break; 348 1.1 riastrad case 12: 349 1.1 riastrad val |= HDMI_DEEP_COLOR_ENABLE; 350 1.1 riastrad val |= HDMI_DEEP_COLOR_DEPTH(HDMI_36BIT_DEEP_COLOR); 351 1.1 riastrad DRM_DEBUG("%s: Enabling hdmi deep color 36 for 12 bpc.\n", 352 1.1 riastrad connector->name); 353 1.1 riastrad break; 354 1.1 riastrad } 355 1.1 riastrad 356 1.1 riastrad WREG32(HDMI_CONTROL + offset, val); 357 1.1 riastrad } 358 1.1 riastrad 359 1.1 riastrad void dce4_set_audio_packet(struct drm_encoder *encoder, u32 offset) 360 1.1 riastrad { 361 1.1 riastrad struct drm_device *dev = encoder->dev; 362 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 363 1.1 riastrad 364 1.1 riastrad WREG32(AFMT_INFOFRAME_CONTROL0 + offset, 365 1.1 riastrad AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */ 366 1.1 riastrad 367 1.1 riastrad WREG32(AFMT_60958_0 + offset, 368 1.1 riastrad AFMT_60958_CS_CHANNEL_NUMBER_L(1)); 369 1.1 riastrad 370 1.1 riastrad WREG32(AFMT_60958_1 + offset, 371 1.1 riastrad AFMT_60958_CS_CHANNEL_NUMBER_R(2)); 372 1.1 riastrad 373 1.1 riastrad WREG32(AFMT_60958_2 + offset, 374 1.1 riastrad AFMT_60958_CS_CHANNEL_NUMBER_2(3) | 375 1.1 riastrad AFMT_60958_CS_CHANNEL_NUMBER_3(4) | 376 1.1 riastrad AFMT_60958_CS_CHANNEL_NUMBER_4(5) | 377 1.1 riastrad AFMT_60958_CS_CHANNEL_NUMBER_5(6) | 378 1.1 riastrad AFMT_60958_CS_CHANNEL_NUMBER_6(7) | 379 1.1 riastrad AFMT_60958_CS_CHANNEL_NUMBER_7(8)); 380 1.1 riastrad 381 1.1 riastrad WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset, 382 1.1 riastrad AFMT_AUDIO_CHANNEL_ENABLE(0xff)); 383 1.1 riastrad 384 1.1 riastrad WREG32(HDMI_AUDIO_PACKET_CONTROL + offset, 385 1.1 riastrad HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */ 386 1.1 riastrad HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */ 387 1.1 riastrad 388 1.1 riastrad /* allow 60958 channel status and send audio packets fields to be updated */ 389 1.1 riastrad WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset, 390 1.1 riastrad AFMT_RESET_FIFO_WHEN_AUDIO_DIS | AFMT_60958_CS_UPDATE); 391 1.1 riastrad } 392 1.1 riastrad 393 1.1 riastrad 394 1.1 riastrad void dce4_set_mute(struct drm_encoder *encoder, u32 offset, bool mute) 395 1.1 riastrad { 396 1.1 riastrad struct drm_device *dev = encoder->dev; 397 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 398 1.1 riastrad 399 1.1 riastrad if (mute) 400 1.1 riastrad WREG32_OR(HDMI_GC + offset, HDMI_GC_AVMUTE); 401 1.1 riastrad else 402 1.1 riastrad WREG32_AND(HDMI_GC + offset, ~HDMI_GC_AVMUTE); 403 1.1 riastrad } 404 1.1 riastrad 405 1.1 riastrad void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable) 406 1.1 riastrad { 407 1.1 riastrad struct drm_device *dev = encoder->dev; 408 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 409 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 410 1.1 riastrad struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 411 1.1 riastrad 412 1.1 riastrad if (!dig || !dig->afmt) 413 1.1 riastrad return; 414 1.1 riastrad 415 1.1 riastrad if (enable) { 416 1.1 riastrad struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 417 1.1 riastrad 418 1.1 riastrad if (connector && drm_detect_monitor_audio(radeon_connector_edid(connector))) { 419 1.1 riastrad WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, 420 1.1 riastrad HDMI_AVI_INFO_SEND | /* enable AVI info frames */ 421 1.1 riastrad HDMI_AVI_INFO_CONT | /* required for audio info values to be updated */ 422 1.1 riastrad HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ 423 1.1 riastrad HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */ 424 1.1 riastrad WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, 425 1.1 riastrad AFMT_AUDIO_SAMPLE_SEND); 426 1.1 riastrad } else { 427 1.1 riastrad WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, 428 1.1 riastrad HDMI_AVI_INFO_SEND | /* enable AVI info frames */ 429 1.1 riastrad HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */ 430 1.1 riastrad WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, 431 1.1 riastrad ~AFMT_AUDIO_SAMPLE_SEND); 432 1.1 riastrad } 433 1.1 riastrad } else { 434 1.1 riastrad WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, 435 1.1 riastrad ~AFMT_AUDIO_SAMPLE_SEND); 436 1.1 riastrad WREG32(HDMI_INFOFRAME_CONTROL0 + dig->afmt->offset, 0); 437 1.1 riastrad } 438 1.1 riastrad 439 1.1 riastrad dig->afmt->enabled = enable; 440 1.1 riastrad 441 1.1 riastrad DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n", 442 1.1 riastrad enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id); 443 1.1 riastrad } 444 1.1 riastrad 445 1.1 riastrad void evergreen_dp_enable(struct drm_encoder *encoder, bool enable) 446 1.1 riastrad { 447 1.1 riastrad struct drm_device *dev = encoder->dev; 448 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 449 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 450 1.1 riastrad struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 451 1.1 riastrad struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 452 1.1 riastrad 453 1.1 riastrad if (!dig || !dig->afmt) 454 1.1 riastrad return; 455 1.1 riastrad 456 1.1 riastrad if (enable && connector && 457 1.1 riastrad drm_detect_monitor_audio(radeon_connector_edid(connector))) { 458 1.1 riastrad struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 459 1.1 riastrad struct radeon_connector *radeon_connector = to_radeon_connector(connector); 460 1.1 riastrad struct radeon_connector_atom_dig *dig_connector; 461 1.1 riastrad uint32_t val; 462 1.1 riastrad 463 1.1 riastrad WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, 464 1.1 riastrad AFMT_AUDIO_SAMPLE_SEND); 465 1.1 riastrad 466 1.1 riastrad WREG32(EVERGREEN_DP_SEC_TIMESTAMP + dig->afmt->offset, 467 1.1 riastrad EVERGREEN_DP_SEC_TIMESTAMP_MODE(1)); 468 1.1 riastrad 469 1.1 riastrad if (!ASIC_IS_DCE6(rdev) && radeon_connector->con_priv) { 470 1.1 riastrad dig_connector = radeon_connector->con_priv; 471 1.1 riastrad val = RREG32(EVERGREEN_DP_SEC_AUD_N + dig->afmt->offset); 472 1.1 riastrad val &= ~EVERGREEN_DP_SEC_N_BASE_MULTIPLE(0xf); 473 1.1 riastrad 474 1.1 riastrad if (dig_connector->dp_clock == 162000) 475 1.1 riastrad val |= EVERGREEN_DP_SEC_N_BASE_MULTIPLE(3); 476 1.1 riastrad else 477 1.1 riastrad val |= EVERGREEN_DP_SEC_N_BASE_MULTIPLE(5); 478 1.1 riastrad 479 1.1 riastrad WREG32(EVERGREEN_DP_SEC_AUD_N + dig->afmt->offset, val); 480 1.1 riastrad } 481 1.1 riastrad 482 1.1 riastrad WREG32(EVERGREEN_DP_SEC_CNTL + dig->afmt->offset, 483 1.1 riastrad EVERGREEN_DP_SEC_ASP_ENABLE | /* Audio packet transmission */ 484 1.1 riastrad EVERGREEN_DP_SEC_ATP_ENABLE | /* Audio timestamp packet transmission */ 485 1.1 riastrad EVERGREEN_DP_SEC_AIP_ENABLE | /* Audio infoframe packet transmission */ 486 1.1 riastrad EVERGREEN_DP_SEC_STREAM_ENABLE); /* Master enable for secondary stream engine */ 487 1.1 riastrad } else { 488 1.1 riastrad WREG32(EVERGREEN_DP_SEC_CNTL + dig->afmt->offset, 0); 489 1.1 riastrad WREG32_AND(AFMT_AUDIO_PACKET_CONTROL + dig->afmt->offset, 490 1.1 riastrad ~AFMT_AUDIO_SAMPLE_SEND); 491 1.1 riastrad } 492 1.1 riastrad 493 1.1 riastrad dig->afmt->enabled = enable; 494 1.1 riastrad } 495