evergreen_hdmi.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. * update the N and CTS parameters for a given pixel clock rate
  35. */
  36. static void evergreen_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
  37. {
  38. struct drm_device *dev = encoder->dev;
  39. struct radeon_device *rdev = dev->dev_private;
  40. struct radeon_hdmi_acr acr = r600_hdmi_acr(clock);
  41. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  42. WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz));
  43. WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz);
  44. WREG32(HDMI_ACR_44_0 + offset, HDMI_ACR_CTS_44(acr.cts_44_1khz));
  45. WREG32(HDMI_ACR_44_1 + offset, acr.n_44_1khz);
  46. WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz));
  47. WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz);
  48. }
  49. /*
  50. * calculate the crc for a given info frame
  51. */
  52. static void evergreen_hdmi_infoframe_checksum(uint8_t packetType,
  53. uint8_t versionNumber,
  54. uint8_t length,
  55. uint8_t *frame)
  56. {
  57. int i;
  58. frame[0] = packetType + versionNumber + length;
  59. for (i = 1; i <= length; i++)
  60. frame[0] += frame[i];
  61. frame[0] = 0x100 - frame[0];
  62. }
  63. /*
  64. * build a HDMI Video Info Frame
  65. */
  66. static void evergreen_hdmi_videoinfoframe(
  67. struct drm_encoder *encoder,
  68. uint8_t color_format,
  69. int active_information_present,
  70. uint8_t active_format_aspect_ratio,
  71. uint8_t scan_information,
  72. uint8_t colorimetry,
  73. uint8_t ex_colorimetry,
  74. uint8_t quantization,
  75. int ITC,
  76. uint8_t picture_aspect_ratio,
  77. uint8_t video_format_identification,
  78. uint8_t pixel_repetition,
  79. uint8_t non_uniform_picture_scaling,
  80. uint8_t bar_info_data_valid,
  81. uint16_t top_bar,
  82. uint16_t bottom_bar,
  83. uint16_t left_bar,
  84. uint16_t right_bar
  85. )
  86. {
  87. struct drm_device *dev = encoder->dev;
  88. struct radeon_device *rdev = dev->dev_private;
  89. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  90. uint8_t frame[14];
  91. frame[0x0] = 0;
  92. frame[0x1] =
  93. (scan_information & 0x3) |
  94. ((bar_info_data_valid & 0x3) << 2) |
  95. ((active_information_present & 0x1) << 4) |
  96. ((color_format & 0x3) << 5);
  97. frame[0x2] =
  98. (active_format_aspect_ratio & 0xF) |
  99. ((picture_aspect_ratio & 0x3) << 4) |
  100. ((colorimetry & 0x3) << 6);
  101. frame[0x3] =
  102. (non_uniform_picture_scaling & 0x3) |
  103. ((quantization & 0x3) << 2) |
  104. ((ex_colorimetry & 0x7) << 4) |
  105. ((ITC & 0x1) << 7);
  106. frame[0x4] = (video_format_identification & 0x7F);
  107. frame[0x5] = (pixel_repetition & 0xF);
  108. frame[0x6] = (top_bar & 0xFF);
  109. frame[0x7] = (top_bar >> 8);
  110. frame[0x8] = (bottom_bar & 0xFF);
  111. frame[0x9] = (bottom_bar >> 8);
  112. frame[0xA] = (left_bar & 0xFF);
  113. frame[0xB] = (left_bar >> 8);
  114. frame[0xC] = (right_bar & 0xFF);
  115. frame[0xD] = (right_bar >> 8);
  116. evergreen_hdmi_infoframe_checksum(0x82, 0x02, 0x0D, frame);
  117. /* Our header values (type, version, length) should be alright, Intel
  118. * is using the same. Checksum function also seems to be OK, it works
  119. * fine for audio infoframe. However calculated value is always lower
  120. * by 2 in comparison to fglrx. It breaks displaying anything in case
  121. * of TVs that strictly check the checksum. Hack it manually here to
  122. * workaround this issue. */
  123. frame[0x0] += 2;
  124. WREG32(AFMT_AVI_INFO0 + offset,
  125. frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
  126. WREG32(AFMT_AVI_INFO1 + offset,
  127. frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
  128. WREG32(AFMT_AVI_INFO2 + offset,
  129. frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
  130. WREG32(AFMT_AVI_INFO3 + offset,
  131. frame[0xC] | (frame[0xD] << 8));
  132. }
  133. /*
  134. * update the info frames with the data from the current display mode
  135. */
  136. void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
  137. {
  138. struct drm_device *dev = encoder->dev;
  139. struct radeon_device *rdev = dev->dev_private;
  140. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  141. if (ASIC_IS_DCE5(rdev))
  142. return;
  143. if (!to_radeon_encoder(encoder)->hdmi_enabled)
  144. return;
  145. r600_audio_set_clock(encoder, mode->clock);
  146. WREG32(HDMI_VBI_PACKET_CONTROL + offset,
  147. HDMI_NULL_SEND); /* send null packets when required */
  148. WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
  149. WREG32(HDMI_AUDIO_PACKET_CONTROL + offset,
  150. HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */
  151. HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
  152. WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
  153. AFMT_AUDIO_SAMPLE_SEND | /* send audio packets */
  154. AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
  155. WREG32(HDMI_ACR_PACKET_CONTROL + offset,
  156. HDMI_ACR_AUTO_SEND | /* allow hw to sent ACR packets when required */
  157. HDMI_ACR_SOURCE); /* select SW CTS value */
  158. WREG32(HDMI_VBI_PACKET_CONTROL + offset,
  159. HDMI_NULL_SEND | /* send null packets when required */
  160. HDMI_GC_SEND | /* send general control packets */
  161. HDMI_GC_CONT); /* send general control packets every frame */
  162. WREG32(HDMI_INFOFRAME_CONTROL0 + offset,
  163. HDMI_AVI_INFO_SEND | /* enable AVI info frames */
  164. HDMI_AVI_INFO_CONT | /* send AVI info frames every frame/field */
  165. HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
  166. HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */
  167. WREG32(AFMT_INFOFRAME_CONTROL0 + offset,
  168. AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */
  169. WREG32(HDMI_INFOFRAME_CONTROL1 + offset,
  170. HDMI_AVI_INFO_LINE(2) | /* anything other than 0 */
  171. HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */
  172. WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
  173. evergreen_hdmi_videoinfoframe(encoder, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  174. 0, 0, 0, 0, 0, 0);
  175. evergreen_hdmi_update_ACR(encoder, mode->clock);
  176. /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
  177. WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
  178. WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
  179. WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
  180. WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
  181. }