dce3_1_afmt.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright 2013 Advanced Micro Devices, Inc.
  3. * Copyright 2014 Rafał Miłecki
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <linux/hdmi.h>
  24. #include <drm/drmP.h>
  25. #include "radeon.h"
  26. #include "radeon_asic.h"
  27. #include "radeon_audio.h"
  28. #include "r600d.h"
  29. void dce3_2_afmt_hdmi_write_speaker_allocation(struct drm_encoder *encoder,
  30. u8 *sadb, int sad_count)
  31. {
  32. struct radeon_device *rdev = encoder->dev->dev_private;
  33. u32 tmp;
  34. /* program the speaker allocation */
  35. tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
  36. tmp &= ~(DP_CONNECTION | SPEAKER_ALLOCATION_MASK);
  37. /* set HDMI mode */
  38. tmp |= HDMI_CONNECTION;
  39. if (sad_count)
  40. tmp |= SPEAKER_ALLOCATION(sadb[0]);
  41. else
  42. tmp |= SPEAKER_ALLOCATION(5); /* stereo */
  43. WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
  44. }
  45. void dce3_2_afmt_dp_write_speaker_allocation(struct drm_encoder *encoder,
  46. u8 *sadb, int sad_count)
  47. {
  48. struct radeon_device *rdev = encoder->dev->dev_private;
  49. u32 tmp;
  50. /* program the speaker allocation */
  51. tmp = RREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER);
  52. tmp &= ~(HDMI_CONNECTION | SPEAKER_ALLOCATION_MASK);
  53. /* set DP mode */
  54. tmp |= DP_CONNECTION;
  55. if (sad_count)
  56. tmp |= SPEAKER_ALLOCATION(sadb[0]);
  57. else
  58. tmp |= SPEAKER_ALLOCATION(5); /* stereo */
  59. WREG32_ENDPOINT(0, AZ_F0_CODEC_PIN0_CONTROL_CHANNEL_SPEAKER, tmp);
  60. }
  61. void dce3_2_afmt_write_sad_regs(struct drm_encoder *encoder,
  62. struct cea_sad *sads, int sad_count)
  63. {
  64. int i;
  65. struct radeon_device *rdev = encoder->dev->dev_private;
  66. static const u16 eld_reg_to_type[][2] = {
  67. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR0, HDMI_AUDIO_CODING_TYPE_PCM },
  68. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR1, HDMI_AUDIO_CODING_TYPE_AC3 },
  69. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR2, HDMI_AUDIO_CODING_TYPE_MPEG1 },
  70. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR3, HDMI_AUDIO_CODING_TYPE_MP3 },
  71. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR4, HDMI_AUDIO_CODING_TYPE_MPEG2 },
  72. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR5, HDMI_AUDIO_CODING_TYPE_AAC_LC },
  73. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR6, HDMI_AUDIO_CODING_TYPE_DTS },
  74. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR7, HDMI_AUDIO_CODING_TYPE_ATRAC },
  75. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR9, HDMI_AUDIO_CODING_TYPE_EAC3 },
  76. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR10, HDMI_AUDIO_CODING_TYPE_DTS_HD },
  77. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR11, HDMI_AUDIO_CODING_TYPE_MLP },
  78. { AZ_F0_CODEC_PIN0_CONTROL_AUDIO_DESCRIPTOR13, HDMI_AUDIO_CODING_TYPE_WMA_PRO },
  79. };
  80. for (i = 0; i < ARRAY_SIZE(eld_reg_to_type); i++) {
  81. u32 value = 0;
  82. u8 stereo_freqs = 0;
  83. int max_channels = -1;
  84. int j;
  85. for (j = 0; j < sad_count; j++) {
  86. struct cea_sad *sad = &sads[j];
  87. if (sad->format == eld_reg_to_type[i][1]) {
  88. if (sad->channels > max_channels) {
  89. value = MAX_CHANNELS(sad->channels) |
  90. DESCRIPTOR_BYTE_2(sad->byte2) |
  91. SUPPORTED_FREQUENCIES(sad->freq);
  92. max_channels = sad->channels;
  93. }
  94. if (sad->format == HDMI_AUDIO_CODING_TYPE_PCM)
  95. stereo_freqs |= sad->freq;
  96. else
  97. break;
  98. }
  99. }
  100. value |= SUPPORTED_FREQUENCIES_STEREO(stereo_freqs);
  101. WREG32_ENDPOINT(0, eld_reg_to_type[i][0], value);
  102. }
  103. }
  104. void dce3_2_audio_set_dto(struct radeon_device *rdev,
  105. struct radeon_crtc *crtc, unsigned int clock)
  106. {
  107. struct radeon_encoder *radeon_encoder;
  108. struct radeon_encoder_atom_dig *dig;
  109. unsigned int max_ratio = clock / 24000;
  110. u32 dto_phase;
  111. u32 wallclock_ratio;
  112. u32 dto_cntl;
  113. if (!crtc)
  114. return;
  115. radeon_encoder = to_radeon_encoder(crtc->encoder);
  116. dig = radeon_encoder->enc_priv;
  117. if (!dig)
  118. return;
  119. if (max_ratio >= 8) {
  120. dto_phase = 192 * 1000;
  121. wallclock_ratio = 3;
  122. } else if (max_ratio >= 4) {
  123. dto_phase = 96 * 1000;
  124. wallclock_ratio = 2;
  125. } else if (max_ratio >= 2) {
  126. dto_phase = 48 * 1000;
  127. wallclock_ratio = 1;
  128. } else {
  129. dto_phase = 24 * 1000;
  130. wallclock_ratio = 0;
  131. }
  132. /* Express [24MHz / target pixel clock] as an exact rational
  133. * number (coefficient of two integer numbers. DCCG_AUDIO_DTOx_PHASE
  134. * is the numerator, DCCG_AUDIO_DTOx_MODULE is the denominator
  135. */
  136. if (dig->dig_encoder == 0) {
  137. dto_cntl = RREG32(DCCG_AUDIO_DTO0_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK;
  138. dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio);
  139. WREG32(DCCG_AUDIO_DTO0_CNTL, dto_cntl);
  140. WREG32(DCCG_AUDIO_DTO0_PHASE, dto_phase);
  141. WREG32(DCCG_AUDIO_DTO0_MODULE, clock);
  142. WREG32(DCCG_AUDIO_DTO_SELECT, 0); /* select DTO0 */
  143. } else {
  144. dto_cntl = RREG32(DCCG_AUDIO_DTO1_CNTL) & ~DCCG_AUDIO_DTO_WALLCLOCK_RATIO_MASK;
  145. dto_cntl |= DCCG_AUDIO_DTO_WALLCLOCK_RATIO(wallclock_ratio);
  146. WREG32(DCCG_AUDIO_DTO1_CNTL, dto_cntl);
  147. WREG32(DCCG_AUDIO_DTO1_PHASE, dto_phase);
  148. WREG32(DCCG_AUDIO_DTO1_MODULE, clock);
  149. WREG32(DCCG_AUDIO_DTO_SELECT, 1); /* select DTO1 */
  150. }
  151. }
  152. void dce3_2_hdmi_update_acr(struct drm_encoder *encoder, long offset,
  153. const struct radeon_hdmi_acr *acr)
  154. {
  155. struct drm_device *dev = encoder->dev;
  156. struct radeon_device *rdev = dev->dev_private;
  157. WREG32(DCE3_HDMI0_ACR_PACKET_CONTROL + offset,
  158. HDMI0_ACR_SOURCE | /* select SW CTS value */
  159. HDMI0_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */
  160. WREG32_P(HDMI0_ACR_32_0 + offset,
  161. HDMI0_ACR_CTS_32(acr->cts_32khz),
  162. ~HDMI0_ACR_CTS_32_MASK);
  163. WREG32_P(HDMI0_ACR_32_1 + offset,
  164. HDMI0_ACR_N_32(acr->n_32khz),
  165. ~HDMI0_ACR_N_32_MASK);
  166. WREG32_P(HDMI0_ACR_44_0 + offset,
  167. HDMI0_ACR_CTS_44(acr->cts_44_1khz),
  168. ~HDMI0_ACR_CTS_44_MASK);
  169. WREG32_P(HDMI0_ACR_44_1 + offset,
  170. HDMI0_ACR_N_44(acr->n_44_1khz),
  171. ~HDMI0_ACR_N_44_MASK);
  172. WREG32_P(HDMI0_ACR_48_0 + offset,
  173. HDMI0_ACR_CTS_48(acr->cts_48khz),
  174. ~HDMI0_ACR_CTS_48_MASK);
  175. WREG32_P(HDMI0_ACR_48_1 + offset,
  176. HDMI0_ACR_N_48(acr->n_48khz),
  177. ~HDMI0_ACR_N_48_MASK);
  178. }
  179. void dce3_2_set_audio_packet(struct drm_encoder *encoder, u32 offset)
  180. {
  181. struct drm_device *dev = encoder->dev;
  182. struct radeon_device *rdev = dev->dev_private;
  183. WREG32(HDMI0_AUDIO_PACKET_CONTROL + offset,
  184. HDMI0_AUDIO_DELAY_EN(1) | /* default audio delay */
  185. HDMI0_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
  186. WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
  187. AFMT_AUDIO_SAMPLE_SEND | /* send audio packets */
  188. AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
  189. WREG32_OR(HDMI0_INFOFRAME_CONTROL0 + offset,
  190. HDMI0_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
  191. HDMI0_AUDIO_INFO_CONT); /* send audio info frames every frame/field */
  192. WREG32_OR(HDMI0_INFOFRAME_CONTROL1 + offset,
  193. HDMI0_AUDIO_INFO_LINE(2)); /* anything other than 0 */
  194. }
  195. void dce3_2_set_mute(struct drm_encoder *encoder, u32 offset, bool mute)
  196. {
  197. struct drm_device *dev = encoder->dev;
  198. struct radeon_device *rdev = dev->dev_private;
  199. if (mute)
  200. WREG32_OR(HDMI0_GC + offset, HDMI0_GC_AVMUTE);
  201. else
  202. WREG32_AND(HDMI0_GC + offset, ~HDMI0_GC_AVMUTE);
  203. }