evergreen_hdmi.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <linux/hdmi.h>
  28. #include <drm/drmP.h>
  29. #include <drm/radeon_drm.h>
  30. #include "radeon.h"
  31. #include "radeon_asic.h"
  32. #include "evergreend.h"
  33. #include "atom.h"
  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. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  43. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  44. uint32_t offset = dig->afmt->offset;
  45. WREG32(HDMI_ACR_32_0 + offset, HDMI_ACR_CTS_32(acr.cts_32khz));
  46. WREG32(HDMI_ACR_32_1 + offset, acr.n_32khz);
  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. WREG32(HDMI_ACR_48_0 + offset, HDMI_ACR_CTS_48(acr.cts_48khz));
  50. WREG32(HDMI_ACR_48_1 + offset, acr.n_48khz);
  51. }
  52. /*
  53. * build a HDMI Video Info Frame
  54. */
  55. static void evergreen_hdmi_update_avi_infoframe(struct drm_encoder *encoder,
  56. void *buffer, size_t size)
  57. {
  58. struct drm_device *dev = encoder->dev;
  59. struct radeon_device *rdev = dev->dev_private;
  60. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  61. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  62. uint32_t offset = dig->afmt->offset;
  63. uint8_t *frame = buffer + 3;
  64. /* Our header values (type, version, length) should be alright, Intel
  65. * is using the same. Checksum function also seems to be OK, it works
  66. * fine for audio infoframe. However calculated value is always lower
  67. * by 2 in comparison to fglrx. It breaks displaying anything in case
  68. * of TVs that strictly check the checksum. Hack it manually here to
  69. * workaround this issue. */
  70. frame[0x0] += 2;
  71. WREG32(AFMT_AVI_INFO0 + offset,
  72. frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
  73. WREG32(AFMT_AVI_INFO1 + offset,
  74. frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
  75. WREG32(AFMT_AVI_INFO2 + offset,
  76. frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
  77. WREG32(AFMT_AVI_INFO3 + offset,
  78. frame[0xC] | (frame[0xD] << 8));
  79. }
  80. /*
  81. * update the info frames with the data from the current display mode
  82. */
  83. void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
  84. {
  85. struct drm_device *dev = encoder->dev;
  86. struct radeon_device *rdev = dev->dev_private;
  87. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  88. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  89. u8 buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AVI_INFOFRAME_SIZE];
  90. struct hdmi_avi_infoframe frame;
  91. uint32_t offset;
  92. ssize_t err;
  93. /* Silent, r600_hdmi_enable will raise WARN for us */
  94. if (!dig->afmt->enabled)
  95. return;
  96. offset = dig->afmt->offset;
  97. r600_audio_set_clock(encoder, mode->clock);
  98. WREG32(HDMI_VBI_PACKET_CONTROL + offset,
  99. HDMI_NULL_SEND); /* send null packets when required */
  100. WREG32(AFMT_AUDIO_CRC_CONTROL + offset, 0x1000);
  101. WREG32(HDMI_AUDIO_PACKET_CONTROL + offset,
  102. HDMI_AUDIO_DELAY_EN(1) | /* set the default audio delay */
  103. HDMI_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
  104. WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
  105. AFMT_AUDIO_SAMPLE_SEND | /* send audio packets */
  106. AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
  107. WREG32(HDMI_ACR_PACKET_CONTROL + offset,
  108. HDMI_ACR_AUTO_SEND | /* allow hw to sent ACR packets when required */
  109. HDMI_ACR_SOURCE); /* select SW CTS value */
  110. WREG32(HDMI_VBI_PACKET_CONTROL + offset,
  111. HDMI_NULL_SEND | /* send null packets when required */
  112. HDMI_GC_SEND | /* send general control packets */
  113. HDMI_GC_CONT); /* send general control packets every frame */
  114. WREG32(HDMI_INFOFRAME_CONTROL0 + offset,
  115. HDMI_AVI_INFO_SEND | /* enable AVI info frames */
  116. HDMI_AVI_INFO_CONT | /* send AVI info frames every frame/field */
  117. HDMI_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
  118. HDMI_AUDIO_INFO_CONT); /* required for audio info values to be updated */
  119. WREG32(AFMT_INFOFRAME_CONTROL0 + offset,
  120. AFMT_AUDIO_INFO_UPDATE); /* required for audio info values to be updated */
  121. WREG32(HDMI_INFOFRAME_CONTROL1 + offset,
  122. HDMI_AVI_INFO_LINE(2) | /* anything other than 0 */
  123. HDMI_AUDIO_INFO_LINE(2)); /* anything other than 0 */
  124. WREG32(HDMI_GC + offset, 0); /* unset HDMI_GC_AVMUTE */
  125. err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
  126. if (err < 0) {
  127. DRM_ERROR("failed to setup AVI infoframe: %zd\n", err);
  128. return;
  129. }
  130. err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
  131. if (err < 0) {
  132. DRM_ERROR("failed to pack AVI infoframe: %zd\n", err);
  133. return;
  134. }
  135. evergreen_hdmi_update_avi_infoframe(encoder, buffer, sizeof(buffer));
  136. evergreen_hdmi_update_ACR(encoder, mode->clock);
  137. /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
  138. WREG32(AFMT_RAMP_CONTROL0 + offset, 0x00FFFFFF);
  139. WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
  140. WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
  141. WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
  142. }