1 From e866f9fc7c6dd6af1e74ce6fa50db9ba21acae5e Mon Sep 17 00:00:00 2001
2 From: Matthias Reichl <hias@horus.com>
3 Date: Sat, 24 Jun 2023 18:52:16 +0200
4 Subject: [PATCH] ALSA: pcm: fix ELD constraints for (E)AC3, DTS(-HD) and MLP
7 commit 04b49b90caeed0b5544ff616d654900d27d403b6 upstream.
9 The SADs of compressed formats contain the channel and sample rate
10 info of the audio data inside the compressed stream, but when
11 building constraints we must use the rates and channels used to
12 transport the compressed streams.
14 eg 48kHz 6ch EAC3 needs to be transmitted as a 2ch 192kHz stream.
16 This patch fixes the constraints for the common AC3 and DTS formats,
17 the constraints for the less common MPEG, DSD etc formats are copied
18 directly from the info in the SADs as before as I don't have the specs
19 and equipment to test those.
21 Signed-off-by: Matthias Reichl <hias@horus.com>
22 Link: https://lore.kernel.org/r/20230624165216.5719-1-hias@horus.com
23 Signed-off-by: Takashi Iwai <tiwai@suse.de>
25 sound/core/pcm_drm_eld.c | 73 ++++++++++++++++++++++++++++++++++++++--
26 1 file changed, 70 insertions(+), 3 deletions(-)
28 --- a/sound/core/pcm_drm_eld.c
29 +++ b/sound/core/pcm_drm_eld.c
34 +#include <linux/bitfield.h>
35 #include <linux/export.h>
36 +#include <linux/hdmi.h>
37 #include <drm/drm_edid.h>
38 #include <sound/pcm.h>
39 #include <sound/pcm_drm_eld.h>
41 +#define SAD0_CHANNELS_MASK GENMASK(2, 0) /* max number of channels - 1 */
42 +#define SAD0_FORMAT_MASK GENMASK(6, 3) /* audio format */
44 +#define SAD1_RATE_MASK GENMASK(6, 0) /* bitfield of supported rates */
45 +#define SAD1_RATE_32000_MASK BIT(0)
46 +#define SAD1_RATE_44100_MASK BIT(1)
47 +#define SAD1_RATE_48000_MASK BIT(2)
48 +#define SAD1_RATE_88200_MASK BIT(3)
49 +#define SAD1_RATE_96000_MASK BIT(4)
50 +#define SAD1_RATE_176400_MASK BIT(5)
51 +#define SAD1_RATE_192000_MASK BIT(6)
53 static const unsigned int eld_rates[] = {
56 @@ -17,9 +31,62 @@ static const unsigned int eld_rates[] =
60 +static unsigned int map_rate_families(const u8 *sad,
61 + unsigned int mask_32000,
62 + unsigned int mask_44100,
63 + unsigned int mask_48000)
65 + unsigned int rate_mask = 0;
67 + if (sad[1] & SAD1_RATE_32000_MASK)
68 + rate_mask |= mask_32000;
69 + if (sad[1] & (SAD1_RATE_44100_MASK | SAD1_RATE_88200_MASK | SAD1_RATE_176400_MASK))
70 + rate_mask |= mask_44100;
71 + if (sad[1] & (SAD1_RATE_48000_MASK | SAD1_RATE_96000_MASK | SAD1_RATE_192000_MASK))
72 + rate_mask |= mask_48000;
76 +static unsigned int sad_rate_mask(const u8 *sad)
78 + switch (FIELD_GET(SAD0_FORMAT_MASK, sad[0])) {
79 + case HDMI_AUDIO_CODING_TYPE_PCM:
80 + return sad[1] & SAD1_RATE_MASK;
81 + case HDMI_AUDIO_CODING_TYPE_AC3:
82 + case HDMI_AUDIO_CODING_TYPE_DTS:
83 + return map_rate_families(sad,
84 + SAD1_RATE_32000_MASK,
85 + SAD1_RATE_44100_MASK,
86 + SAD1_RATE_48000_MASK);
87 + case HDMI_AUDIO_CODING_TYPE_EAC3:
88 + case HDMI_AUDIO_CODING_TYPE_DTS_HD:
89 + case HDMI_AUDIO_CODING_TYPE_MLP:
90 + return map_rate_families(sad,
92 + SAD1_RATE_176400_MASK,
93 + SAD1_RATE_192000_MASK);
95 + /* TODO adjust for other compressed formats as well */
96 + return sad[1] & SAD1_RATE_MASK;
100 static unsigned int sad_max_channels(const u8 *sad)
102 - return 1 + (sad[0] & 7);
103 + switch (FIELD_GET(SAD0_FORMAT_MASK, sad[0])) {
104 + case HDMI_AUDIO_CODING_TYPE_PCM:
105 + return 1 + FIELD_GET(SAD0_CHANNELS_MASK, sad[0]);
106 + case HDMI_AUDIO_CODING_TYPE_AC3:
107 + case HDMI_AUDIO_CODING_TYPE_DTS:
108 + case HDMI_AUDIO_CODING_TYPE_EAC3:
110 + case HDMI_AUDIO_CODING_TYPE_DTS_HD:
111 + case HDMI_AUDIO_CODING_TYPE_MLP:
114 + /* TODO adjust for other compressed formats as well */
115 + return 1 + FIELD_GET(SAD0_CHANNELS_MASK, sad[0]);
119 static int eld_limit_rates(struct snd_pcm_hw_params *params,
120 @@ -42,7 +109,7 @@ static int eld_limit_rates(struct snd_pc
121 * requested number of channels.
123 if (c->min <= max_channels)
124 - rate_mask |= sad[1];
125 + rate_mask |= sad_rate_mask(sad);
129 @@ -70,7 +137,7 @@ static int eld_limit_channels(struct snd
132 for (i = drm_eld_sad_count(eld); i > 0; i--, sad += 3)
133 - if (rate_mask & sad[1])
134 + if (rate_mask & sad_rate_mask(sad))
135 t.max = max(t.max, sad_max_channels(sad));