Skip to contentSkip to conversation

ASoC: Intel: hdac_hdmi: Add sampling frequencies constraint

PATCH In review Yong Zhi 3 participants 7 messages Aug 7, 2018

Subsystems (2)
lore
Share & tools
lore

Yong Zhi

author
#0 lore raw

PATCH 1/1 ASoC: Intel: hdac_hdmi: Add sampling frequencies constraint

Playback of 44.1Khz contents with HDMI plugged returns "Invalid pipe config".

This patch adds rate constraint to allow user space SRC to do the converting.

---
 sound/soc/codecs/hdac_hdmi.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
sound/soc/codecs/hdac_hdmi.c +44 -0
index 7b8533abf637..b222a2e91463 100644
@@ -288,6 +288,38 @@ static unsigned int sad_sample_bits_lpcm(const u8 *sad)
 	return (sad[2] & 7);
 }
 
+/**
+ * sad_sample_rates_lpcm - Find supported sampling frequencies
+ *
+ * @sad: pointer to CEA_SADs entry byte 2 which details sampling frequencies
+ *	 supported according to CEA-861 EDID V3. In little endian byte order.
+ *
+ *	 bit 7: Reserved (0)
+ *	 bit 6: 192kHz
+ *	 bit 5: 176kHz
+ *	 bit 4: 96kHz
+ *	 bit 3: 88kHz
+ *	 bit 2: 48kHz
+ *	 bit 1: 44kHz
+ *	 bit 0: 32kHz
+ *
+ * Return: bitmask of supported sampling frequencies.
+ */
+static u8 sad_sample_rates_lpcm(const u8 *sad)
+{
+	return (sad[1] & 0x7F);
+}
+
+static const unsigned int cea_sampling_freqs[7] = {
+	SNDRV_PCM_RATE_32000,	/* 0:  32000Hz */
+	SNDRV_PCM_RATE_44100,	/* 1:  44100Hz */
+	SNDRV_PCM_RATE_48000,	/* 2:  48000Hz */
+	SNDRV_PCM_RATE_88200,	/* 3:  88200Hz */
+	SNDRV_PCM_RATE_96000,	/* 4:  96000Hz */
+	SNDRV_PCM_RATE_176400,	/* 5: 176400Hz */
+	SNDRV_PCM_RATE_192000,	/* 6: 192000Hz */
+};
+
 static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
 						void *eld)
 {
@@ -301,6 +333,8 @@ static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
 
 	for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
 		if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
+			unsigned int rates = 0;
+			u8 sad_rates, j;
 
 			/*
 			 * the controller support 20 and 24 bits in 32 bit
@@ -308,6 +342,16 @@ static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
 			 */
 			if (sad_sample_bits_lpcm(sad) & 0x6)
 				formats |= SNDRV_PCM_FMTBIT_S32;
+
+			sad_rates = sad_sample_rates_lpcm(sad);
+			/* Filter out 44.1, 88.2 and 176.4Khz */
+			for (j = 0; j < 7; j += 2)
+				if (sad_rates & BIT(j))
+					rates |= cea_sampling_freqs[j];
+
+			snd_pcm_hw_constraint_mask64(runtime,
+						     SNDRV_PCM_HW_PARAM_RATE,
+						     rates);
 		}
 	}
 
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Yong Zhi

Playback of 44.1Khz contents with HDMI plugged returns "Invalid pipe config".

This patch adds rate constraint to allow user space SRC to do the converting.

I didn't test this personally but 44.1kHz isn't well supported with the firmware+iDisp/HDMI path. The code looks good to me so

Quoted 73 lines
---
  sound/soc/codecs/hdac_hdmi.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 44 insertions(+)
sound/soc/codecs/hdac_hdmi.c +44 -0
index 7b8533abf637..b222a2e91463 100644
@@ -288,6 +288,38 @@ static unsigned int sad_sample_bits_lpcm(const u8 *sad)
  	return (sad[2] & 7);
  }
 
+/**
+ * sad_sample_rates_lpcm - Find supported sampling frequencies
+ *
+ * @sad: pointer to CEA_SADs entry byte 2 which details sampling frequencies
+ *	 supported according to CEA-861 EDID V3. In little endian byte order.
+ *
+ *	 bit 7: Reserved (0)
+ *	 bit 6: 192kHz
+ *	 bit 5: 176kHz
+ *	 bit 4: 96kHz
+ *	 bit 3: 88kHz
+ *	 bit 2: 48kHz
+ *	 bit 1: 44kHz
+ *	 bit 0: 32kHz
+ *
+ * Return: bitmask of supported sampling frequencies.
+ */
+static u8 sad_sample_rates_lpcm(const u8 *sad)
+{
+	return (sad[1] & 0x7F);
+}
+
+static const unsigned int cea_sampling_freqs[7] = {
+	SNDRV_PCM_RATE_32000,	/* 0:  32000Hz */
+	SNDRV_PCM_RATE_44100,	/* 1:  44100Hz */
+	SNDRV_PCM_RATE_48000,	/* 2:  48000Hz */
+	SNDRV_PCM_RATE_88200,	/* 3:  88200Hz */
+	SNDRV_PCM_RATE_96000,	/* 4:  96000Hz */
+	SNDRV_PCM_RATE_176400,	/* 5: 176400Hz */
+	SNDRV_PCM_RATE_192000,	/* 6: 192000Hz */
+};
+
  static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
  						void *eld)
  {
@@ -301,6 +333,8 @@ static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
 
  	for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
  		if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
+			unsigned int rates = 0;
+			u8 sad_rates, j;
 
  			/*
  			 * the controller support 20 and 24 bits in 32 bit
@@ -308,6 +342,16 @@ static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
  			 */
  			if (sad_sample_bits_lpcm(sad) & 0x6)
  				formats |= SNDRV_PCM_FMTBIT_S32;
+
+			sad_rates = sad_sample_rates_lpcm(sad);
+			/* Filter out 44.1, 88.2 and 176.4Khz */
+			for (j = 0; j < 7; j += 2)
+				if (sad_rates & BIT(j))
+					rates |= cea_sampling_freqs[j];
+
+			snd_pcm_hw_constraint_mask64(runtime,
+						     SNDRV_PCM_HW_PARAM_RATE,
+						     rates);
  		}
  	}
 
#2 lore raw
In reply to Yong Zhi
Quoted 3 lines · Yong Zhi

Playback of 44.1Khz contents with HDMI plugged returns "Invalid pipe config".

Why? Is it a limitation of i915 graphics side?
If it's a generic issue, we'd need to fix also in the legacy HDMI driver, too.

(snip)
....

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+			sad_rates = sad_sample_rates_lpcm(sad);
+			/* Filter out 44.1, 88.2 and 176.4Khz */
+			for (j = 0; j < 7; j += 2)
+				if (sad_rates & BIT(j))
+					rates |= cea_sampling_freqs[j];
+
+			snd_pcm_hw_constraint_mask64(runtime,
+						     SNDRV_PCM_HW_PARAM_RATE,
+						     rates);

The whole changes are too complex. You don't have to reduce the list dynamically, but just need to tell the all possible rates with a static array.

Or, even simpler, just filter the rates bits in hdac_hdmi_create_dais() from the beginning like below.

thanks,

Takashi

sound/soc/codecs/hdac_hdmi.c +6 -0
@@ -1410,6 +1410,12 @@ static int hdac_hdmi_create_dais(struct hdac_device *hdev,
 		if (ret)
 			return ret;
 
+		/* Filter out 44.1, 88.2 and 176.4Khz */
+		rates &= ~(SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |
+			   SNDRV_PCM_RATE_176400);
+		if (!rates)
+			return -EINVAL;
+
 		sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
 		hdmi_dais[i].name = devm_kstrdup(&hdev->dev,
 					dai_name, GFP_KERNEL);
author
#3 lore raw

Hi, Takashi,

Thanks for the review.

Quoted 11 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, August 7, 2018 10:23 AM
To: Zhi, Yong <[email protected]>
Cc: [email protected]; [email protected]; alsa- [email protected]; N, Harshapriya <[email protected]>; [email protected]; M, Naveen <[email protected]>; Kale, Sanyog R <[email protected]>
Subject: Re: [alsa-devel] [PATCH] ASoC: Intel: hdac_hdmi: Add sampling frequencies constraint

Quoted 9 lines
Quoted 3 lines · Yong Zhi

Playback of 44.1Khz contents with HDMI plugged returns "Invalid pipe config".

Why? Is it a limitation of i915 graphics side?
If it's a generic issue, we'd need to fix also in the legacy HDMI driver, too.

The HDMI paths in DFW topology are configured for 48Khz operation.

Quoted 17 lines

(snip)
....

Review

Quoted 9 lines
(quoted diff) +9 -0
+
+			sad_rates = sad_sample_rates_lpcm(sad);
+			/* Filter out 44.1, 88.2 and 176.4Khz */
+			for (j = 0; j < 7; j += 2)
+				if (sad_rates & BIT(j))
+					rates |= cea_sampling_freqs[j];
+
+			snd_pcm_hw_constraint_mask64(runtime,
+

SNDRV_PCM_HW_PARAM_RATE,

Review

Quoted 1 line
(quoted diff) +1 -0
+						     rates);

The whole changes are too complex. You don't have to reduce the list dynamically, but just need to tell the all possible rates with a static array.

Quoted 8 lines

Or, even simpler, just filter the rates bits in hdac_hdmi_create_dais() from the beginning like below.

thanks,

Takashi

Ack, will make changes in hdac_hdmi_create_dais() thanks!!

Quoted 17 lines
sound/soc/codecs/hdac_hdmi.c +2 -0
@@ -1410,6 +1410,12 @@ static int hdac_hdmi_create_dais(struct
 hdac_device *hdev,
 		if (ret)
 			return ret;
 
+		/* Filter out 44.1, 88.2 and 176.4Khz */
+		rates &= ~(SNDRV_PCM_RATE_44100 |

SNDRV_PCM_RATE_88200 |

sound/soc/codecs/hdac_hdmi.c +4 -0
+			   SNDRV_PCM_RATE_176400);
+		if (!rates)
+			return -EINVAL;
+
 		sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
 		hdmi_dais[i].name = devm_kstrdup(&hdev->dev,
 					dai_name, GFP_KERNEL);
#4 lore raw
Quoted 19 lines · Yong

Hi, Takashi,

Thanks for the review.

Quoted 14 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, August 7, 2018 10:23 AM
To: Zhi, Yong <[email protected]>
Cc: [email protected]; [email protected]; alsa- [email protected]; N, Harshapriya <[email protected]>; [email protected]; M, Naveen <[email protected]>; Kale, Sanyog R <[email protected]>
Subject: Re: [alsa-devel] [PATCH] ASoC: Intel: hdac_hdmi: Add sampling frequencies constraint

Quoted 1 line · Yong Zhi
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Playback of 44.1Khz contents with HDMI plugged returns "Invalid pipe config".

Why? Is it a limitation of i915 graphics side?
If it's a generic issue, we'd need to fix also in the legacy HDMI driver, too.

The HDMI paths in DFW topology are configured for 48Khz operation.

OK, so it's specific to this driver, not for the legacy configuration, so far.

What if the legacy HDMI codec driver is used on top of Intel SST (as the recent patchset "Enable HDA Codec support on Intel Platforms")? The legacy HDMI codec driver isn't enabled there, but in theory it can be. I suppose that a similar workaround is required, right?

thanks,

Takashi

author
#5 lore raw

Hi, Takashi,

Quoted 39 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, August 7, 2018 10:41 AM
To: Zhi, Yong <[email protected]>
Cc: [email protected]; [email protected]; alsa- [email protected]; N, Harshapriya <[email protected]>; [email protected]; M, Naveen <[email protected]>; Kale, Sanyog R <[email protected]>
Subject: Re: [alsa-devel] [PATCH] ASoC: Intel: hdac_hdmi: Add sampling frequencies constraint

Quoted 26 lines · Yong

Hi, Takashi,

Thanks for the review.

Quoted 20 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, August 7, 2018 10:23 AM
To: Zhi, Yong <[email protected]>
Cc: [email protected]; [email protected]; alsa- [email protected]; N, Harshapriya <[email protected]>; [email protected]; M, Naveen <[email protected]>; Kale, Sanyog R <[email protected]>
Subject: Re: [alsa-devel] [PATCH] ASoC: Intel: hdac_hdmi: Add sampling frequencies constraint

Quoted 3 lines · Yong Zhi

Playback of 44.1Khz contents with HDMI plugged returns "Invalid pipe config".

Why? Is it a limitation of i915 graphics side?
If it's a generic issue, we'd need to fix also in the legacy HDMI driver, too.

Quoted 10 lines
Quoted 1 line

The HDMI paths in DFW topology are configured for 48Khz operation.

OK, so it's specific to this driver, not for the legacy configuration, so far.

What if the legacy HDMI codec driver is used on top of Intel SST (as the recent patchset "Enable HDA Codec support on Intel Platforms")? The legacy HDMI codec driver isn't enabled there, but in theory it can be. I suppose that a similar workaround is required, right?

Think so if that's the case, but I am far from expert on this topic :)

Quoted 3 lines

thanks,

Takashi

#6 lore raw
Quoted 40 lines · Yong

Hi, Takashi,

Quoted 38 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, August 7, 2018 10:41 AM
To: Zhi, Yong <[email protected]>
Cc: [email protected]; [email protected]; alsa- [email protected]; N, Harshapriya <[email protected]>; [email protected]; M, Naveen <[email protected]>; Kale, Sanyog R <[email protected]>
Subject: Re: [alsa-devel] [PATCH] ASoC: Intel: hdac_hdmi: Add sampling frequencies constraint

Quoted 15 lines · Yong

Hi, Takashi,

Thanks for the review.

Quoted 11 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, August 7, 2018 10:23 AM
To: Zhi, Yong <[email protected]>
Cc: [email protected]; [email protected]; alsa- [email protected]; N, Harshapriya <[email protected]>; [email protected]; M, Naveen <[email protected]>; Kale, Sanyog R <[email protected]>
Subject: Re: [alsa-devel] [PATCH] ASoC: Intel: hdac_hdmi: Add sampling frequencies constraint

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines · Yong Zhi

Playback of 44.1Khz contents with HDMI plugged returns "Invalid pipe config".

Why? Is it a limitation of i915 graphics side?
If it's a generic issue, we'd need to fix also in the legacy HDMI driver, too.

The HDMI paths in DFW topology are configured for 48Khz operation.

OK, so it's specific to this driver, not for the legacy configuration, so far.

Quoted 7 lines
Quoted 6 lines

What if the legacy HDMI codec driver is used on top of Intel SST (as the recent patchset "Enable HDA Codec support on Intel Platforms")? The legacy HDMI codec driver isn't enabled there, but in theory it can be. I suppose that a similar workaround is required, right?

Think so if that's the case, but I am far from expert on this topic :)

There are two issues here.
1. the firmware relies on a timer which isn't aligned with any 44.1 frequency. In general we don't support 44.1kHz in master mode (we've relied on 48kHz frequencies since 2013 and no one cared or bothered to complain). If you look at all machine drivers using hdmi_hdac they are all based on 48kHz already. I suggested to Yong to do this filtering in the codec itself rather than in the front-ends since the DSP *could* do some resampling. I was also planning to remove all these front-end restrictions which prevent folks from using more that 48kHz/stereo/16 bits over HDMI.

2. it's not clear how the link itself would be configured (need the 12-11-11- pattern), it's not clear to me it's supported in decoupled mode (and I don't know how to test it in the first place due to issue #1)

For the case with the HDA codec path, we are also using that same hdac_hdmi codec in the machine driver, along with the new hdac_hda pseudo codec, so the same limitations will be enforced.

As to your question on whether this applies to the legacy driver, I don't think so. I just tried on my Skylake NUC, all HDMI devices seem to support 44.1kHz without errors. The limitation that Yong added is just a pragmatic view that 44.1 support is broken when going through the DSP and there isn't any real plan to fix this for now since this isn't a required feature and doesn't break compliance (HDMI sources may select one of 32,44.1,48kHz, HDMI sinks must support all of these frequencies).

Quoted 4 lines
Quoted 4 lines

thanks,

Takashi