r600_hdmi.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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 "r600d.h"
  31. #include "atom.h"
  32. /*
  33. * HDMI color format
  34. */
  35. enum r600_hdmi_color_format {
  36. RGB = 0,
  37. YCC_422 = 1,
  38. YCC_444 = 2
  39. };
  40. /*
  41. * IEC60958 status bits
  42. */
  43. enum r600_hdmi_iec_status_bits {
  44. AUDIO_STATUS_DIG_ENABLE = 0x01,
  45. AUDIO_STATUS_V = 0x02,
  46. AUDIO_STATUS_VCFG = 0x04,
  47. AUDIO_STATUS_EMPHASIS = 0x08,
  48. AUDIO_STATUS_COPYRIGHT = 0x10,
  49. AUDIO_STATUS_NONAUDIO = 0x20,
  50. AUDIO_STATUS_PROFESSIONAL = 0x40,
  51. AUDIO_STATUS_LEVEL = 0x80
  52. };
  53. struct radeon_hdmi_acr r600_hdmi_predefined_acr[] = {
  54. /* 32kHz 44.1kHz 48kHz */
  55. /* Clock N CTS N CTS N CTS */
  56. { 25174, 4576, 28125, 7007, 31250, 6864, 28125 }, /* 25,20/1.001 MHz */
  57. { 25200, 4096, 25200, 6272, 28000, 6144, 25200 }, /* 25.20 MHz */
  58. { 27000, 4096, 27000, 6272, 30000, 6144, 27000 }, /* 27.00 MHz */
  59. { 27027, 4096, 27027, 6272, 30030, 6144, 27027 }, /* 27.00*1.001 MHz */
  60. { 54000, 4096, 54000, 6272, 60000, 6144, 54000 }, /* 54.00 MHz */
  61. { 54054, 4096, 54054, 6272, 60060, 6144, 54054 }, /* 54.00*1.001 MHz */
  62. { 74175, 11648, 210937, 17836, 234375, 11648, 140625 }, /* 74.25/1.001 MHz */
  63. { 74250, 4096, 74250, 6272, 82500, 6144, 74250 }, /* 74.25 MHz */
  64. { 148351, 11648, 421875, 8918, 234375, 5824, 140625 }, /* 148.50/1.001 MHz */
  65. { 148500, 4096, 148500, 6272, 165000, 6144, 148500 }, /* 148.50 MHz */
  66. { 0, 4096, 0, 6272, 0, 6144, 0 } /* Other */
  67. };
  68. /*
  69. * calculate CTS value if it's not found in the table
  70. */
  71. static void r600_hdmi_calc_cts(uint32_t clock, int *CTS, int N, int freq)
  72. {
  73. if (*CTS == 0)
  74. *CTS = clock * N / (128 * freq) * 1000;
  75. DRM_DEBUG("Using ACR timing N=%d CTS=%d for frequency %d\n",
  76. N, *CTS, freq);
  77. }
  78. struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock)
  79. {
  80. struct radeon_hdmi_acr res;
  81. u8 i;
  82. for (i = 0; r600_hdmi_predefined_acr[i].clock != clock &&
  83. r600_hdmi_predefined_acr[i].clock != 0; i++)
  84. ;
  85. res = r600_hdmi_predefined_acr[i];
  86. /* In case some CTS are missing */
  87. r600_hdmi_calc_cts(clock, &res.cts_32khz, res.n_32khz, 32000);
  88. r600_hdmi_calc_cts(clock, &res.cts_44_1khz, res.n_44_1khz, 44100);
  89. r600_hdmi_calc_cts(clock, &res.cts_48khz, res.n_48khz, 48000);
  90. return res;
  91. }
  92. /*
  93. * update the N and CTS parameters for a given pixel clock rate
  94. */
  95. static void r600_hdmi_update_ACR(struct drm_encoder *encoder, uint32_t clock)
  96. {
  97. struct drm_device *dev = encoder->dev;
  98. struct radeon_device *rdev = dev->dev_private;
  99. struct radeon_hdmi_acr acr = r600_hdmi_acr(clock);
  100. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  101. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  102. uint32_t offset = dig->afmt->offset;
  103. WREG32(HDMI0_ACR_32_0 + offset, HDMI0_ACR_CTS_32(acr.cts_32khz));
  104. WREG32(HDMI0_ACR_32_1 + offset, acr.n_32khz);
  105. WREG32(HDMI0_ACR_44_0 + offset, HDMI0_ACR_CTS_44(acr.cts_44_1khz));
  106. WREG32(HDMI0_ACR_44_1 + offset, acr.n_44_1khz);
  107. WREG32(HDMI0_ACR_48_0 + offset, HDMI0_ACR_CTS_48(acr.cts_48khz));
  108. WREG32(HDMI0_ACR_48_1 + offset, acr.n_48khz);
  109. }
  110. /*
  111. * calculate the crc for a given info frame
  112. */
  113. static void r600_hdmi_infoframe_checksum(uint8_t packetType,
  114. uint8_t versionNumber,
  115. uint8_t length,
  116. uint8_t *frame)
  117. {
  118. int i;
  119. frame[0] = packetType + versionNumber + length;
  120. for (i = 1; i <= length; i++)
  121. frame[0] += frame[i];
  122. frame[0] = 0x100 - frame[0];
  123. }
  124. /*
  125. * build a HDMI Video Info Frame
  126. */
  127. static void r600_hdmi_videoinfoframe(
  128. struct drm_encoder *encoder,
  129. enum r600_hdmi_color_format color_format,
  130. int active_information_present,
  131. uint8_t active_format_aspect_ratio,
  132. uint8_t scan_information,
  133. uint8_t colorimetry,
  134. uint8_t ex_colorimetry,
  135. uint8_t quantization,
  136. int ITC,
  137. uint8_t picture_aspect_ratio,
  138. uint8_t video_format_identification,
  139. uint8_t pixel_repetition,
  140. uint8_t non_uniform_picture_scaling,
  141. uint8_t bar_info_data_valid,
  142. uint16_t top_bar,
  143. uint16_t bottom_bar,
  144. uint16_t left_bar,
  145. uint16_t right_bar
  146. )
  147. {
  148. struct drm_device *dev = encoder->dev;
  149. struct radeon_device *rdev = dev->dev_private;
  150. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  151. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  152. uint32_t offset = dig->afmt->offset;
  153. uint8_t frame[14];
  154. frame[0x0] = 0;
  155. frame[0x1] =
  156. (scan_information & 0x3) |
  157. ((bar_info_data_valid & 0x3) << 2) |
  158. ((active_information_present & 0x1) << 4) |
  159. ((color_format & 0x3) << 5);
  160. frame[0x2] =
  161. (active_format_aspect_ratio & 0xF) |
  162. ((picture_aspect_ratio & 0x3) << 4) |
  163. ((colorimetry & 0x3) << 6);
  164. frame[0x3] =
  165. (non_uniform_picture_scaling & 0x3) |
  166. ((quantization & 0x3) << 2) |
  167. ((ex_colorimetry & 0x7) << 4) |
  168. ((ITC & 0x1) << 7);
  169. frame[0x4] = (video_format_identification & 0x7F);
  170. frame[0x5] = (pixel_repetition & 0xF);
  171. frame[0x6] = (top_bar & 0xFF);
  172. frame[0x7] = (top_bar >> 8);
  173. frame[0x8] = (bottom_bar & 0xFF);
  174. frame[0x9] = (bottom_bar >> 8);
  175. frame[0xA] = (left_bar & 0xFF);
  176. frame[0xB] = (left_bar >> 8);
  177. frame[0xC] = (right_bar & 0xFF);
  178. frame[0xD] = (right_bar >> 8);
  179. r600_hdmi_infoframe_checksum(0x82, 0x02, 0x0D, frame);
  180. /* Our header values (type, version, length) should be alright, Intel
  181. * is using the same. Checksum function also seems to be OK, it works
  182. * fine for audio infoframe. However calculated value is always lower
  183. * by 2 in comparison to fglrx. It breaks displaying anything in case
  184. * of TVs that strictly check the checksum. Hack it manually here to
  185. * workaround this issue. */
  186. frame[0x0] += 2;
  187. WREG32(HDMI0_AVI_INFO0 + offset,
  188. frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
  189. WREG32(HDMI0_AVI_INFO1 + offset,
  190. frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x7] << 24));
  191. WREG32(HDMI0_AVI_INFO2 + offset,
  192. frame[0x8] | (frame[0x9] << 8) | (frame[0xA] << 16) | (frame[0xB] << 24));
  193. WREG32(HDMI0_AVI_INFO3 + offset,
  194. frame[0xC] | (frame[0xD] << 8));
  195. }
  196. /*
  197. * build a Audio Info Frame
  198. */
  199. static void r600_hdmi_audioinfoframe(
  200. struct drm_encoder *encoder,
  201. uint8_t channel_count,
  202. uint8_t coding_type,
  203. uint8_t sample_size,
  204. uint8_t sample_frequency,
  205. uint8_t format,
  206. uint8_t channel_allocation,
  207. uint8_t level_shift,
  208. int downmix_inhibit
  209. )
  210. {
  211. struct drm_device *dev = encoder->dev;
  212. struct radeon_device *rdev = dev->dev_private;
  213. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  214. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  215. uint32_t offset = dig->afmt->offset;
  216. uint8_t frame[11];
  217. frame[0x0] = 0;
  218. frame[0x1] = (channel_count & 0x7) | ((coding_type & 0xF) << 4);
  219. frame[0x2] = (sample_size & 0x3) | ((sample_frequency & 0x7) << 2);
  220. frame[0x3] = format;
  221. frame[0x4] = channel_allocation;
  222. frame[0x5] = ((level_shift & 0xF) << 3) | ((downmix_inhibit & 0x1) << 7);
  223. frame[0x6] = 0;
  224. frame[0x7] = 0;
  225. frame[0x8] = 0;
  226. frame[0x9] = 0;
  227. frame[0xA] = 0;
  228. r600_hdmi_infoframe_checksum(0x84, 0x01, 0x0A, frame);
  229. WREG32(HDMI0_AUDIO_INFO0 + offset,
  230. frame[0x0] | (frame[0x1] << 8) | (frame[0x2] << 16) | (frame[0x3] << 24));
  231. WREG32(HDMI0_AUDIO_INFO1 + offset,
  232. frame[0x4] | (frame[0x5] << 8) | (frame[0x6] << 16) | (frame[0x8] << 24));
  233. }
  234. /*
  235. * test if audio buffer is filled enough to start playing
  236. */
  237. static bool r600_hdmi_is_audio_buffer_filled(struct drm_encoder *encoder)
  238. {
  239. struct drm_device *dev = encoder->dev;
  240. struct radeon_device *rdev = dev->dev_private;
  241. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  242. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  243. uint32_t offset = dig->afmt->offset;
  244. return (RREG32(HDMI0_STATUS + offset) & 0x10) != 0;
  245. }
  246. /*
  247. * have buffer status changed since last call?
  248. */
  249. int r600_hdmi_buffer_status_changed(struct drm_encoder *encoder)
  250. {
  251. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  252. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  253. int status, result;
  254. if (!dig->afmt || !dig->afmt->enabled)
  255. return 0;
  256. status = r600_hdmi_is_audio_buffer_filled(encoder);
  257. result = dig->afmt->last_buffer_filled_status != status;
  258. dig->afmt->last_buffer_filled_status = status;
  259. return result;
  260. }
  261. /*
  262. * write the audio workaround status to the hardware
  263. */
  264. static void r600_hdmi_audio_workaround(struct drm_encoder *encoder)
  265. {
  266. struct drm_device *dev = encoder->dev;
  267. struct radeon_device *rdev = dev->dev_private;
  268. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  269. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  270. uint32_t offset = dig->afmt->offset;
  271. bool hdmi_audio_workaround = false; /* FIXME */
  272. u32 value;
  273. if (!hdmi_audio_workaround ||
  274. r600_hdmi_is_audio_buffer_filled(encoder))
  275. value = 0; /* disable workaround */
  276. else
  277. value = HDMI0_AUDIO_TEST_EN; /* enable workaround */
  278. WREG32_P(HDMI0_AUDIO_PACKET_CONTROL + offset,
  279. value, ~HDMI0_AUDIO_TEST_EN);
  280. }
  281. /*
  282. * update the info frames with the data from the current display mode
  283. */
  284. void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode)
  285. {
  286. struct drm_device *dev = encoder->dev;
  287. struct radeon_device *rdev = dev->dev_private;
  288. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  289. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  290. uint32_t offset;
  291. if (ASIC_IS_DCE5(rdev))
  292. return;
  293. /* Silent, r600_hdmi_enable will raise WARN for us */
  294. if (!dig->afmt->enabled)
  295. return;
  296. offset = dig->afmt->offset;
  297. r600_audio_set_clock(encoder, mode->clock);
  298. WREG32(HDMI0_VBI_PACKET_CONTROL + offset,
  299. HDMI0_NULL_SEND); /* send null packets when required */
  300. WREG32(HDMI0_AUDIO_CRC_CONTROL + offset, 0x1000);
  301. if (ASIC_IS_DCE32(rdev)) {
  302. WREG32(HDMI0_AUDIO_PACKET_CONTROL + offset,
  303. HDMI0_AUDIO_DELAY_EN(1) | /* default audio delay */
  304. HDMI0_AUDIO_PACKETS_PER_LINE(3)); /* should be suffient for all audio modes and small enough for all hblanks */
  305. WREG32(AFMT_AUDIO_PACKET_CONTROL + offset,
  306. AFMT_AUDIO_SAMPLE_SEND | /* send audio packets */
  307. AFMT_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
  308. } else {
  309. WREG32(HDMI0_AUDIO_PACKET_CONTROL + offset,
  310. HDMI0_AUDIO_SAMPLE_SEND | /* send audio packets */
  311. HDMI0_AUDIO_DELAY_EN(1) | /* default audio delay */
  312. HDMI0_AUDIO_PACKETS_PER_LINE(3) | /* should be suffient for all audio modes and small enough for all hblanks */
  313. HDMI0_60958_CS_UPDATE); /* allow 60958 channel status fields to be updated */
  314. }
  315. WREG32(HDMI0_ACR_PACKET_CONTROL + offset,
  316. HDMI0_ACR_AUTO_SEND | /* allow hw to sent ACR packets when required */
  317. HDMI0_ACR_SOURCE); /* select SW CTS value */
  318. WREG32(HDMI0_VBI_PACKET_CONTROL + offset,
  319. HDMI0_NULL_SEND | /* send null packets when required */
  320. HDMI0_GC_SEND | /* send general control packets */
  321. HDMI0_GC_CONT); /* send general control packets every frame */
  322. /* TODO: HDMI0_AUDIO_INFO_UPDATE */
  323. WREG32(HDMI0_INFOFRAME_CONTROL0 + offset,
  324. HDMI0_AVI_INFO_SEND | /* enable AVI info frames */
  325. HDMI0_AVI_INFO_CONT | /* send AVI info frames every frame/field */
  326. HDMI0_AUDIO_INFO_SEND | /* enable audio info frames (frames won't be set until audio is enabled) */
  327. HDMI0_AUDIO_INFO_CONT); /* send audio info frames every frame/field */
  328. WREG32(HDMI0_INFOFRAME_CONTROL1 + offset,
  329. HDMI0_AVI_INFO_LINE(2) | /* anything other than 0 */
  330. HDMI0_AUDIO_INFO_LINE(2)); /* anything other than 0 */
  331. WREG32(HDMI0_GC + offset, 0); /* unset HDMI0_GC_AVMUTE */
  332. r600_hdmi_videoinfoframe(encoder, RGB, 0, 0, 0, 0,
  333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  334. r600_hdmi_update_ACR(encoder, mode->clock);
  335. /* it's unknown what these bits do excatly, but it's indeed quite useful for debugging */
  336. WREG32(HDMI0_RAMP_CONTROL0 + offset, 0x00FFFFFF);
  337. WREG32(HDMI0_RAMP_CONTROL1 + offset, 0x007FFFFF);
  338. WREG32(HDMI0_RAMP_CONTROL2 + offset, 0x00000001);
  339. WREG32(HDMI0_RAMP_CONTROL3 + offset, 0x00000001);
  340. r600_hdmi_audio_workaround(encoder);
  341. }
  342. /*
  343. * update settings with current parameters from audio engine
  344. */
  345. void r600_hdmi_update_audio_settings(struct drm_encoder *encoder)
  346. {
  347. struct drm_device *dev = encoder->dev;
  348. struct radeon_device *rdev = dev->dev_private;
  349. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  350. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  351. struct r600_audio audio = r600_audio_status(rdev);
  352. uint32_t offset;
  353. uint32_t iec;
  354. if (!dig->afmt || !dig->afmt->enabled)
  355. return;
  356. offset = dig->afmt->offset;
  357. DRM_DEBUG("%s with %d channels, %d Hz sampling rate, %d bits per sample,\n",
  358. r600_hdmi_is_audio_buffer_filled(encoder) ? "playing" : "stopped",
  359. audio.channels, audio.rate, audio.bits_per_sample);
  360. DRM_DEBUG("0x%02X IEC60958 status bits and 0x%02X category code\n",
  361. (int)audio.status_bits, (int)audio.category_code);
  362. iec = 0;
  363. if (audio.status_bits & AUDIO_STATUS_PROFESSIONAL)
  364. iec |= 1 << 0;
  365. if (audio.status_bits & AUDIO_STATUS_NONAUDIO)
  366. iec |= 1 << 1;
  367. if (audio.status_bits & AUDIO_STATUS_COPYRIGHT)
  368. iec |= 1 << 2;
  369. if (audio.status_bits & AUDIO_STATUS_EMPHASIS)
  370. iec |= 1 << 3;
  371. iec |= HDMI0_60958_CS_CATEGORY_CODE(audio.category_code);
  372. switch (audio.rate) {
  373. case 32000:
  374. iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0x3);
  375. break;
  376. case 44100:
  377. iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0x0);
  378. break;
  379. case 48000:
  380. iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0x2);
  381. break;
  382. case 88200:
  383. iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0x8);
  384. break;
  385. case 96000:
  386. iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0xa);
  387. break;
  388. case 176400:
  389. iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0xc);
  390. break;
  391. case 192000:
  392. iec |= HDMI0_60958_CS_SAMPLING_FREQUENCY(0xe);
  393. break;
  394. }
  395. WREG32(HDMI0_60958_0 + offset, iec);
  396. iec = 0;
  397. switch (audio.bits_per_sample) {
  398. case 16:
  399. iec |= HDMI0_60958_CS_WORD_LENGTH(0x2);
  400. break;
  401. case 20:
  402. iec |= HDMI0_60958_CS_WORD_LENGTH(0x3);
  403. break;
  404. case 24:
  405. iec |= HDMI0_60958_CS_WORD_LENGTH(0xb);
  406. break;
  407. }
  408. if (audio.status_bits & AUDIO_STATUS_V)
  409. iec |= 0x5 << 16;
  410. WREG32_P(HDMI0_60958_1 + offset, iec, ~0x5000f);
  411. r600_hdmi_audioinfoframe(encoder, audio.channels - 1, 0, 0, 0, 0, 0, 0,
  412. 0);
  413. r600_hdmi_audio_workaround(encoder);
  414. }
  415. /*
  416. * enable the HDMI engine
  417. */
  418. void r600_hdmi_enable(struct drm_encoder *encoder)
  419. {
  420. struct drm_device *dev = encoder->dev;
  421. struct radeon_device *rdev = dev->dev_private;
  422. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  423. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  424. uint32_t offset;
  425. u32 hdmi;
  426. if (ASIC_IS_DCE5(rdev))
  427. return;
  428. /* Silent, r600_hdmi_enable will raise WARN for us */
  429. if (dig->afmt->enabled)
  430. return;
  431. offset = dig->afmt->offset;
  432. /* Older chipsets require setting HDMI and routing manually */
  433. if (rdev->family >= CHIP_R600 && !ASIC_IS_DCE3(rdev)) {
  434. hdmi = HDMI0_ERROR_ACK | HDMI0_ENABLE;
  435. switch (radeon_encoder->encoder_id) {
  436. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  437. WREG32_P(AVIVO_TMDSA_CNTL, AVIVO_TMDSA_CNTL_HDMI_EN,
  438. ~AVIVO_TMDSA_CNTL_HDMI_EN);
  439. hdmi |= HDMI0_STREAM(HDMI0_STREAM_TMDSA);
  440. break;
  441. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  442. WREG32_P(AVIVO_LVTMA_CNTL, AVIVO_LVTMA_CNTL_HDMI_EN,
  443. ~AVIVO_LVTMA_CNTL_HDMI_EN);
  444. hdmi |= HDMI0_STREAM(HDMI0_STREAM_LVTMA);
  445. break;
  446. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  447. WREG32_P(DDIA_CNTL, DDIA_HDMI_EN, ~DDIA_HDMI_EN);
  448. hdmi |= HDMI0_STREAM(HDMI0_STREAM_DDIA);
  449. break;
  450. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  451. hdmi |= HDMI0_STREAM(HDMI0_STREAM_DVOA);
  452. break;
  453. default:
  454. dev_err(rdev->dev, "Invalid encoder for HDMI: 0x%X\n",
  455. radeon_encoder->encoder_id);
  456. break;
  457. }
  458. WREG32(HDMI0_CONTROL + offset, hdmi);
  459. }
  460. if (rdev->irq.installed) {
  461. /* if irq is available use it */
  462. rdev->irq.afmt[dig->afmt->id] = true;
  463. radeon_irq_set(rdev);
  464. }
  465. dig->afmt->enabled = true;
  466. DRM_DEBUG("Enabling HDMI interface @ 0x%04X for encoder 0x%x\n",
  467. offset, radeon_encoder->encoder_id);
  468. }
  469. /*
  470. * disable the HDMI engine
  471. */
  472. void r600_hdmi_disable(struct drm_encoder *encoder)
  473. {
  474. struct drm_device *dev = encoder->dev;
  475. struct radeon_device *rdev = dev->dev_private;
  476. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  477. struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
  478. uint32_t offset;
  479. if (ASIC_IS_DCE5(rdev))
  480. return;
  481. /* Called for ATOM_ENCODER_MODE_HDMI only */
  482. if (!dig || !dig->afmt) {
  483. WARN_ON(1);
  484. return;
  485. }
  486. if (!dig->afmt->enabled)
  487. return;
  488. offset = dig->afmt->offset;
  489. DRM_DEBUG("Disabling HDMI interface @ 0x%04X for encoder 0x%x\n",
  490. offset, radeon_encoder->encoder_id);
  491. /* disable irq */
  492. rdev->irq.afmt[dig->afmt->id] = false;
  493. radeon_irq_set(rdev);
  494. /* Older chipsets not handled by AtomBIOS */
  495. if (rdev->family >= CHIP_R600 && !ASIC_IS_DCE3(rdev)) {
  496. switch (radeon_encoder->encoder_id) {
  497. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
  498. WREG32_P(AVIVO_TMDSA_CNTL, 0,
  499. ~AVIVO_TMDSA_CNTL_HDMI_EN);
  500. break;
  501. case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
  502. WREG32_P(AVIVO_LVTMA_CNTL, 0,
  503. ~AVIVO_LVTMA_CNTL_HDMI_EN);
  504. break;
  505. case ENCODER_OBJECT_ID_INTERNAL_DDI:
  506. WREG32_P(DDIA_CNTL, 0, ~DDIA_HDMI_EN);
  507. break;
  508. case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
  509. break;
  510. default:
  511. dev_err(rdev->dev, "Invalid encoder for HDMI: 0x%X\n",
  512. radeon_encoder->encoder_id);
  513. break;
  514. }
  515. WREG32(HDMI0_CONTROL + offset, HDMI0_ERROR_ACK);
  516. }
  517. dig->afmt->enabled = false;
  518. }