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