Skip to contentSkip to conversation

ASoC: hdmi-codec: add ELD information to procfs

PATCH In review Dmitry Baryshkov 5 participants 8 messages Jan 24, 2025 – Apr 7, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ASoC: hdmi-codec: add ELD information to procfs

Follow the HDA lead and add ELD-related information to procfs for the ASoC / HDMI-codec cards.

---
Dmitry Baryshkov (2):
ALSA: hda/hdmi: extract common interface for ELD handling
ASoC: hdmi-codec: dump ELD through procfs

 include/sound/pcm_drm_eld.h   |  91 ++++++++++
 sound/core/pcm_drm_eld.c      | 387 ++++++++++++++++++++++++++++++++++++++++++
 sound/pci/hda/Kconfig         |   1 +
 sound/pci/hda/hda_eld.c       | 385 +----------------------------------------
 sound/pci/hda/hda_local.h     |  49 +-----
 sound/pci/hda/patch_hdmi.c    |   6 +-
 sound/soc/codecs/hdmi-codec.c |  68 ++++++++
 7 files changed, 562 insertions(+), 425 deletions(-)

---
base-commit: d5e972e5216ebd4cb9a0bb0b0bd310b86f270d36
change-id: 20250124-alsa-hdmi-codec-eld-09fcc1cc005a

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>
#1 lore raw

PATCH 1/2 ALSA: hda/hdmi: extract common interface for ELD handling

Other HDMI-related cards (e.g. hdmi-codec) are also using the ELD. Exrtact common set of interfaces for handling the ELD.

---
 include/sound/pcm_drm_eld.h |  91 +++++++++++
 sound/core/pcm_drm_eld.c    | 387 ++++++++++++++++++++++++++++++++++++++++++++
 sound/pci/hda/Kconfig       |   1 +
 sound/pci/hda/hda_eld.c     | 385 +------------------------------------------
 sound/pci/hda/hda_local.h   |  49 +-----
 sound/pci/hda/patch_hdmi.c  |   6 +-
 6 files changed, 494 insertions(+), 425 deletions(-)
include/sound/pcm_drm_eld.h +91 -0
index 28a55a8beb287ca3b4fbdd945982df3e24544c9f..5a38413ada916456633514b32eed573b45e7b39a 100644
@@ -2,6 +2,97 @@
 #ifndef __SOUND_PCM_DRM_ELD_H
 #define __SOUND_PCM_DRM_ELD_H
 
+enum eld_versions {
+	ELD_VER_CEA_861D	= 2,
+	ELD_VER_PARTIAL		= 31,
+};
+
+enum cea_audio_coding_types {
+	AUDIO_CODING_TYPE_REF_STREAM_HEADER	=  0,
+	AUDIO_CODING_TYPE_LPCM			=  1,
+	AUDIO_CODING_TYPE_AC3			=  2,
+	AUDIO_CODING_TYPE_MPEG1			=  3,
+	AUDIO_CODING_TYPE_MP3			=  4,
+	AUDIO_CODING_TYPE_MPEG2			=  5,
+	AUDIO_CODING_TYPE_AACLC			=  6,
+	AUDIO_CODING_TYPE_DTS			=  7,
+	AUDIO_CODING_TYPE_ATRAC			=  8,
+	AUDIO_CODING_TYPE_SACD			=  9,
+	AUDIO_CODING_TYPE_EAC3			= 10,
+	AUDIO_CODING_TYPE_DTS_HD		= 11,
+	AUDIO_CODING_TYPE_MLP			= 12,
+	AUDIO_CODING_TYPE_DST			= 13,
+	AUDIO_CODING_TYPE_WMAPRO		= 14,
+	AUDIO_CODING_TYPE_REF_CXT		= 15,
+	/* also include valid xtypes below */
+	AUDIO_CODING_TYPE_HE_AAC		= 15,
+	AUDIO_CODING_TYPE_HE_AAC2		= 16,
+	AUDIO_CODING_TYPE_MPEG_SURROUND		= 17,
+};
+
+enum cea_audio_coding_xtypes {
+	AUDIO_CODING_XTYPE_HE_REF_CT		= 0,
+	AUDIO_CODING_XTYPE_HE_AAC		= 1,
+	AUDIO_CODING_XTYPE_HE_AAC2		= 2,
+	AUDIO_CODING_XTYPE_MPEG_SURROUND	= 3,
+	AUDIO_CODING_XTYPE_FIRST_RESERVED	= 4,
+};
+
+/*
+ * CEA Short Audio Descriptor data
+ */
+struct snd_cea_sad {
+	int	channels;
+	int	format;		/* (format == 0) indicates invalid SAD */
+	int	rates;
+	int	sample_bits;	/* for LPCM */
+	int	max_bitrate;	/* for AC3...ATRAC */
+	int	profile;	/* for WMAPRO */
+};
+
+#define ELD_FIXED_BYTES	20
+#define ELD_MAX_SIZE    256
+#define ELD_MAX_MNL	16
+#define ELD_MAX_SAD	16
+
+#define ELD_PCM_BITS_8		BIT(0)
+#define ELD_PCM_BITS_16		BIT(1)
+#define ELD_PCM_BITS_20		BIT(2)
+#define ELD_PCM_BITS_24		BIT(3)
+#define ELD_PCM_BITS_32		BIT(4)
+
+/*
+ * ELD: EDID Like Data
+ */
+struct snd_parsed_hdmi_eld {
+	/*
+	 * all fields will be cleared before updating ELD
+	 */
+	int	baseline_len;
+	int	eld_ver;
+	int	cea_edid_ver;
+	char	monitor_name[ELD_MAX_MNL + 1];
+	int	manufacture_id;
+	int	product_id;
+	u64	port_id;
+	int	support_hdcp;
+	int	support_ai;
+	int	conn_type;
+	int	aud_synch_delay;
+	int	spk_alloc;
+	int	sad_count;
+	struct snd_cea_sad sad[ELD_MAX_SAD];
+};
+
 int snd_pcm_hw_constraint_eld(struct snd_pcm_runtime *runtime, void *eld);
 
+int snd_parse_eld(struct device *dev, struct snd_parsed_hdmi_eld *e,
+		  const unsigned char *buf, int size);
+void snd_show_eld(struct device *dev, struct snd_parsed_hdmi_eld *e);
+
+#ifdef CONFIG_SND_PROC_FS
+void snd_print_eld_info(struct snd_parsed_hdmi_eld *eld,
+			struct snd_info_buffer *buffer);
+#endif
+
 #endif
sound/core/pcm_drm_eld.c +387 -0

398 lines not on this page · raw message

sound/pci/hda/Kconfig +1 -0
index e393578cbe6840ccf8fab48707b4e2c4b802ea6c..9f68cb73b54fc523a527fdc50ddb046671197ac8 100644
@@ -266,6 +266,7 @@ comment "Set to Y if you want auto-loading the codec driver"
 config SND_HDA_CODEC_HDMI
 	tristate "Build HDMI/DisplayPort HD-audio codec support"
 	select SND_DYNAMIC_MINORS
+	select SND_PCM_ELD
 	help
 	  Say Y or M here to include HDMI and DisplayPort HD-audio codec
 	  support in snd-hda-intel driver.  This includes all AMD/ATI,
sound/pci/hda/hda_eld.c +8 -377

452 lines not on this page · raw message

sound/pci/hda/hda_local.h +4 -45

71 lines not on this page · raw message

sound/pci/hda/patch_hdmi.c +3 -3
index 643e0496b09362ea2efb861ad45b8ca4b8f851c5..7167989a8d86a87daf2549c0d2b1d387abdcad51 100644
@@ -1511,8 +1511,8 @@ static void update_eld(struct hda_codec *codec,
 
 	if (eld->eld_valid) {
 		if (eld->eld_size <= 0 ||
-		    snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
-				       eld->eld_size) < 0) {
+		    snd_parse_eld(hda_codec_dev(codec), &eld->info,
+				  eld->eld_buffer, eld->eld_size) < 0) {
 			eld->eld_valid = false;
 			if (repoll) {
 				schedule_delayed_work(&per_pin->work,
@@ -1555,7 +1555,7 @@ static void update_eld(struct hda_codec *codec,
 		pcm_jack = pin_idx_to_pcm_jack(codec, per_pin);
 
 	if (eld->eld_valid)
-		snd_hdmi_show_eld(codec, &eld->info);
+		snd_show_eld(hda_codec_dev(codec), &eld->info);
 
 	eld_changed = (pin_eld->eld_valid != eld->eld_valid);
 	eld_changed |= (pin_eld->monitor_present != eld->monitor_present);
Signature · 1 line
2.39.5
#2 lore raw

PATCH 2/2 ASoC: hdmi-codec: dump ELD through procfs

In reply to Dmitry Baryshkov

Use freshly added API and add eld#n files to procfs for the ASoC cards utilizing HDMI codec. This simplifies debugging of the possible ASoC / HDMI / DisplayPort audio issues.

---
 sound/soc/codecs/hdmi-codec.c | 68 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
sound/soc/codecs/hdmi-codec.c +68 -0
index 69f98975e14ae367f482862724a358eb138ebf6a..497376bcd3ffc60335ec6a30f7f2e609ce766852 100644
@@ -281,6 +281,7 @@ static const struct hdmi_codec_cea_spk_alloc hdmi_codec_channel_alloc[] = {
 struct hdmi_codec_priv {
 	struct hdmi_codec_pdata hcd;
 	uint8_t eld[MAX_ELD_BYTES];
+	struct snd_parsed_hdmi_eld eld_parsed;
 	struct snd_pcm_chmap *chmap_info;
 	unsigned int chmap_idx;
 	struct mutex lock;
@@ -288,6 +289,7 @@ struct hdmi_codec_priv {
 	struct snd_soc_jack *jack;
 	unsigned int jack_status;
 	u8 iec_status[AES_IEC958_STATUS_SIZE];
+	struct snd_info_entry *proc_entry;
 };
 
 static const struct snd_soc_dapm_widget hdmi_widgets[] = {
@@ -469,6 +471,9 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream,
 		if (ret)
 			goto err;
 
+		snd_parse_eld(dai->dev, &hcp->eld_parsed,
+			      hcp->eld, sizeof(hcp->eld));
+
 		ret = snd_pcm_hw_constraint_eld(substream->runtime, hcp->eld);
 		if (ret)
 			goto err;
@@ -825,8 +830,54 @@ static int hdmi_codec_pcm_new(struct snd_soc_pcm_runtime *rtd,
 	return 0;
 }
 
+#ifdef CONFIG_SND_PROC_FS
+static void print_eld_info(struct snd_info_entry *entry,
+			   struct snd_info_buffer *buffer)
+{
+	struct hdmi_codec_priv *hcp = entry->private_data;
+
+	snd_print_eld_info(&hcp->eld_parsed, buffer);
+}
+
+static int hdmi_dai_proc_new(struct hdmi_codec_priv *hcp,
+			     struct snd_soc_dai *dai)
+{
+	struct snd_info_entry *entry;
+	char name[32];
+	int err;
+
+	snprintf(name, sizeof(name), "eld#%d", dai->id);
+	err = snd_card_proc_new(dai->component->card->snd_card, name, &entry);
+	if (err < 0)
+		return err;
+
+	snd_info_set_text_ops(entry, hcp, print_eld_info);
+	hcp->proc_entry = entry;
+
+	return 0;
+}
+
+static void hdmi_dai_proc_free(struct hdmi_codec_priv *hcp)
+{
+	snd_info_free_entry(hcp->proc_entry);
+	hcp->proc_entry = NULL;
+}
+#else
+static int hdmi_dai_proc_new(struct hdmi_codec_priv *hcp,
+			     struct snd_soc_dai *dai)
+{
+	return 0;
+}
+
+static void hdmi_dai_proc_free(struct hdmi_codec_priv *hcp)
+{
+}
+#endif
+
 static int hdmi_dai_probe(struct snd_soc_dai *dai)
 {
+	struct hdmi_codec_priv *hcp =
+		snd_soc_component_get_drvdata(dai->component);
 	struct snd_soc_dapm_context *dapm;
 	struct hdmi_codec_daifmt *daifmt;
 	struct snd_soc_dapm_route route[] = {
@@ -859,6 +910,15 @@ static int hdmi_dai_probe(struct snd_soc_dai *dai)
 
 	snd_soc_dai_dma_data_set_playback(dai, daifmt);
 
+	return hdmi_dai_proc_new(hcp, dai);
+}
+
+static int hdmi_dai_remove(struct snd_soc_dai *dai)
+{
+	struct hdmi_codec_priv *hcp =
+		snd_soc_component_get_drvdata(dai->component);
+
+	hdmi_dai_proc_free(hcp);
 	return 0;
 }
 
@@ -875,11 +935,18 @@ static void hdmi_codec_jack_report(struct hdmi_codec_priv *hcp,
 static void plugged_cb(struct device *dev, bool plugged)
 {
 	struct hdmi_codec_priv *hcp = dev_get_drvdata(dev);
+	int ret;
 
 	if (plugged) {
 		if (hcp->hcd.ops->get_eld) {
 			hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data,
 					    hcp->eld, sizeof(hcp->eld));
+			ret = snd_parse_eld(dev, &hcp->eld_parsed,
+					    hcp->eld, sizeof(hcp->eld));
+			if (ret < 0)
+				dev_dbg(dev, "Failed to parse ELD: %d\n", ret);
+			else
+				snd_show_eld(dev, &hcp->eld_parsed);
 		}
 		hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT);
 	} else {
@@ -926,6 +993,7 @@ static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai)
 
 static const struct snd_soc_dai_ops hdmi_codec_i2s_dai_ops = {
 	.probe				= hdmi_dai_probe,
+	.remove				= hdmi_dai_remove,
 	.startup			= hdmi_codec_startup,
 	.shutdown			= hdmi_codec_shutdown,
 	.hw_params			= hdmi_codec_hw_params,
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] ASoC: hdmi-codec: dump ELD through procfs

Quoted 3 lines · Dmitry Baryshkov

Use freshly added API and add eld#n files to procfs for the ASoC cards utilizing HDMI codec. This simplifies debugging of the possible ASoC / HDMI / DisplayPort audio issues.

#4 lore raw

Re: [PATCH 2/2] ASoC: hdmi-codec: dump ELD through procfs

In reply to Dmitry Baryshkov

Hi Dmitry,

Quoted 5 lines · Dmitry Baryshkov

Use freshly added API and add eld#n files to procfs for the ASoC cards utilizing HDMI codec. This simplifies debugging of the possible ASoC / HDMI / DisplayPort audio issues.

Thanks for your patch, which is now commit 0ecd24a6d8b251eb ("ASoC:
hdmi-codec: dump ELD through procfs") in v6.15-rc1.

This causes the following failure on Salvator-XS:

    ------------[ cut here ]------------
    proc_dir_entry 'card0/eld#0' already registered
    WARNING: CPU: 3 PID: 93 at fs/proc/generic.c:377 proc_register+0x12c/0x1b8
    CPU: 3 UID: 0 PID: 93 Comm: kworker/u33:5 Not tainted
6.14.0-rc1-arm64-renesas-00004-g0ecd24a6d8b2 #2923
    Hardware name: Renesas Salvator-X 2nd version board based on r8a77951 (DT)
    Workqueue: events_unbound deferred_probe_work_func
    pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
    pc : proc_register+0x12c/0x1b8
    lr : proc_register+0x12c/0x1b8
    sp : ffff800081ac38d0
    x29: ffff800081ac38d0 x28: ffff0004c2f7b398 x27: ffff8000813fca80
    x26: ffff0004c2f3b8c0 x25: ffff8000814b3660 x24: ffff0004c2f3b840
    x23: 0000000000000005 x22: ffff0004c2ce7b2c x21: 0000000000000005
    x20: ffff0004c2ce7a80 x19: ffff0004c2ce7a48 x18: 0000000000000006
    x17: 0000000000000000 x16: 0000000000000068 x15: 0769076707650772
    x14: 0720077907640761 x13: ffff800081380a30 x12: 00000000000005ca
    x11: 00000000000001ee x10: ffff8000813d8a30 x9 : ffff800081380a30
    x8 : 00000000ffffefff x7 : ffff8000813d8a30 x6 : 80000000fffff000
    x5 : 00000000000001ef x4 : 0000000000000000 x3 : 0000000000000000
    x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0004c0870000
    Call trace:
     proc_register+0x12c/0x1b8 (P)
     proc_create_data+0x3c/0x60
     snd_info_register+0xcc/0x12c
     snd_info_register+0x30/0x12c
     snd_info_card_register+0x1c/0x94
     snd_card_register+0x1a4/0x1e4
     snd_soc_bind_card+0x7dc/0xab4
     snd_soc_register_card+0xec/0x100
     devm_snd_soc_register_card+0x48/0x98
     audio_graph_parse_of+0x1c4/0x1f8
     graph_probe+0x6c/0x80
     platform_probe+0x64/0xbc
     really_probe+0xb8/0x294
     __driver_probe_device+0x74/0x124
     driver_probe_device+0xd4/0x158
     __device_attach_driver+0xd4/0x154
     bus_for_each_drv+0x84/0xe0
     __device_attach+0x9c/0x188
     device_initial_probe+0x10/0x18
     bus_probe_device+0xa0/0xa4
     deferred_probe_work_func+0x80/0xb4
     process_one_work+0x144/0x280
     worker_thread+0x2c4/0x3cc
     kthread+0x128/0x1e0
     ret_from_fork+0x10/0x20
    ---[ end trace 0000000000000000 ]---
    asoc-audio-graph-card sound: ASoC: failed to register soundcard -12
    asoc-audio-graph-card sound: probe with driver

asoc-audio-graph-card failed with error -12

And:

ALSA device list:
- #0: rcar-sound
+ No soundcards found.

So the card it tried to register is the first one?

Reverting the commit fixes the issue.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw

Re: [PATCH 2/2] ASoC: hdmi-codec: dump ELD through procfs

Hi Geert

Thank you for your report

Quoted 8 lines
Quoted 5 lines

Use freshly added API and add eld#n files to procfs for the ASoC cards utilizing HDMI codec. This simplifies debugging of the possible ASoC / HDMI / DisplayPort audio issues.

Thanks for your patch, which is now commit 0ecd24a6d8b251eb ("ASoC:
hdmi-codec: dump ELD through procfs") in v6.15-rc1.

Our team have noticed this issue and posted the patch. But it seems it is not yet applied.

I will post it again.

Thank you for your help !!

Best regards
---
Kuninori Morimoto

#6 lore raw
In reply to Dmitry Baryshkov
Quoted 5 lines · Dmitry Baryshkov

Follow the HDA lead and add ELD-related information to procfs for the ASoC / HDMI-codec cards.

Looks fine, but it's too late for 6.14.

If Mark doesn't mind, I'm going to take this series after 6.14 merge window is closed.

thanks,

Takashi

Quoted 21 lines

---
Dmitry Baryshkov (2):
ALSA: hda/hdmi: extract common interface for ELD handling
ASoC: hdmi-codec: dump ELD through procfs

 include/sound/pcm_drm_eld.h   |  91 ++++++++++
 sound/core/pcm_drm_eld.c      | 387 ++++++++++++++++++++++++++++++++++++++++++
 sound/pci/hda/Kconfig         |   1 +
 sound/pci/hda/hda_eld.c       | 385 +----------------------------------------
 sound/pci/hda/hda_local.h     |  49 +-----
 sound/pci/hda/patch_hdmi.c    |   6 +-
 sound/soc/codecs/hdmi-codec.c |  68 ++++++++
 7 files changed, 562 insertions(+), 425 deletions(-)

---
base-commit: d5e972e5216ebd4cb9a0bb0b0bd310b86f270d36
change-id: 20250124-alsa-hdmi-codec-eld-09fcc1cc005a

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>
#7 lore raw
Quoted 7 lines · Takashi Iwai
Quoted 4 lines · Dmitry Baryshkov

Follow the HDA lead and add ELD-related information to procfs for the ASoC / HDMI-codec cards.

Quoted 6 lines
Quoted 1 line

Looks fine, but it's too late for 6.14.

If Mark doesn't mind, I'm going to take this series after 6.14 merge window is closed.

Both patches applied to for-next branch now.

thanks,

Takashi