r600_hdmi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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. */
  26. #include "drmP.h"
  27. #include "radeon_drm.h"
  28. #include "radeon.h"
  29. #include "radeon_asic.h"
  30. #include "atom.h"
  31. /*
  32. * HDMI color format
  33. */
  34. enum r600_hdmi_color_format {
  35. RGB = 0,
  36. YCC_422 = 1,
  37. YCC_444 = 2
  38. };
  39. /*
  40. * IEC60958 status bits
  41. */
  42. enum r600_hdmi_iec_status_bits {
  43. AUDIO_STATUS_DIG_ENABLE = 0x01,
  44. AUDIO_STATUS_V = 0x02,
  45. AUDIO_STATUS_VCFG = 0x04,
  46. AUDIO_STATUS_EMPHASIS = 0x08,
  47. AUDIO_STATUS_COPYRIGHT = 0x10,
  48. AUDIO_STATUS_NONAUDIO = 0x20,
  49. AUDIO_STATUS_PROFESSIONAL = 0x40,
  50. AUDIO_STATUS_LEVEL = 0x80
  51. };
  52. struct {
  53. uint32_t Clock;
  54. int N_32kHz;
  55. int CTS_32kHz;
  56. int N_44_1kHz;
  57. int CTS_44_1kHz;
  58. int N_48kHz;
  59. int CTS_48kHz;
  60. } r600_hdmi_ACR[] = {
  61. /* 32kHz 44.1kHz 48kHz */
  62. /* Clock N CTS N CTS N CTS */
  63. { 25174, 4576, 28125, 7007, 31250, 6864, 28125 }, /* 25,20/1.001 MHz */
  64. { 25200, 4096, 25200, 6272, 28000, 6144, 25200 }, /* 25.20 MHz */
  65. { 27000, 4096, 27000, 6272, 30000, 6144, 27000 }, /* 27.00 MHz */
  66. { 27027, 4096, 27027, 6272, 30030, 6144, 27027 }, /* 27.00*1.001 MHz */
  67. { 54000, 4096, 54000, 6272, 60000, 6144, 54000 }, /* 54.00 MHz */
  68. { 54054, 4096, 54054, 6272, 60060, 6144, 54054 }, /* 54.00*1.001 MHz */
  69. { 74175, 11648, 210937, 17836, 234375, 11648, 140625 }, /* 74.25/1.001 MHz */
  70. { 74250, 4096, 74250, 6272, 82500, 6144, 74250 }, /* 74.25 MHz */
  71. { 148351, 11648, 421875, 8918, 234375, 5824, 140625 }, /* 148.50/1.001 MHz */
  72. { 148500, 4096, 148500, 6272, 165000, 6144, 148500 }, /* 148.50 MHz */
  73. { 0, 4096, 0, 6272, 0, 6144, 0 } /* Other */
  74. };
  75. /*
  76. * calculate CTS value if it's not found in the table
  77. */
  78. static void r600_hdmi_calc_CTS(uint32_t clock, int *CTS, int N, int freq)
  79. {
  80. if (*CTS == 0)
  81. *CTS = clock * N / (128 * freq) * 1000;
  82. DRM_DEBUG("Using ACR timing N=%d CTS=%d for frequency %d\n",
  83. N, *CTS, freq);
  84. }
  85. /*
  86. * update the N and CTS parameters for a given pixel clock rate
  87. */
  88. static void r600_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
  89. {
  90. struct drm_device *dev = encoder->dev;
  91. struct radeon_device *rdev = dev->dev_private;
  92. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  93. int CTS;
  94. int N;
  95. int i;
  96. for (i = 0; r600_hdmi_ACR[i].Clock != clock && r600_hdmi_ACR[i].Clock != 0; i++);
  97. CTS = r600_hdmi_ACR[i].CTS_32kHz;
  98. N = r600_hdmi_ACR[i].N_32kHz;
  99. r600_hdmi_calc_CTS(clock, &CTS, N, 32000);
  100. WREG32(offset+R600_HDMI_32kHz_CTS, CTS << 12);
  101. WREG32(offset+R600_HDMI_32kHz_N, N);
  102. CTS = r600_hdmi_ACR[i].CTS_44_1kHz;
  103. N = r600_hdmi_ACR[i].N_44_1kHz;
  104. r600_hdmi_calc_CTS(clock, &CTS, N, 44100);
  105. WREG32(offset+R600_HDMI_44_1kHz_CTS, CTS << 12);
  106. WREG32(offset+R600_HDMI_44_1kHz_N, N);
  107. CTS = r600_hdmi_ACR[i].CTS_48kHz;
  108. N = r600_hdmi_ACR[i].N_48kHz;
  109. r600_hdmi_calc_CTS(clock, &CTS, N, 48000);
  110. WREG32(offset+R600_HDMI_48kHz_CTS, CTS << 12);
  111. WREG32(offset+R600_HDMI_48kHz_N, N);
  112. }
  113. /*
  114. * calculate the crc for a given info frame
  115. */
  116. static void r600_hdmi_infoframe_checksum(uint8_t packetType,
  117. uint8_t versionNumber,
  118. uint8_t length,
  119. uint8_t *frame)
  120. {
  121. int i;
  122. frame[0] = packetType + versionNumber + length;
  123. for (i = 1; i <= length; i++)
  124. frame[0] += frame[i];
  125. frame[0] = 0x100 - frame[0];
  126. }
  127. /*
  128. * build a HDMI Video Info Frame
  129. */
  130. static void r600_hdmi_videoinfoframe(
  131. struct drm_encoder *encoder,
  132. enum r600_hdmi_color_format color_format,
  133. int active_information_present,
  134. uint8_t active_format_aspect_ratio,
  135. uint8_t scan_information,
  136. uint8_t colorimetry,
  137. uint8_t ex_colorimetry,
  138. uint8_t quantization,
  139. int ITC,
  140. uint8_t picture_aspect_ratio,
  141. uint8_t video_format_identification,
  142. uint8_t pixel_repetition,
  143. uint8_t non_uniform_picture_scaling,
  144. uint8_t bar_info_data_valid,
  145. uint16_t top_bar,
  146. uint16_t bottom_bar,
  147. uint16_t left_bar,
  148. uint16_t right_bar
  149. )
  150. {
  151. struct drm_device *dev = encoder->dev;
  152. struct radeon_device *rdev = dev->dev_private;
  153. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  154. uint8_t frame[14];
  155. frame[0x0] = 0;
  156. frame[0x1] =
  157. (scan_information & 0x3) |
  158. ((bar_info_data_valid & 0x3) << 2) |
  159. ((active_information_present & 0x1) << 4) |
  160. ((color_format & 0x3) << 5);
  161. frame[0x2] =
  162. (active_format_aspect_ratio & 0xF) |
  163. ((picture_aspect_ratio & 0x3) << 4) |
  164. ((colorimetry & 0x3) << 6);
  165. frame[0x3] =
  166. (non_uniform_picture_scaling & 0x3) |
  167. ((quantization & 0x3) << 2) |
  168. ((ex_colorimetry & 0x7) << 4) |
  169. ((ITC & 0x1) << 7);
  170. frame[0x4] = (video_format_identification & 0x7F);
  171. frame[0x5] = (pixel_repetition & 0xF);
  172. frame[0x6] = (top_bar & 0xFF);
  173. frame[0x7] = (top_bar >> 8);
  174. frame[0x8] = (bottom_bar & 0xFF);
  175. frame[0x9] = (bottom_bar >> 8);
  176. frame[0xA] = (left_bar & 0xFF);
  177. frame[0xB] = (left_bar >> 8);
  178. frame[0xC] = (right_bar & 0xFF);
  179. frame[0xD] = (right_bar >> 8);
  180. r600_hdmi_infoframe_checksum(0x82, 0x02, 0x0D, frame);
  181. /* Our header values (type, version, length) should be alright, Intel
  182. * is using the same. Checksum function also seems to be OK, it works
  183. * fine for audio infoframe. However calculated value is always lower
  184. * by 2 in comparison to fglrx. It breaks displaying anything in case
  185. * of TVs that strictly check the checksum. Hack it manually here to
  186. * workaround this issue. */
  187. frame[0x0] += 2;
  188. WREG32(offset+R600_HDMI_VIDEOINFOFRAME_0,
  189. frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
  190. WREG32(offset+R600_HDMI_VIDEOINFOFRAME_1,
  191. frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
  192. WREG32(offset+R600_HDMI_VIDEOINFOFRAME_2,
  193. frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
  194. WREG32(offset+R600_HDMI_VIDEOINFOFRAME_3,
  195. frame[0xC] | (frame[0xD] << 8));
  196. }
  197. /*
  198. * build a Audio Info Frame
  199. */
  200. static void r600_hdmi_audioinfoframe(
  201. struct drm_encoder *encoder,
  202. uint8_t channel_count,
  203. uint8_t coding_type,
  204. uint8_t sample_size,
  205. uint8_t sample_frequency,
  206. uint8_t format,
  207. uint8_t channel_allocation,
  208. uint8_t level_shift,
  209. int downmix_inhibit
  210. )
  211. {
  212. struct drm_device *dev = encoder->dev;
  213. struct radeon_device *rdev = dev->dev_private;
  214. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  215. uint8_t frame[11];
  216. frame[0x0] = 0;
  217. frame[0x1] = (channel_count & 0x7) | ((coding_type & 0xF) << 4);
  218. frame[0x2] = (sample_size & 0x3) | ((sample_frequency & 0x7) << 2);
  219. frame[0x3] = format;
  220. frame[0x4] = channel_allocation;
  221. frame[0x5] = ((level_shift & 0xF) << 3) | ((downmix_inhibit & 0x1) << 7);
  222. frame[0x6] = 0;
  223. frame[0x7] = 0;
  224. frame[0x8] = 0;
  225. frame[0x9] = 0;
  226. frame[0xA] = 0;
  227. r600_hdmi_infoframe_checksum(0x84, 0x01, 0x0A, frame);
  228. WREG32(offset+R600_HDMI_AUDIOINFOFRAME_0,
  229. frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
  230. WREG32(offset+R600_HDMI_AUDIOINFOFRAME_1,
  231. frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x8] << 24));
  232. }
  233. /*
  234. * test if audio buffer is filled enough to start playing
  235. */
  236. static int r600_hdmi_is_audio_buffer_filled(struct drm_encoder *encoder)
  237. {
  238. struct drm_device *dev = encoder->dev;
  239. struct radeon_device *rdev = dev->dev_private;
  240. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  241. return (RREG32(offset+R600_HDMI_STATUS) & 0x10) != 0;
  242. }
  243. /*
  244. * have buffer status changed since last call?
  245. */
  246. int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder)
  247. {
  248. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  249. int status, result;
  250. if (!radeon_encoder->hdmi_offset)
  251. return 0;
  252. status = r600_hdmi_is_audio_buffer_filled(encoder);
  253. result = radeon_encoder->hdmi_buffer_status != status;
  254. radeon_encoder->hdmi_buffer_status = status;
  255. return result;
  256. }
  257. /*
  258. * write the audio workaround status to the hardware
  259. */
  260. void r600_hdmi_audio_workaround(struct drm_encoder *encoder)
  261. {
  262. struct drm_device *dev = encoder->dev;
  263. struct radeon_device *rdev = dev->dev_private;
  264. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  265. uint32_t offset = radeon_encoder->hdmi_offset;
  266. if (!offset)
  267. return;
  268. if (!radeon_encoder->hdmi_audio_workaround ||
  269. r600_hdmi_is_audio_buffer_filled(encoder)) {
  270. /* disable audio workaround */
  271. WREG32_P(offset+R600_HDMI_CNTL, 0x00000001, ~0x00001001);
  272. } else {
  273. /* enable audio workaround */
  274. WREG32_P(offset+R600_HDMI_CNTL, 0x00001001, ~0x00001001);
  275. }
  276. }
  277. /*
  278. * update the info frames with the data from the current display mode
  279. */
  280. void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
  281. {
  282. struct drm_device *dev = encoder->dev;
  283. struct radeon_device *rdev = dev->dev_private;
  284. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  285. if (ASIC_IS_DCE4(rdev))
  286. return;
  287. if (!offset)
  288. return;
  289. r600_audio_set_clock(encoder, mode->clock);
  290. WREG32(offset+R600_HDMI_UNKNOWN_0, 0x1000);
  291. WREG32(offset+R600_HDMI_UNKNOWN_1, 0x0);
  292. WREG32(offset+R600_HDMI_UNKNOWN_2, 0x1000);
  293. r600_hdmi_update_ACR(encoder, mode->clock);
  294. WREG32(offset+R600_HDMI_VIDEOCNTL, 0x13);
  295. WREG32(offset+R600_HDMI_VERSION, 0x202);
  296. r600_hdmi_videoinfoframe(encoder, RGB, 0, 0, 0, 0,
  297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  298. /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
  299. WREG32(offset+R600_HDMI_AUDIO_DEBUG_0, 0x00FFFFFF);
  300. WREG32(offset+R600_HDMI_AUDIO_DEBUG_1, 0x007FFFFF);
  301. WREG32(offset+R600_HDMI_AUDIO_DEBUG_2, 0x00000001);
  302. WREG32(offset+R600_HDMI_AUDIO_DEBUG_3, 0x00000001);
  303. r600_hdmi_audio_workaround(encoder);
  304. /* audio packets per line, does anyone know how to calc this ? */
  305. WREG32_P(offset+R600_HDMI_CNTL, 0x00040000, ~0x001F0000);
  306. }
  307. /*
  308. * update settings with current parameters from audio engine
  309. */
  310. void r600_hdmi_update_audio_settings(struct drm_encoder *encoder)
  311. {
  312. struct drm_device *dev = encoder->dev;
  313. struct radeon_device *rdev = dev->dev_private;
  314. uint32_t offset = to_radeon_encoder(encoder)->hdmi_offset;
  315. int channels = r600_audio_channels(rdev);
  316. int rate = r600_audio_rate(rdev);
  317. int bps = r600_audio_bits_per_sample(rdev);
  318. uint8_t status_bits = r600_audio_status_bits(rdev);
  319. uint8_t category_code = r600_audio_category_code(rdev);
  320. uint32_t iec;
  321. if (!offset)
  322. return;
  323. DRM_DEBUG("%s with %d channels, %d Hz sampling rate, %d bits per sample,\n",
  324. r600_hdmi_is_audio_buffer_filled(encoder) ? "playing" : "stopped",
  325. channels, rate, bps);
  326. DRM_DEBUG("0x%02X IEC60958 status bits and 0x%02X category code\n",
  327. (int)status_bits, (int)category_code);
  328. iec = 0;
  329. if (status_bits & AUDIO_STATUS_PROFESSIONAL)
  330. iec |= 1 << 0;
  331. if (status_bits & AUDIO_STATUS_NONAUDIO)
  332. iec |= 1 << 1;
  333. if (status_bits & AUDIO_STATUS_COPYRIGHT)
  334. iec |= 1 << 2;
  335. if (status_bits & AUDIO_STATUS_EMPHASIS)
  336. iec |= 1 << 3;
  337. iec |= category_code << 8;
  338. switch (rate) {
  339. case 32000: iec |= 0x3 << 24; break;
  340. case 44100: iec |= 0x0 << 24; break;
  341. case 88200: iec |= 0x8 << 24; break;
  342. case 176400: iec |= 0xc << 24; break;
  343. case 48000: iec |= 0x2 << 24; break;
  344. case 96000: iec |= 0xa << 24; break;
  345. case 192000: iec |= 0xe << 24; break;
  346. }
  347. WREG32(offset+R600_HDMI_IEC60958_1, iec);
  348. iec = 0;
  349. switch (bps) {
  350. case 16: iec |= 0x2; break;
  351. case 20: iec |= 0x3; break;
  352. case 24: iec |= 0xb; break;
  353. }
  354. if (status_bits & AUDIO_STATUS_V)
  355. iec |= 0x5 << 16;
  356. WREG32_P(offset+R600_HDMI_IEC60958_2, iec, ~0x5000f);
  357. /* 0x021 or 0x031 sets the audio frame length */
  358. WREG32(offset+R600_HDMI_AUDIOCNTL, 0x31);
  359. r600_hdmi_audioinfoframe(encoder, channels-1, 0, 0, 0, 0, 0, 0, 0);
  360. r600_hdmi_audio_workaround(encoder);
  361. }
  362. static int r600_hdmi_find_free_block(struct drm_device *dev)
  363. {
  364. struct radeon_device *rdev = dev->dev_private;
  365. struct drm_encoder *encoder;
  366. struct radeon_encoder *radeon_encoder;
  367. bool free_blocks[3] = { true, true, true };
  368. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  369. radeon_encoder = to_radeon_encoder(encoder);
  370. switch (radeon_encoder->hdmi_offset) {
  371. case R600_HDMI_BLOCK1:
  372. free_blocks[0] = false;
  373. break;
  374. case R600_HDMI_BLOCK2:
  375. free_blocks[1] = false;
  376. break;
  377. case R600_HDMI_BLOCK3:
  378. free_blocks[2] = false;
  379. break;
  380. }
  381. }
  382. if (rdev->family == CHIP_RS600 || rdev->family == CHIP_RS690 ||
  383. rdev->family == CHIP_RS740) {
  384. return free_blocks[0] ? R600_HDMI_BLOCK1 : 0;
  385. } else if (rdev->family >= CHIP_R600) {
  386. if (free_blocks[0])
  387. return R600_HDMI_BLOCK1;
  388. else if (free_blocks[1])
  389. return R600_HDMI_BLOCK2;
  390. }
  391. return 0;
  392. }
  393. static void r600_hdmi_assign_block(struct drm_encoder *encoder)
  394. {
  395. struct drm_device *dev = encoder->dev;
  396. struct radeon_device *rdev = dev->dev_private;
  397. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  398. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  399. if (!dig) {
  400. dev_err(rdev->dev, "Enabling HDMI on non-dig encoder\n");
  401. return;
  402. }
  403. if (ASIC_IS_DCE4(rdev)) {
  404. /* TODO */
  405. } else if (ASIC_IS_DCE3(rdev)) {
  406. radeon_encoder->hdmi_offset = dig->dig_encoder ?
  407. R600_HDMI_BLOCK3 : R600_HDMI_BLOCK1;
  408. if (ASIC_IS_DCE32(rdev))
  409. radeon_encoder->hdmi_config_offset = dig->dig_encoder ?
  410. R600_HDMI_CONFIG2 : R600_HDMI_CONFIG1;
  411. } else if (rdev->family >= CHIP_R600 || rdev->family == CHIP_RS600 ||
  412. rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) {
  413. radeon_encoder->hdmi_offset = r600_hdmi_find_free_block(dev);
  414. }
  415. }
  416. /*
  417. * enable the HDMI engine
  418. */
  419. void r600_hdmi_enable(struct drm_encoder *encoder)
  420. {
  421. struct drm_device *dev = encoder->dev;
  422. struct radeon_device *rdev = dev->dev_private;
  423. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  424. uint32_t offset;
  425. if (ASIC_IS_DCE4(rdev))
  426. return;
  427. if (!radeon_encoder->hdmi_offset) {
  428. r600_hdmi_assign_block(encoder);
  429. if (!radeon_encoder->hdmi_offset) {
  430. dev_warn(rdev->dev, "Could not find HDMI block for "
  431. "0x%x encoder\n", radeon_encoder->encoder_id);
  432. return;
  433. }
  434. }
  435. offset = radeon_encoder->hdmi_offset;
  436. if (ASIC_IS_DCE32(rdev) && !ASIC_IS_DCE4(rdev)) {
  437. WREG32_P(radeon_encoder->hdmi_config_offset + 0x4, 0x1, ~0x1);
  438. } else if (rdev->family >= CHIP_R600 && !ASIC_IS_DCE3(rdev)) {
  439. switch (radeon_encoder->encoder_id) {
  440. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  441. WREG32_P(AVIVO_TMDSA_CNTL, 0x4, ~0x4);
  442. WREG32(offset + R600_HDMI_ENABLE, 0x101);
  443. break;
  444. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  445. WREG32_P(AVIVO_LVTMA_CNTL, 0x4, ~0x4);
  446. WREG32(offset + R600_HDMI_ENABLE, 0x105);
  447. break;
  448. default:
  449. dev_err(rdev->dev, "Unknown HDMI output type\n");
  450. break;
  451. }
  452. }
  453. if (rdev->irq.installed
  454. && rdev->family != CHIP_RS600
  455. && rdev->family != CHIP_RS690
  456. && rdev->family != CHIP_RS740) {
  457. /* if irq is available use it */
  458. rdev->irq.hdmi[offset == R600_HDMI_BLOCK1 ? 0 : 1] = true;
  459. radeon_irq_set(rdev);
  460. r600_audio_disable_polling(encoder);
  461. } else {
  462. /* if not fallback to polling */
  463. r600_audio_enable_polling(encoder);
  464. }
  465. DRM_DEBUG("Enabling HDMI interface @ 0x%04X for encoder 0x%x\n",
  466. radeon_encoder->hdmi_offset, radeon_encoder->encoder_id);
  467. }
  468. /*
  469. * disable the HDMI engine
  470. */
  471. void r600_hdmi_disable(struct drm_encoder *encoder)
  472. {
  473. struct drm_device *dev = encoder->dev;
  474. struct radeon_device *rdev = dev->dev_private;
  475. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  476. uint32_t offset;
  477. if (ASIC_IS_DCE4(rdev))
  478. return;
  479. offset = radeon_encoder->hdmi_offset;
  480. if (!offset) {
  481. dev_err(rdev->dev, "Disabling not enabled HDMI\n");
  482. return;
  483. }
  484. DRM_DEBUG("Disabling HDMI interface @ 0x%04X for encoder 0x%x\n",
  485. offset, radeon_encoder->encoder_id);
  486. /* disable irq */
  487. rdev->irq.hdmi[offset == R600_HDMI_BLOCK1 ? 0 : 1] = false;
  488. radeon_irq_set(rdev);
  489. /* disable polling */
  490. r600_audio_disable_polling(encoder);
  491. if (ASIC_IS_DCE32(rdev) && !ASIC_IS_DCE4(rdev)) {
  492. WREG32_P(radeon_encoder->hdmi_config_offset + 0x4, 0, ~0x1);
  493. } else if (rdev->family >= CHIP_R600 && !ASIC_IS_DCE3(rdev)) {
  494. switch (radeon_encoder->encoder_id) {
  495. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  496. WREG32_P(AVIVO_TMDSA_CNTL, 0, ~0x4);
  497. WREG32(offset + R600_HDMI_ENABLE, 0);
  498. break;
  499. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  500. WREG32_P(AVIVO_LVTMA_CNTL, 0, ~0x4);
  501. WREG32(offset + R600_HDMI_ENABLE, 0);
  502. break;
  503. default:
  504. dev_err(rdev->dev, "Unknown HDMI output type\n");
  505. break;
  506. }
  507. }
  508. radeon_encoder->hdmi_offset = 0;
  509. radeon_encoder->hdmi_config_offset = 0;
  510. }