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 | */ |
| 27 | #include "drmP.h" |
| 28 | #include "radeon_drm.h" |
| 29 | #include "radeon.h" |
| 30 | #include "radeon_asic.h" |
| 31 | #include "evergreend.h" |
| 32 | #include "atom.h" |
| 33 | |
| 34 | /* |
| 35 | * update the N and CTS parameters for a given pixel clock rate |
| 36 | */ |
| 37 | static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock) |
| 38 | { |
| 39 | struct drm_device *dev = encoder->dev; |
| 40 | struct radeon_device *rdev = dev->dev_private; |
| 41 | struct radeon_hdmi_acr acr = r600_hdmi_acr(clock); |
| 42 | uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset; |
| 43 | |
| 44 | WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz)); |
| 45 | WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz); |
| 46 | |
| 47 | WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz)); |
| 48 | WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz); |
| 49 | |
| 50 | WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz)); |
| 51 | WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz); |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * calculate the crc for a given info frame |
| 56 | */ |
| 57 | static void evergreen_hdmi_infoframe_checksum(uint8_t packetType, |
| 58 | uint8_t versionNumber, |
| 59 | uint8_t length, |
| 60 | uint8_t *frame) |
| 61 | { |
| 62 | int i; |
| 63 | frame[0] = packetType + versionNumber + length; |
| 64 | for (i = 1; i <= length; i++) |
| 65 | frame[0] += frame[i]; |
| 66 | frame[0] = 0x100 - frame[0]; |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * build a HDMI Video Info Frame |
| 71 | */ |
| 72 | static void evergreen_hdmi_videoinfoframe( |
| 73 | struct drm_encoder *encoder, |
| 74 | uint8_t color_format, |
| 75 | int active_information_present, |
| 76 | uint8_t active_format_aspect_ratio, |
| 77 | uint8_t scan_information, |
| 78 | uint8_t colorimetry, |
| 79 | uint8_t ex_colorimetry, |
| 80 | uint8_t quantization, |
| 81 | int ITC, |
| 82 | uint8_t picture_aspect_ratio, |
| 83 | uint8_t video_format_identification, |
| 84 | uint8_t pixel_repetition, |
| 85 | uint8_t non_uniform_picture_scaling, |
| 86 | uint8_t bar_info_data_valid, |
| 87 | uint16_t top_bar, |
| 88 | uint16_t bottom_bar, |
| 89 | uint16_t left_bar, |
| 90 | uint16_t right_bar |
| 91 | ) |
| 92 | { |
| 93 | struct drm_device *dev = encoder->dev; |
| 94 | struct radeon_device *rdev = dev->dev_private; |
| 95 | uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset; |
| 96 | |
| 97 | uint8_t frame[14]; |
| 98 | |
| 99 | frame[0x0] = 0; |
| 100 | frame[0x1] = |
| 101 | (scan_information & 0x3) | |
| 102 | ((bar_info_data_valid & 0x3) << 2) | |
| 103 | ((active_information_present & 0x1) << 4) | |
| 104 | ((color_format & 0x3) << 5); |
| 105 | frame[0x2] = |
| 106 | (active_format_aspect_ratio & 0xF) | |
| 107 | ((picture_aspect_ratio & 0x3) << 4) | |
| 108 | ((colorimetry & 0x3) << 6); |
| 109 | frame[0x3] = |
| 110 | (non_uniform_picture_scaling & 0x3) | |
| 111 | ((quantization & 0x3) << 2) | |
| 112 | ((ex_colorimetry & 0x7) << 4) | |
| 113 | ((ITC & 0x1) << 7); |
| 114 | frame[0x4] = (video_format_identification & 0x7F); |
| 115 | frame[0x5] = (pixel_repetition & 0xF); |
| 116 | frame[0x6] = (top_bar & 0xFF); |
| 117 | frame[0x7] = (top_bar >> 8); |
| 118 | frame[0x8] = (bottom_bar & 0xFF); |
| 119 | frame[0x9] = (bottom_bar >> 8); |
| 120 | frame[0xA] = (left_bar & 0xFF); |
| 121 | frame[0xB] = (left_bar >> 8); |
| 122 | frame[0xC] = (right_bar & 0xFF); |
| 123 | frame[0xD] = (right_bar >> 8); |
| 124 | |
| 125 | evergreen_hdmi_infoframe_checksum(0x82, 0x02, 0x0D, frame); |
| 126 | /* Our header values (type, version, length) should be alright, Intel |
| 127 | * is using the same. Checksum function also seems to be OK, it works |
| 128 | * fine for audio infoframe. However calculated value is always lower |
| 129 | * by 2 in comparison to fglrx. It breaks displaying anything in case |
| 130 | * of TVs that strictly check the checksum. Hack it manually here to |
| 131 | * workaround this issue. */ |
| 132 | frame[0x0] += 2; |
| 133 | |
| 134 | WREG32(AFMT_AVI_INFO0 + offset, |
| 135 | frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24)); |
| 136 | WREG32(AFMT_AVI_INFO1 + offset, |
| 137 | frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24)); |
| 138 | WREG32(AFMT_AVI_INFO2 + offset, |
| 139 | frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24)); |
| 140 | WREG32(AFMT_AVI_INFO3 + offset, |
| 141 | frame[0xC] | (frame[0xD] << 8)); |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * update the info frames with the data from the current display mode |
| 146 | */ |
| 147 | void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode) |
| 148 | { |
| 149 | struct drm_device *dev = encoder->dev; |
| 150 | struct radeon_device *rdev = dev->dev_private; |
| 151 | uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset; |
| 152 | |
| 153 | if (ASIC_IS_DCE5(rdev)) |
| 154 | return; |
| 155 | |
| 156 | if (!to_radeon_encoder(encoder)->hdmi_enabled) |
| 157 | return; |
| 158 | |
| 159 | r600_audio_set_clock(encoder, mode->clock); |
| 160 | |
| 161 | WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000); |
| 162 | WREG32(HDMI_GC + offset, 0x0); |
| 163 | |
| 164 | /* Send audio packets */ |
| 165 | WREG32_P(AFMT_AUDIO_PACKET_CONTROL + offset, |
| 166 | AFMT_AUDIO_SAMPLE_SEND, ~AFMT_AUDIO_SAMPLE_SEND); |
| 167 | |
| 168 | WREG32(HDMI_ACR_PACKET_CONTROL + offset, 0x1000); |
| 169 | |
| 170 | evergreen_hdmi_update_ACR(encoder, mode->clock); |
| 171 | |
| 172 | WREG32(HDMI_INFOFRAME_CONTROL0 + offset, 0x13); |
| 173 | |
| 174 | WREG32(HDMI_INFOFRAME_CONTROL1 + offset, 0x202); |
| 175 | |
| 176 | evergreen_hdmi_videoinfoframe(encoder, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 177 | 0, 0, 0, 0, 0, 0); |
| 178 | |
| 179 | /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */ |
| 180 | WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF); |
| 181 | WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF); |
| 182 | WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001); |
| 183 | WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001); |
| 184 | |
| 185 | /* audio packets per line, does anyone know how to calc this ? */ |
| 186 | WREG32_P(AFMT_AUDIO_PACKET_CONTROL + offset, 0x00040000, ~0x001F0000); |
| 187 | } |