950-0799-ASoC-hdmi-codec-fix-channel-info-for-compressed-form.patch 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From 3f388718331b5ce2acd34730448db001759868aa Mon Sep 17 00:00:00 2001
  2. From: Matthias Reichl <[email protected]>
  3. Date: Sat, 24 Jun 2023 18:52:32 +0200
  4. Subject: [PATCH] ASoC: hdmi-codec: fix channel info for compressed formats
  5. commit 4e0871333661d2ec0ed3dc00a945c2160eccae77 upstream.
  6. According to CTA 861 the channel/speaker allocation info in the
  7. audio infoframe only applies to uncompressed (PCM) audio streams.
  8. The channel count info should indicate the number of channels
  9. in the transmitted audio, which usually won't match the number of
  10. channels used to transmit the compressed bitstream.
  11. Some devices (eg some Sony TVs) will refuse to decode compressed
  12. audio if these values are not set correctly.
  13. To fix this we can simply set the channel count to 0 (which means
  14. "refer to stream header") and set the channel/speaker allocation to 0
  15. as well (which would mean stereo FL/FR for PCM, a safe value all sinks
  16. will support) when transmitting compressed audio.
  17. Signed-off-by: Matthias Reichl <[email protected]>
  18. Link: https://lore.kernel.org/r/[email protected]
  19. Signed-off-by: Takashi Iwai <[email protected]>
  20. ---
  21. sound/soc/codecs/hdmi-codec.c | 36 +++++++++++++++++++++++------------
  22. 1 file changed, 24 insertions(+), 12 deletions(-)
  23. --- a/sound/soc/codecs/hdmi-codec.c
  24. +++ b/sound/soc/codecs/hdmi-codec.c
  25. @@ -484,31 +484,43 @@ static int hdmi_codec_fill_codec_params(
  26. struct hdmi_codec_params *hp)
  27. {
  28. struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
  29. - int idx;
  30. + int idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
  31. + u8 ca_id = 0;
  32. + bool pcm_audio = !(hcp->iec_status[0] & IEC958_AES0_NONAUDIO);
  33. +
  34. + if (pcm_audio) {
  35. + /* Select a channel allocation that matches with ELD and pcm channels */
  36. + idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels);
  37. +
  38. + if (idx < 0) {
  39. + dev_err(dai->dev, "Not able to map channels to speakers (%d)\n",
  40. + idx);
  41. + hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
  42. + return idx;
  43. + }
  44. - /* Select a channel allocation that matches with ELD and pcm channels */
  45. - idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels);
  46. - if (idx < 0) {
  47. - dev_err(dai->dev, "Not able to map channels to speakers (%d)\n",
  48. - idx);
  49. - hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
  50. - return idx;
  51. + ca_id = hdmi_codec_channel_alloc[idx].ca_id;
  52. }
  53. memset(hp, 0, sizeof(*hp));
  54. hdmi_audio_infoframe_init(&hp->cea);
  55. - hp->cea.channels = channels;
  56. +
  57. + if (pcm_audio)
  58. + hp->cea.channels = channels;
  59. + else
  60. + hp->cea.channels = 0;
  61. +
  62. hp->cea.coding_type = HDMI_AUDIO_CODING_TYPE_STREAM;
  63. hp->cea.sample_size = HDMI_AUDIO_SAMPLE_SIZE_STREAM;
  64. hp->cea.sample_frequency = HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM;
  65. - hp->cea.channel_allocation = hdmi_codec_channel_alloc[idx].ca_id;
  66. + hp->cea.channel_allocation = ca_id;
  67. hp->sample_width = sample_width;
  68. hp->sample_rate = sample_rate;
  69. hp->channels = channels;
  70. - hcp->chmap_idx = hdmi_codec_channel_alloc[idx].ca_id;
  71. + hcp->chmap_idx = idx;
  72. return 0;
  73. }