bcm27xx: update 6.1 patches to latest version
[openwrt/staging/dangole.git] / target / linux / bcm27xx / patches-6.1 / 950-0799-ASoC-hdmi-codec-fix-channel-info-for-compressed-form.patch
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
5
6 commit 4e0871333661d2ec0ed3dc00a945c2160eccae77 upstream.
7
8 According to CTA 861 the channel/speaker allocation info in the
9 audio infoframe only applies to uncompressed (PCM) audio streams.
10
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.
14
15 Some devices (eg some Sony TVs) will refuse to decode compressed
16 audio if these values are not set correctly.
17
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.
22
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>
26 ---
27 sound/soc/codecs/hdmi-codec.c | 36 +++++++++++++++++++++++------------
28 1 file changed, 24 insertions(+), 12 deletions(-)
29
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)
34 {
35 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);
36 - int idx;
37 + int idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
38 + u8 ca_id = 0;
39 + bool pcm_audio = !(hcp->iec_status[0] & IEC958_AES0_NONAUDIO);
40 +
41 + if (pcm_audio) {
42 + /* Select a channel allocation that matches with ELD and pcm channels */
43 + idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels);
44 +
45 + if (idx < 0) {
46 + dev_err(dai->dev, "Not able to map channels to speakers (%d)\n",
47 + idx);
48 + hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
49 + return idx;
50 + }
51
52 - /* Select a channel allocation that matches with ELD and pcm channels */
53 - idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels);
54 - if (idx < 0) {
55 - dev_err(dai->dev, "Not able to map channels to speakers (%d)\n",
56 - idx);
57 - hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
58 - return idx;
59 + ca_id = hdmi_codec_channel_alloc[idx].ca_id;
60 }
61
62 memset(hp, 0, sizeof(*hp));
63
64 hdmi_audio_infoframe_init(&hp->cea);
65 - hp->cea.channels = channels;
66 +
67 + if (pcm_audio)
68 + hp->cea.channels = channels;
69 + else
70 + hp->cea.channels = 0;
71 +
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;
77
78 hp->sample_width = sample_width;
79 hp->sample_rate = sample_rate;
80 hp->channels = channels;
81
82 - hcp->chmap_idx = hdmi_codec_channel_alloc[idx].ca_id;
83 + hcp->chmap_idx = idx;
84
85 return 0;
86 }