1e55d3e6cSRafał Miłecki /* 2e55d3e6cSRafał Miłecki * Copyright 2008 Advanced Micro Devices, Inc. 3e55d3e6cSRafał Miłecki * Copyright 2008 Red Hat Inc. 4e55d3e6cSRafał Miłecki * Copyright 2009 Christian König. 5e55d3e6cSRafał Miłecki * 6e55d3e6cSRafał Miłecki * Permission is hereby granted, free of charge, to any person obtaining a 7e55d3e6cSRafał Miłecki * copy of this software and associated documentation files (the "Software"), 8e55d3e6cSRafał Miłecki * to deal in the Software without restriction, including without limitation 9e55d3e6cSRafał Miłecki * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10e55d3e6cSRafał Miłecki * and/or sell copies of the Software, and to permit persons to whom the 11e55d3e6cSRafał Miłecki * Software is furnished to do so, subject to the following conditions: 12e55d3e6cSRafał Miłecki * 13e55d3e6cSRafał Miłecki * The above copyright notice and this permission notice shall be included in 14e55d3e6cSRafał Miłecki * all copies or substantial portions of the Software. 15e55d3e6cSRafał Miłecki * 16e55d3e6cSRafał Miłecki * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17e55d3e6cSRafał Miłecki * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18e55d3e6cSRafał Miłecki * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19e55d3e6cSRafał Miłecki * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20e55d3e6cSRafał Miłecki * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21e55d3e6cSRafał Miłecki * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22e55d3e6cSRafał Miłecki * OTHER DEALINGS IN THE SOFTWARE. 23e55d3e6cSRafał Miłecki * 24e55d3e6cSRafał Miłecki * Authors: Christian König 25e55d3e6cSRafał Miłecki * Rafał Miłecki 26e55d3e6cSRafał Miłecki */ 27e3b2e034SThierry Reding #include <linux/hdmi.h> 28760285e7SDavid Howells #include <drm/drmP.h> 29760285e7SDavid Howells #include <drm/radeon_drm.h> 30e55d3e6cSRafał Miłecki #include "radeon.h" 31e55d3e6cSRafał Miłecki #include "radeon_asic.h" 32e55d3e6cSRafał Miłecki #include "evergreend.h" 33e55d3e6cSRafał Miłecki #include "atom.h" 34e55d3e6cSRafał Miłecki 356159b65aSRafał Miłecki extern void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder); 36b530602fSAlex Deucher extern void dce6_afmt_write_sad_regs(struct drm_encoder *encoder); 37b530602fSAlex Deucher extern void dce6_afmt_select_pin(struct drm_encoder *encoder); 38b530602fSAlex Deucher 39e55d3e6cSRafał Miłecki /* 40e55d3e6cSRafał Miłecki * update the N and CTS parameters for a given pixel clock rate 41e55d3e6cSRafał Miłecki */ 42e55d3e6cSRafał Miłecki static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock) 43e55d3e6cSRafał Miłecki { 44e55d3e6cSRafał Miłecki struct drm_device *dev = encoder->dev; 45e55d3e6cSRafał Miłecki struct radeon_device *rdev = dev->dev_private; 46e55d3e6cSRafał Miłecki struct radeon_hdmi_acr acr = r600_hdmi_acr(clock); 47cfcbd6d3SRafał Miłecki struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 48cfcbd6d3SRafał Miłecki struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 49cfcbd6d3SRafał Miłecki uint32_t offset = dig->afmt->offset; 50e55d3e6cSRafał Miłecki 51e55d3e6cSRafał Miłecki WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz)); 52e55d3e6cSRafał Miłecki WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz); 53e55d3e6cSRafał Miłecki 54e55d3e6cSRafał Miłecki WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz)); 55e55d3e6cSRafał Miłecki WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz); 56e55d3e6cSRafał Miłecki 57e55d3e6cSRafał Miłecki WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz)); 58e55d3e6cSRafał Miłecki WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz); 59e55d3e6cSRafał Miłecki } 60e55d3e6cSRafał Miłecki 61*712fd8a2SAlex Deucher static void dce4_afmt_write_latency_fields(struct drm_encoder *encoder, 62*712fd8a2SAlex Deucher struct drm_display_mode *mode) 63*712fd8a2SAlex Deucher { 64*712fd8a2SAlex Deucher struct radeon_device *rdev = encoder->dev->dev_private; 65*712fd8a2SAlex Deucher struct drm_connector *connector; 66*712fd8a2SAlex Deucher struct radeon_connector *radeon_connector = NULL; 67*712fd8a2SAlex Deucher u32 tmp = 0; 68*712fd8a2SAlex Deucher 69*712fd8a2SAlex Deucher list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { 70*712fd8a2SAlex Deucher if (connector->encoder == encoder) { 71*712fd8a2SAlex Deucher radeon_connector = to_radeon_connector(connector); 72*712fd8a2SAlex Deucher break; 73*712fd8a2SAlex Deucher } 74*712fd8a2SAlex Deucher } 75*712fd8a2SAlex Deucher 76*712fd8a2SAlex Deucher if (!radeon_connector) { 77*712fd8a2SAlex Deucher DRM_ERROR("Couldn't find encoder's connector\n"); 78*712fd8a2SAlex Deucher return; 79*712fd8a2SAlex Deucher } 80*712fd8a2SAlex Deucher 81*712fd8a2SAlex Deucher if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 82*712fd8a2SAlex Deucher if (connector->latency_present[1]) 83*712fd8a2SAlex Deucher tmp = VIDEO_LIPSYNC(connector->video_latency[1]) | 84*712fd8a2SAlex Deucher AUDIO_LIPSYNC(connector->audio_latency[1]); 85*712fd8a2SAlex Deucher else 86*712fd8a2SAlex Deucher tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255); 87*712fd8a2SAlex Deucher } else { 88*712fd8a2SAlex Deucher if (connector->latency_present[0]) 89*712fd8a2SAlex Deucher tmp = VIDEO_LIPSYNC(connector->video_latency[0]) | 90*712fd8a2SAlex Deucher AUDIO_LIPSYNC(connector->audio_latency[0]); 91*712fd8a2SAlex Deucher else 92*712fd8a2SAlex Deucher tmp = VIDEO_LIPSYNC(255) | AUDIO_LIPSYNC(255); 93*712fd8a2SAlex Deucher } 94*712fd8a2SAlex Deucher WREG32(AZ_F0_CODEC_PIN0_CONTROL_RESPONSE_LIPSYNC, tmp); 95*712fd8a2SAlex Deucher } 96*712fd8a2SAlex Deucher 97ba7def4fSAlex Deucher static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder) 98ba7def4fSAlex Deucher { 99ba7def4fSAlex Deucher struct radeon_device *rdev = encoder->dev->dev_private; 100ba7def4fSAlex Deucher struct drm_connector *connector; 101ba7def4fSAlex Deucher struct radeon_connector *radeon_connector = NULL; 102ba7def4fSAlex Deucher u32 tmp; 103ba7def4fSAlex Deucher u8 *sadb; 104ba7def4fSAlex Deucher int sad_count; 105ba7def4fSAlex Deucher 106ba7def4fSAlex Deucher list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { 1078a992ee1SAlex Deucher if (connector->encoder == encoder) { 108ba7def4fSAlex Deucher radeon_connector = to_radeon_connector(connector); 1098a992ee1SAlex Deucher break; 1108a992ee1SAlex Deucher } 111ba7def4fSAlex Deucher } 112ba7def4fSAlex Deucher 113ba7def4fSAlex Deucher if (!radeon_connector) { 114ba7def4fSAlex Deucher DRM_ERROR("Couldn't find encoder's connector\n"); 115ba7def4fSAlex Deucher return; 116ba7def4fSAlex Deucher } 117ba7def4fSAlex Deucher 118ba7def4fSAlex Deucher sad_count = drm_edid_to_speaker_allocation(radeon_connector->edid, &sadb); 119ba7def4fSAlex Deucher if (sad_count < 0) { 120ba7def4fSAlex Deucher DRM_ERROR("Couldn't read Speaker Allocation Data Block: %d\n", sad_count); 121ba7def4fSAlex Deucher return; 122ba7def4fSAlex Deucher } 123ba7def4fSAlex Deucher 124ba7def4fSAlex Deucher /* program the speaker allocation */ 125ba7def4fSAlex Deucher tmp = RREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER); 126ba7def4fSAlex Deucher tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK); 127ba7def4fSAlex Deucher /* set HDMI mode */ 128ba7def4fSAlex Deucher tmp |= HDMI_CONNECTION; 129ba7def4fSAlex Deucher if (sad_count) 130ba7def4fSAlex Deucher tmp |= SPEAKER_ALLOCATION(sadb[0]); 131ba7def4fSAlex Deucher else 132ba7def4fSAlex Deucher tmp |= SPEAKER_ALLOCATION(5); /* stereo */ 133ba7def4fSAlex Deucher WREG32(AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp); 134ba7def4fSAlex Deucher 135ba7def4fSAlex Deucher kfree(sadb); 136ba7def4fSAlex Deucher } 137ba7def4fSAlex Deucher 13846892caaSRafał Miłecki static void evergreen_hdmi_write_sad_regs(struct drm_encoder *encoder) 13946892caaSRafał Miłecki { 14046892caaSRafał Miłecki struct radeon_device *rdev = encoder->dev->dev_private; 14146892caaSRafał Miłecki struct drm_connector *connector; 14246892caaSRafał Miłecki struct radeon_connector *radeon_connector = NULL; 14346892caaSRafał Miłecki struct cea_sad *sads; 14446892caaSRafał Miłecki int i, sad_count; 14546892caaSRafał Miłecki 14646892caaSRafał Miłecki static const u16 eld_reg_to_type[][2] = { 14746892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM }, 14846892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 }, 14946892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 }, 15046892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 }, 15146892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 }, 15246892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC }, 15346892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS }, 15446892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC }, 15546892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 }, 15646892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD }, 15746892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP }, 15846892caaSRafał Miłecki { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO }, 15946892caaSRafał Miłecki }; 16046892caaSRafał Miłecki 16146892caaSRafał Miłecki list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { 1628a992ee1SAlex Deucher if (connector->encoder == encoder) { 16346892caaSRafał Miłecki radeon_connector = to_radeon_connector(connector); 1648a992ee1SAlex Deucher break; 1658a992ee1SAlex Deucher } 16646892caaSRafał Miłecki } 16746892caaSRafał Miłecki 16846892caaSRafał Miłecki if (!radeon_connector) { 16946892caaSRafał Miłecki DRM_ERROR("Couldn't find encoder's connector\n"); 17046892caaSRafał Miłecki return; 17146892caaSRafał Miłecki } 17246892caaSRafał Miłecki 17346892caaSRafał Miłecki sad_count = drm_edid_to_sad(radeon_connector->edid, &sads); 17446892caaSRafał Miłecki if (sad_count < 0) { 17546892caaSRafał Miłecki DRM_ERROR("Couldn't read SADs: %d\n", sad_count); 17646892caaSRafał Miłecki return; 17746892caaSRafał Miłecki } 17846892caaSRafał Miłecki BUG_ON(!sads); 17946892caaSRafał Miłecki 18046892caaSRafał Miłecki for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) { 18146892caaSRafał Miłecki u32 value = 0; 18246892caaSRafał Miłecki int j; 18346892caaSRafał Miłecki 18446892caaSRafał Miłecki for (j = 0; j < sad_count; j++) { 18546892caaSRafał Miłecki struct cea_sad *sad = &sads[j]; 18646892caaSRafał Miłecki 18746892caaSRafał Miłecki if (sad->format == eld_reg_to_type[i][1]) { 18846892caaSRafał Miłecki value = MAX_CHANNELS(sad->channels) | 18946892caaSRafał Miłecki DESCRIPTOR_BYTE_2(sad->byte2) | 19046892caaSRafał Miłecki SUPPORTED_FREQUENCIES(sad->freq); 19146892caaSRafał Miłecki if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM) 19246892caaSRafał Miłecki value |= SUPPORTED_FREQUENCIES_STEREO(sad->freq); 19346892caaSRafał Miłecki break; 19446892caaSRafał Miłecki } 19546892caaSRafał Miłecki } 19646892caaSRafał Miłecki WREG32(eld_reg_to_type[i][0], value); 19746892caaSRafał Miłecki } 19846892caaSRafał Miłecki 19946892caaSRafał Miłecki kfree(sads); 20046892caaSRafał Miłecki } 20146892caaSRafał Miłecki 202e55d3e6cSRafał Miłecki /* 203e55d3e6cSRafał Miłecki * build a HDMI Video Info Frame 204e55d3e6cSRafał Miłecki */ 205e3b2e034SThierry Reding static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder, 206e3b2e034SThierry Reding void *buffer, size_t size) 207e55d3e6cSRafał Miłecki { 208e55d3e6cSRafał Miłecki struct drm_device *dev = encoder->dev; 209e55d3e6cSRafał Miłecki struct radeon_device *rdev = dev->dev_private; 210cfcbd6d3SRafał Miłecki struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 211cfcbd6d3SRafał Miłecki struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 212cfcbd6d3SRafał Miłecki uint32_t offset = dig->afmt->offset; 213e3b2e034SThierry Reding uint8_t *frame = buffer + 3; 214f100380eSAlex Deucher uint8_t *header = buffer; 215e55d3e6cSRafał Miłecki 216e55d3e6cSRafał Miłecki WREG32(AFMT_AVI_INFO0 + offset, 217e55d3e6cSRafał Miłecki frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24)); 218e55d3e6cSRafał Miłecki WREG32(AFMT_AVI_INFO1 + offset, 219e55d3e6cSRafał Miłecki frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24)); 220e55d3e6cSRafał Miłecki WREG32(AFMT_AVI_INFO2 + offset, 221e55d3e6cSRafał Miłecki frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); 222e55d3e6cSRafał Miłecki WREG32(AFMT_AVI_INFO3 + offset, 223f100380eSAlex Deucher frame[0xC] | (frame[0xD] << 8) | (header[1] << 24)); 224e55d3e6cSRafał Miłecki } 225e55d3e6cSRafał Miłecki 226b1f6f47eSAlex Deucher static void evergreen_audio_set_dto(struct drm_encoder *encoder, u32 clock) 227b1f6f47eSAlex Deucher { 228b1f6f47eSAlex Deucher struct drm_device *dev = encoder->dev; 229b1f6f47eSAlex Deucher struct radeon_device *rdev = dev->dev_private; 230b1f6f47eSAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 231b1f6f47eSAlex Deucher struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 232b1f6f47eSAlex Deucher struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 233731da21bSAlex Deucher u32 base_rate = 24000; 2341518dd8eSAlex Deucher u32 max_ratio = clock / base_rate; 2351518dd8eSAlex Deucher u32 dto_phase; 2361518dd8eSAlex Deucher u32 dto_modulo = clock; 2371518dd8eSAlex Deucher u32 wallclock_ratio; 2381518dd8eSAlex Deucher u32 dto_cntl; 239b1f6f47eSAlex Deucher 240b1f6f47eSAlex Deucher if (!dig || !dig->afmt) 241b1f6f47eSAlex Deucher return; 242b1f6f47eSAlex Deucher 243b530602fSAlex Deucher if (ASIC_IS_DCE6(rdev)) { 244b530602fSAlex Deucher dto_phase = 24 * 1000; 245b530602fSAlex Deucher } else { 2461518dd8eSAlex Deucher if (max_ratio >= 8) { 2471518dd8eSAlex Deucher dto_phase = 192 * 1000; 2481518dd8eSAlex Deucher wallclock_ratio = 3; 2491518dd8eSAlex Deucher } else if (max_ratio >= 4) { 2501518dd8eSAlex Deucher dto_phase = 96 * 1000; 2511518dd8eSAlex Deucher wallclock_ratio = 2; 2521518dd8eSAlex Deucher } else if (max_ratio >= 2) { 2531518dd8eSAlex Deucher dto_phase = 48 * 1000; 2541518dd8eSAlex Deucher wallclock_ratio = 1; 2551518dd8eSAlex Deucher } else { 2561518dd8eSAlex Deucher dto_phase = 24 * 1000; 2571518dd8eSAlex Deucher wallclock_ratio = 0; 2581518dd8eSAlex Deucher } 2591518dd8eSAlex Deucher dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK; 2601518dd8eSAlex Deucher dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio); 2611518dd8eSAlex Deucher WREG32(DCCG_AUDIO_DTO0_CNTL, dto_cntl); 262b530602fSAlex Deucher } 2631518dd8eSAlex Deucher 264b1f6f47eSAlex Deucher /* XXX two dtos; generally use dto0 for hdmi */ 265b1f6f47eSAlex Deucher /* Express [24MHz / target pixel clock] as an exact rational 266b1f6f47eSAlex Deucher * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE 267b1f6f47eSAlex Deucher * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator 268b1f6f47eSAlex Deucher */ 2697d61d835SAlex Deucher WREG32(DCCG_AUDIO_DTO_SOURCE, DCCG_AUDIO_DTO0_SOURCE_SEL(radeon_crtc->crtc_id)); 2701518dd8eSAlex Deucher WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase); 2711518dd8eSAlex Deucher WREG32(DCCG_AUDIO_DTO0_MODULE, dto_modulo); 272b1f6f47eSAlex Deucher } 273b1f6f47eSAlex Deucher 274b1f6f47eSAlex Deucher 275e55d3e6cSRafał Miłecki /* 276e55d3e6cSRafał Miłecki * update the info frames with the data from the current display mode 277e55d3e6cSRafał Miłecki */ 278e55d3e6cSRafał Miłecki void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode) 279e55d3e6cSRafał Miłecki { 280e55d3e6cSRafał Miłecki struct drm_device *dev = encoder->dev; 281e55d3e6cSRafał Miłecki struct radeon_device *rdev = dev->dev_private; 282cfcbd6d3SRafał Miłecki struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 283cfcbd6d3SRafał Miłecki struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 284e3b2e034SThierry Reding u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE]; 285e3b2e034SThierry Reding struct hdmi_avi_infoframe frame; 286cfcbd6d3SRafał Miłecki uint32_t offset; 287e3b2e034SThierry Reding ssize_t err; 288e55d3e6cSRafał Miłecki 289c2b4cacfSAlex Deucher if (!dig || !dig->afmt) 290c2b4cacfSAlex Deucher return; 291c2b4cacfSAlex Deucher 292cfcbd6d3SRafał Miłecki /* Silent, r600_hdmi_enable will raise WARN for us */ 293cfcbd6d3SRafał Miłecki if (!dig->afmt->enabled) 294e55d3e6cSRafał Miłecki return; 295cfcbd6d3SRafał Miłecki offset = dig->afmt->offset; 296e55d3e6cSRafał Miłecki 297b1f6f47eSAlex Deucher evergreen_audio_set_dto(encoder, mode->clock); 298e55d3e6cSRafał Miłecki 2991c3439f2SRafał Miłecki WREG32(HDMI_VBI_PACKET_CONTROL + offset, 3001c3439f2SRafał Miłecki HDMI_NULL_SEND); /* send null packets when required */ 3011c3439f2SRafał Miłecki 302e55d3e6cSRafał Miłecki WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000); 303e55d3e6cSRafał Miłecki 3041c3439f2SRafał Miłecki WREG32(HDMI_VBI_PACKET_CONTROL + offset, 3051c3439f2SRafał Miłecki HDMI_NULL_SEND | /* send null packets when required */ 3061c3439f2SRafał Miłecki HDMI_GC_SEND | /* send general control packets */ 3071c3439f2SRafał Miłecki HDMI_GC_CONT); /* send general control packets every frame */ 308e55d3e6cSRafał Miłecki 3091c3439f2SRafał Miłecki WREG32(HDMI_INFOFRAME_CONTROL0 + offset, 3101c3439f2SRafał Miłecki HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */ 3111c3439f2SRafał Miłecki HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */ 3121c3439f2SRafał Miłecki 3131c3439f2SRafał Miłecki WREG32(AFMT_INFOFRAME_CONTROL0 + offset, 3141c3439f2SRafał Miłecki AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */ 3151c3439f2SRafał Miłecki 3161c3439f2SRafał Miłecki WREG32(HDMI_INFOFRAME_CONTROL1 + offset, 3171c3439f2SRafał Miłecki HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */ 3181c3439f2SRafał Miłecki 3191c3439f2SRafał Miłecki WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */ 320e55d3e6cSRafał Miłecki 32191a44019SRafał Miłecki WREG32(HDMI_AUDIO_PACKET_CONTROL + offset, 32291a44019SRafał Miłecki HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */ 32391a44019SRafał Miłecki HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */ 32491a44019SRafał Miłecki 32591a44019SRafał Miłecki WREG32(AFMT_AUDIO_PACKET_CONTROL + offset, 32691a44019SRafał Miłecki AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */ 32791a44019SRafał Miłecki 32891a44019SRafał Miłecki /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */ 32991a44019SRafał Miłecki 33091a44019SRafał Miłecki WREG32(HDMI_ACR_PACKET_CONTROL + offset, 33191a44019SRafał Miłecki HDMI_ACR_AUTO_SEND | /* allow hw to sent ACR packets when required */ 33291a44019SRafał Miłecki HDMI_ACR_SOURCE); /* select SW CTS value */ 33391a44019SRafał Miłecki 33491a44019SRafał Miłecki evergreen_hdmi_update_ACR(encoder, mode->clock); 33591a44019SRafał Miłecki 336f93e3fc3SRafał Miłecki WREG32(AFMT_60958_0 + offset, 337f93e3fc3SRafał Miłecki AFMT_60958_CS_CHANNEL_NUMBER_L(1)); 338f93e3fc3SRafał Miłecki 339f93e3fc3SRafał Miłecki WREG32(AFMT_60958_1 + offset, 340f93e3fc3SRafał Miłecki AFMT_60958_CS_CHANNEL_NUMBER_R(2)); 341f93e3fc3SRafał Miłecki 342f93e3fc3SRafał Miłecki WREG32(AFMT_60958_2 + offset, 343f93e3fc3SRafał Miłecki AFMT_60958_CS_CHANNEL_NUMBER_2(3) | 344f93e3fc3SRafał Miłecki AFMT_60958_CS_CHANNEL_NUMBER_3(4) | 345f93e3fc3SRafał Miłecki AFMT_60958_CS_CHANNEL_NUMBER_4(5) | 346f93e3fc3SRafał Miłecki AFMT_60958_CS_CHANNEL_NUMBER_5(6) | 347f93e3fc3SRafał Miłecki AFMT_60958_CS_CHANNEL_NUMBER_6(7) | 348f93e3fc3SRafał Miłecki AFMT_60958_CS_CHANNEL_NUMBER_7(8)); 349f93e3fc3SRafał Miłecki 3506159b65aSRafał Miłecki if (ASIC_IS_DCE6(rdev)) { 3516159b65aSRafał Miłecki dce6_afmt_write_speaker_allocation(encoder); 3526159b65aSRafał Miłecki } else { 353ba7def4fSAlex Deucher dce4_afmt_write_speaker_allocation(encoder); 3546159b65aSRafał Miłecki } 355f93e3fc3SRafał Miłecki 356f93e3fc3SRafał Miłecki WREG32(AFMT_AUDIO_PACKET_CONTROL2 + offset, 357f93e3fc3SRafał Miłecki AFMT_AUDIO_CHANNEL_ENABLE(0xff)); 358f93e3fc3SRafał Miłecki 359f93e3fc3SRafał Miłecki /* fglrx sets 0x40 in 0x5f80 here */ 360b530602fSAlex Deucher 361b530602fSAlex Deucher if (ASIC_IS_DCE6(rdev)) { 362b530602fSAlex Deucher dce6_afmt_select_pin(encoder); 363b530602fSAlex Deucher dce6_afmt_write_sad_regs(encoder); 364b530602fSAlex Deucher } else { 36546892caaSRafał Miłecki evergreen_hdmi_write_sad_regs(encoder); 366*712fd8a2SAlex Deucher dce4_afmt_write_latency_fields(encoder, mode); 367b530602fSAlex Deucher } 368f93e3fc3SRafał Miłecki 369e3b2e034SThierry Reding err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); 370e3b2e034SThierry Reding if (err < 0) { 371e3b2e034SThierry Reding DRM_ERROR("failed to setup AVI infoframe: %zd\n", err); 372e3b2e034SThierry Reding return; 373e3b2e034SThierry Reding } 374e55d3e6cSRafał Miłecki 375e3b2e034SThierry Reding err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); 376e3b2e034SThierry Reding if (err < 0) { 377e3b2e034SThierry Reding DRM_ERROR("failed to pack AVI infoframe: %zd\n", err); 378e3b2e034SThierry Reding return; 379e3b2e034SThierry Reding } 380e3b2e034SThierry Reding 381e3b2e034SThierry Reding evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer)); 3821c3439f2SRafał Miłecki 383d3418eacSRafał Miłecki WREG32_OR(HDMI_INFOFRAME_CONTROL0 + offset, 384d3418eacSRafał Miłecki HDMI_AVI_INFO_SEND | /* enable AVI info frames */ 385d3418eacSRafał Miłecki HDMI_AVI_INFO_CONT); /* required for audio info values to be updated */ 386d3418eacSRafał Miłecki 387d3418eacSRafał Miłecki WREG32_P(HDMI_INFOFRAME_CONTROL1 + offset, 388d3418eacSRafał Miłecki HDMI_AVI_INFO_LINE(2), /* anything other than 0 */ 389d3418eacSRafał Miłecki ~HDMI_AVI_INFO_LINE_MASK); 390d3418eacSRafał Miłecki 391d3418eacSRafał Miłecki WREG32_OR(AFMT_AUDIO_PACKET_CONTROL + offset, 392d3418eacSRafał Miłecki AFMT_AUDIO_SAMPLE_SEND); /* send audio packets */ 393d3418eacSRafał Miłecki 394e55d3e6cSRafał Miłecki /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */ 395e55d3e6cSRafał Miłecki WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF); 396e55d3e6cSRafał Miłecki WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF); 397e55d3e6cSRafał Miłecki WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001); 398e55d3e6cSRafał Miłecki WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001); 399e55d3e6cSRafał Miłecki } 400a973bea1SAlex Deucher 401a973bea1SAlex Deucher void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable) 402a973bea1SAlex Deucher { 403b530602fSAlex Deucher struct drm_device *dev = encoder->dev; 404b530602fSAlex Deucher struct radeon_device *rdev = dev->dev_private; 405a973bea1SAlex Deucher struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 406a973bea1SAlex Deucher struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 407a973bea1SAlex Deucher 408c2b4cacfSAlex Deucher if (!dig || !dig->afmt) 409c2b4cacfSAlex Deucher return; 410c2b4cacfSAlex Deucher 411a973bea1SAlex Deucher /* Silent, r600_hdmi_enable will raise WARN for us */ 412a973bea1SAlex Deucher if (enable && dig->afmt->enabled) 413a973bea1SAlex Deucher return; 414a973bea1SAlex Deucher if (!enable && !dig->afmt->enabled) 415a973bea1SAlex Deucher return; 416a973bea1SAlex Deucher 417b530602fSAlex Deucher if (enable) { 418b530602fSAlex Deucher if (ASIC_IS_DCE6(rdev)) 419b530602fSAlex Deucher dig->afmt->pin = dce6_audio_get_pin(rdev); 420b530602fSAlex Deucher else 421b530602fSAlex Deucher dig->afmt->pin = r600_audio_get_pin(rdev); 422b530602fSAlex Deucher } else { 423b530602fSAlex Deucher dig->afmt->pin = NULL; 424b530602fSAlex Deucher } 425b530602fSAlex Deucher 426a973bea1SAlex Deucher dig->afmt->enabled = enable; 427a973bea1SAlex Deucher 428a973bea1SAlex Deucher DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n", 429a973bea1SAlex Deucher enable ? "En" : "Dis", dig->afmt->offset, radeon_encoder->encoder_id); 430a973bea1SAlex Deucher } 431