Skip to contentSkip to conversation

ASoC: topology: Fix logical inversion in set_link_hw_format()

PATCH In review Xiuli Pan 5 participants 25 messages Feb 23, 2018 – Apr 16, 2018

Subsystems (3)
lore
Share & tools
lore

Xiuli Pan

author
#0 lore raw

PATCH 1/1 ASoC: topology: Fix logical inversion in set_link_hw_format()

From: Pan Xiuli <[email protected]>

The master/slave conventions are wrt. the codec. The topology code contains a logical inversion, fix to follow ASoC usage.

---
 sound/soc/soc-topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/soc-topology.c +3 -3
index 561f74d..2931248 100644
@@ -2030,11 +2030,11 @@ static void set_link_hw_format(struct snd_soc_dai_link *link,
 		/* clock masters */
 		bclk_master = hw_config->bclk_master;
 		fsync_master = hw_config->fsync_master;
-		if (!bclk_master && !fsync_master)
+		if (bclk_master && fsync_master)
 			link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
-		else if (bclk_master && !fsync_master)
-			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
 		else if (!bclk_master && fsync_master)
+			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
+		else if (bclk_master && !fsync_master)
 			link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
 		else
 			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

The patch

ASoC: topology: Fix logical inversion in set_link_hw_format()

has been applied to the asoc tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 7f34c3f38e9666216fda155b6ebededd1073f5aa Mon Sep 17 00:00:00 2001

From: Pan Xiuli <[email protected]>
Date: Fri, 23 Feb 2018 06:01:28 +0800
Subject: [PATCH] ASoC: topology: Fix logical inversion in set_link_hw_format()

The master/slave conventions are wrt. the codec. The topology code contains a logical inversion, fix to follow ASoC usage.

---
 sound/soc/soc-topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/soc-topology.c +3 -3
index 01a50413c66f..5f507993c43e 100644
@@ -1996,11 +1996,11 @@ static void set_link_hw_format(struct snd_soc_dai_link *link,
 		/* clock masters */
 		bclk_master = hw_config->bclk_master;
 		fsync_master = hw_config->fsync_master;
-		if (!bclk_master && !fsync_master)
+		if (bclk_master && fsync_master)
 			link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
-		else if (bclk_master && !fsync_master)
-			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
 		else if (!bclk_master && fsync_master)
+			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
+		else if (bclk_master && !fsync_master)
 			link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
 		else
 			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
Signature · 1 line
2.16.1
#2 lore raw

Re: Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

Hello Mark Brown, Pan Xiuli,

As far as I understand, the suggested commit *breaks* the functionality instead of fixing it, and should not be applied. Please correct me if I am wrong.

1. The existing functionality works correctly, nothing to fix here.

Below is a comment from include/sound/soc-dai.h:77

~~~~
/*
* DAI hardware clock masters.
*
* This is wrt the codec, the inverse is true for the interface
* i.e. if the codec is clk and FRM master then the interface is
* clk and frame slave.
*/
#define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & FRM master */
#define SND_SOC_DAIFMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */
#define SND_SOC_DAIFMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */
#define SND_SOC_DAIFMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */
~~~~

According to the comment, the existing functionality works correctly "WRT the interface". The suggested commit doesn't fix the behaviour: instead, it reverts the logic to "WRT the codec". But the existing implementation is also valid.

2. The suggested commit breaks the existing ASoC.

The existing functionality already works with several existing ASoC by Intel. The suggested commit will break it for the following reason:

The ALSA topology mechanism loads the binary topology file into ASoC. The suggested commit modifies the parser, but the binaries are already created for the existing functionality. As a result, all existing binaries will be parsed incorrectly.

3. The suggested commit should not go into stable.

For the reasons explained earlier, applying the suggested commit into stable kernel will break the stable kernel.

As I am not in the mailing list, I will not be able to stop Greg K-H <[email protected]> when he will ask "If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it."

@Mark Brown could you please add me to the thread if such situation happens, so that I could share my point for the stable patches.

Best Regards,
Kirill

maintainer
#3 lore raw

Re: Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

Quoted 9 lines · Kirill Marinushkin

2. The suggested commit breaks the existing ASoC.

The existing functionality already works with several existing ASoC by Intel. The suggested commit will break it for the following reason:

The ALSA topology mechanism loads the binary topology file into ASoC. The suggested commit modifies the parser, but the binaries are already created for the existing functionality. As a result, all existing binaries will be parsed incorrectly.

Are there actual binaries using the existing code or is that just theoretical? My impression was that this was fixing things for existing binaries which were shipped for non-mainline kernels, is that not the case?

#4 lore raw

Re: Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

Quoted 9 lines · Mark Brown
Quoted 7 lines · Kirill Marinushkin

2. The suggested commit breaks the existing ASoC.
The existing functionality already works with several existing ASoC by Intel. The suggested commit will break it for the following reason:
The ALSA topology mechanism loads the binary topology file into ASoC. The suggested commit modifies the parser, but the binaries are already created for the existing functionality. As a result, all existing binaries will be parsed incorrectly.

Quoted 4 lines

Are there actual binaries using the existing code or is that just theoretical? My impression was that this was fixing things for existing binaries which were shipped for non-mainline kernels, is that not the case?

There is an actual conf, which can be converted into an actual binary:
alsa-lib/src/conf/topology/broadwell/broadwell.conf

Theoretically, there can be an unknown number of the binaries, not available publicly.

Broadwell exists for a long time, and there is no way to be sure that all the theoretically existing binaries are modified together with this kernel patch.

#5 lore raw

Re: [alsa-devel] Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

In reply to Kirill Marinushkin
Quoted 24 lines · Kirill Marinushkin

Hello Mark Brown, Pan Xiuli,

As far as I understand, the suggested commit *breaks* the functionality instead of fixing it, and should not be applied. Please correct me if I am wrong.

1. The existing functionality works correctly, nothing to fix here.

Below is a comment from include/sound/soc-dai.h:77

~~~~
/*
* DAI hardware clock masters.
*
* This is wrt the codec, the inverse is true for the interface
* i.e. if the codec is clk and FRM master then the interface is
* clk and frame slave.
*/
#define SND_SOC_DAIFMT_CBM_CFM (1 << 12) /* codec clk & FRM master */
#define SND_SOC_DAIFMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */
#define SND_SOC_DAIFMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */
#define SND_SOC_DAIFMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */
~~~~

Quoted 3 lines

According to the comment, the existing functionality works correctly "WRT the interface". The suggested commit doesn't fix the behaviour: instead, it reverts the logic to "WRT the codec". But the existing implementation is also valid.

Look at all the machine drivers, they always use the mask by looking at the codec side. The comment on top means that the SOC side ('the interface') is the dual of the codec side.

This issue was found during the development of SOF (Sound Open Firmware) where we get the reverse of the intended behavior when using the same conventions in topology files as in machine drivers.

Quoted 11 lines

2. The suggested commit breaks the existing ASoC.

The existing functionality already works with several existing ASoC by Intel. The suggested commit will break it for the following reason:

The ALSA topology mechanism loads the binary topology file into ASoC. The suggested commit modifies the parser, but the binaries are already created for the existing functionality. As a result, all existing binaries will be parsed incorrectly.

I know there is a similar inversion in the alsa-lib topology files for Broadwell, the codec is marked as master when it really is slave. I don't know how Intel handled this on SKL.

But you have a point that if people used this inversion in the past it'd break functionality on existing devices which retrieve topology information from ACPI tables and binary files.

Gah. Maybe we should keep this inversion then, document it and compensate for it in topology creating tools. Liam, what do you think?

Quoted 22 lines

3. The suggested commit should not go into stable.

For the reasons explained earlier, applying the suggested commit into stable kernel will break the stable kernel.

As I am not in the mailing list, I will not be able to stop Greg K-H <[email protected]> when he will ask "If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it."

@Mark Brown could you please add me to the thread if such situation happens, so that I could share my point for the stable patches.

Best Regards,
Kirill
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#6 lore raw

Re: [alsa-devel] Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

Quoted 25 lines · Pierre-Louis Bossart
Quoted 24 lines · Kirill Marinushkin

Hello Mark Brown, Pan Xiuli,

As far as I understand, the suggested commit *breaks* the functionality instead of fixing it, and should not be applied. Please correct me if I am wrong.

1. The existing functionality works correctly, nothing to fix here.

Below is a comment from include/sound/soc-dai.h:77

~~~~
/*
  * DAI hardware clock masters.
  *
  * This is wrt the codec, the inverse is true for the interface
  * i.e. if the codec is clk and FRM master then the interface is
  * clk and frame slave.
  */
#define SND_SOC_DAIFMT_CBM_CFM        (1 << 12) /* codec clk & FRM master */ #define SND_SOC_DAIFMT_CBS_CFM        (2 << 12) /* codec clk slave & FRM master */ #define SND_SOC_DAIFMT_CBM_CFS        (3 << 12) /* codec clk master & frame slave */ #define SND_SOC_DAIFMT_CBS_CFS        (4 << 12) /* codec clk & FRM slave */
~~~~

Quoted 6 lines
Quoted 3 lines

According to the comment, the existing functionality works correctly "WRT the interface". The suggested commit doesn't fix the behaviour: instead, it reverts the logic to "WRT the codec". But the existing implementation is also valid.

Look at all the machine drivers, they always use the mask by looking at the codec side. The comment on top means that the SOC side ('the interface') is the dual of the codec side.

Yes, you are right. Analyzing from the codec side makes more sense.

Quoted 9 lines

This issue was found during the development of SOF (Sound Open Firmware) where we get the reverse of the intended behavior when using the same conventions in topology files as in machine drivers.

Quoted 7 lines

2. The suggested commit breaks the existing ASoC.

The existing functionality already works with several existing ASoC by Intel. The suggested commit will break it for the following reason:

Quoted 9 lines
Quoted 4 lines

The ALSA topology mechanism loads the binary topology file into ASoC. The suggested commit modifies the parser, but the binaries are already created for the existing functionality. As a result, all existing binaries will be parsed incorrectly.

I know there is a similar inversion in the alsa-lib topology files for Broadwell, the codec is marked as master when it really is slave. I don't know how Intel handled this on SKL.

But you have a point that if people used this inversion in the past it'd break functionality on existing devices which retrieve topology information from ACPI tables and binary files.

Yes. The Broadwell conf files, which you mentioned, demonstrate that this functionality is already used as it is.

Quoted 25 lines

Gah. Maybe we should keep this inversion then, document it and compensate for it in topology creating tools. Liam, what do you think?

Quoted 22 lines

3. The suggested commit should not go into stable.

For the reasons explained earlier, applying the suggested commit into stable kernel will break the stable kernel.

As I am not in the mailing list, I will not be able to stop Greg K-H <[email protected]> when he will ask "If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it."

@Mark Brown could you please add me to the thread if such situation happens, so that I could share my point for the stable patches.

Best Regards,
Kirill
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

maintainer
#7 lore raw

Re: [alsa-devel] Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

In reply to Pierre-Louis Bossart
Quoted 6 lines · Pierre-Louis Bossart
Quoted 3 lines · Kirill Marinushkin

According to the comment, the existing functionality works correctly "WRT the interface". The suggested commit doesn't fix the behaviour: instead, it reverts the logic to "WRT the codec". But the existing implementation is also valid.

Quoted 7 lines

Look at all the machine drivers, they always use the mask by looking at the codec side. The comment on top means that the SOC side ('the interface') is the dual of the codec side.

This issue was found during the development of SOF (Sound Open Firmware) where we get the reverse of the intended behavior when using the same conventions in topology files as in machine drivers.

Is this perhaps something that the earlier firmware is handling inside the firmware?

#8 lore raw

Re: [alsa-devel] Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

Quoted 11 lines · Mark Brown
Quoted 9 lines · Pierre-Louis Bossart
Quoted 3 lines · Kirill Marinushkin

According to the comment, the existing functionality works correctly "WRT the interface". The suggested commit doesn't fix the behaviour: instead, it reverts the logic to "WRT the codec". But the existing implementation is also valid.

Look at all the machine drivers, they always use the mask by looking at the codec side. The comment on top means that the SOC side ('the interface') is the dual of the codec side.

Quoted 6 lines
Quoted 3 lines

This issue was found during the development of SOF (Sound Open Firmware) where we get the reverse of the intended behavior when using the same conventions in topology files as in machine drivers.

Is this perhaps something that the earlier firmware is handling inside the firmware?

For SKL+ the SSP settings come from binary blobs read from ACPI/NHLT tables so I am wondering if this inversion is compensated for in the tools used to generate the blobs.

maintainer
#9 lore raw

Re: [alsa-devel] Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

Quoted 7 lines · Pierre-Louis Bossart
Quoted 5 lines · Mark Brown
Quoted 3 lines · Pierre-Louis Bossart

This issue was found during the development of SOF (Sound Open Firmware) where we get the reverse of the intended behavior when using the same conventions in topology files as in machine drivers.

Quoted 6 lines
Quoted 2 lines

Is this perhaps something that the earlier firmware is handling inside the firmware?

For SKL+ the SSP settings come from binary blobs read from ACPI/NHLT tables so I am wondering if this inversion is compensated for in the tools used to generate the blobs.

Ugh, I'm confused here. Is this a case of SoF differing from the regular firmware somehow - presumably the stuff coming from the NHLT table is the same for both firmwares?

#10 lore raw

[PATCH 0/1] Re: Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

Hello Mark, Pierre-Louis, Pan, Liam,

As there are too much open questions regarding the bclk and fsync inversion in set_link_hw_format(), I would like to suggest the alternative solution.

This solution will fit both use-cases:

* existing use-cases (Broadwell, etc.)
* new use-cases (Sound Open Firmware, etc.)

The solution includes 1 patch for linux + 1 patch for alsa-lib. I will send them to this mailing thread.

Kirill Marinushkin (1):
ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

 include/uapi/sound/asoc.h | 16 ++++++++++++++--
 sound/soc/soc-topology.c  | 12 +++++++-----
 2 files changed, 21 insertions(+), 7 deletions(-)
Signature · 1 line
2.13.6
#11 lore raw

PATCH 1/1 ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config:

alsa-lib/src/conf/topology/broadwell/broadwell.conf

This commit provides the backwards-compatible solution to fix this misuse. This commit goes in pair with the corresponding patch for alsa-lib.

---
 include/uapi/sound/asoc.h | 16 ++++++++++++++--
 sound/soc/soc-topology.c  | 12 +++++++-----
 2 files changed, 21 insertions(+), 7 deletions(-)
include/uapi/sound/asoc.h +14 -2
index 69c37ecbff7e..f0e5e21efa54 100644
@@ -160,6 +160,18 @@
 #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS    (1 << 2)
 #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP            (1 << 3)
 
+/* DAI topology BCLK parameter
+ * For the backwards capability, by default codec is bclk master
+ */
+#define SND_SOC_TPLG_BCLK_CM         0 /* codec is bclk master */
+#define SND_SOC_TPLG_BCLK_CS         1 /* codec is bclk slave */
+
+/* DAI topology FSYNC parameter
+ * For the backwards capability, by default codec is fsync master
+ */
+#define SND_SOC_TPLG_FSYNC_CM         0 /* codec is fsync master */
+#define SND_SOC_TPLG_FSYNC_CS         1 /* codec is fsync slave */
+
 /*
  * Block Header.
  * This header precedes all object and object arrays below.
@@ -315,8 +327,8 @@ struct snd_soc_tplg_hw_config {
 	__u8 clock_gated;	/* 1 if clock can be gated to save power */
 	__u8 invert_bclk;	/* 1 for inverted BCLK, 0 for normal */
 	__u8 invert_fsync;	/* 1 for inverted frame clock, 0 for normal */
-	__u8 bclk_master;	/* 1 for master of BCLK, 0 for slave */
-	__u8 fsync_master;	/* 1 for master of FSYNC, 0 for slave */
+	__u8 bclk_master;	/* SND_SOC_TPLG_BCLK_ value */
+	__u8 fsync_master;	/* SND_SOC_TPLG_FSYNC_ value */
 	__u8 mclk_direction;    /* 0 for input, 1 for output */
 	__le16 reserved;	/* for 32bit alignment */
 	__le32 mclk_rate;	/* MCLK or SYSCLK freqency in Hz */
sound/soc/soc-topology.c +7 -5
index 01a50413c66f..c5bdc673b195 100644
@@ -1994,13 +1994,15 @@ static void set_link_hw_format(struct snd_soc_dai_link *link,
 			link->dai_fmt |= SND_SOC_DAIFMT_IB_IF;
 
 		/* clock masters */
-		bclk_master = hw_config->bclk_master;
-		fsync_master = hw_config->fsync_master;
-		if (!bclk_master && !fsync_master)
+		bclk_master = (hw_config->bclk_master ==
+			       SND_SOC_TPLG_BCLK_CM);
+		fsync_master = (hw_config->fsync_master ==
+				SND_SOC_TPLG_FSYNC_CM);
+		if (bclk_master && fsync_master)
 			link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
-		else if (bclk_master && !fsync_master)
-			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
 		else if (!bclk_master && fsync_master)
+			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
+		else if (bclk_master && !fsync_master)
 			link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
 		else
 			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
Signature · 1 line
2.13.6
#12 lore raw

PATCH 1/1 ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config:

alsa-lib/src/conf/topology/broadwell/broadwell.conf

This commit provides the backwards-compatible solution to fix this misuse. This commit goes in pair with the corresponding patch for linux.

Cc Mark Brown <[email protected]>
Cc Pierre-Louis Bossart <[email protected]>
Cc Pan Xiuli <[email protected]>
Cc Liam Girdwood <[email protected]>
---
 include/sound/asoc.h                       | 16 ++++++++++++++--
 src/conf/topology/broadwell/broadwell.conf |  4 ++--
 src/topology/pcm.c                         | 20 ++++++++++++++++----
 3 files changed, 32 insertions(+), 8 deletions(-)
include/sound/asoc.h +14 -2
index 0f5d9f9a..89b00703 100644
@@ -156,6 +156,18 @@
 #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS    (1 << 2)
 #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP            (1 << 3)
 
+/* DAI topology BCLK parameter
+ * For the backwards capability, by default codec is bclk master
+ */
+#define SND_SOC_TPLG_BCLK_CM         0 /* codec is bclk master */
+#define SND_SOC_TPLG_BCLK_CS         1 /* codec is bclk slave */
+
+/* DAI topology FSYNC parameter
+ * For the backwards capability, by default codec is fsync master
+ */
+#define SND_SOC_TPLG_FSYNC_CM         0 /* codec is fsync master */
+#define SND_SOC_TPLG_FSYNC_CS         1 /* codec is fsync slave */
+
 /*
  * Block Header.
  * This header precedes all object and object arrays below.
@@ -311,8 +323,8 @@ struct snd_soc_tplg_hw_config {
 	__u8 clock_gated;	/* 1 if clock can be gated to save power */
 	__u8 invert_bclk;	/* 1 for inverted BCLK, 0 for normal */
 	__u8 invert_fsync;	/* 1 for inverted frame clock, 0 for normal */
-	__u8 bclk_master;	/* 1 for master of BCLK, 0 for slave */
-	__u8 fsync_master;	/* 1 for master of FSYNC, 0 for slave */
+	__u8 bclk_master;	/* SND_SOC_TPLG_BCLK_ value */
+	__u8 fsync_master;	/* SND_SOC_TPLG_FSYNC_ value */
 	__u8 mclk_direction;    /* 0 for input, 1 for output */
 	__le16 reserved;	/* for 32bit alignment */
 	__le32 mclk_rate;	/* MCLK or SYSCLK freqency in Hz */
src/conf/topology/broadwell/broadwell.conf +2 -2
index b8405d93..09fc4daa 100644
@@ -393,8 +393,8 @@ SectionGraph."dsp" {
 SectionHWConfig."CodecHWConfig" {
 	id "1"
 	format "I2S"		# physical audio format.
-	bclk   "master"		# Platform is master of bit clock
-	fsync  "master"		# platform is master of fsync
+	bclk   "codec_slave"	# platform is master of bit clock (codec is slave)
+	fsync  "codec_slave"	# platform is master of fsync (codec is slave)
 }
 
 SectionLink."Codec" {
src/topology/pcm.c +16 -4
index 58cee31d..d5d5e5b3 100644
@@ -1137,8 +1137,14 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
-			if (!strcmp(val, "master"))
-				hw_cfg->bclk_master = true;
+			/* For backwards capability,
+			 * "master" == "codec is slave"
+			 */
+			if (!strcmp(val, "master") ||
+			    !strcmp(val, "codec_slave"))
+				hw_cfg->bclk_master = SND_SOC_TPLG_BCLK_CS;
+			else if (!strcmp(val, "codec_master"))
+				hw_cfg->bclk_master = SND_SOC_TPLG_BCLK_CM;
 			continue;
 		}
 
@@ -1163,8 +1169,14 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
-			if (!strcmp(val, "master"))
-				hw_cfg->fsync_master = true;
+			/* For backwards capability,
+			 * "master" == "codec is slave"
+			 */
+			if (!strcmp(val, "master") ||
+			    !strcmp(val, "codec_slave"))
+				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CS;
+			else if (!strcmp(val, "codec_master"))
+				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CM;
 			continue;
 		}
 
Signature · 1 line
2.13.6
maintainer
#13 lore raw

Re: [PATCH, alsa-lib] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

Quoted 2 lines · Kirill Marinushkin

The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config:

You should include Jaroslav and Takashi when sending alsa-lib patches.

src/topology/pcm.c int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, · line 1179

Quoted 8 lines
src/topology/pcm.c +8 -0
+			/* For backwards capability,
+			 * "master" == "codec is slave"
+			 */
+			if (!strcmp(val, "master") ||
+			    !strcmp(val, "codec_slave"))
+				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CS;
+			else if (!strcmp(val, "codec_master"))
+				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CM;

Should we warn on use of "master" since it's being deprecated here (and might be confusing for users)?

#14 lore raw

Re: [PATCH, alsa-lib] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

Quoted 6 lines · Mark Brown
Quoted 2 lines · Kirill Marinushkin

The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config:

You should include Jaroslav and Takashi when sending alsa-lib patches.

Yep, please at the next time.
(And, don't stick with an old thread, but refresh a new thread.)

Quoted 12 lines

src/topology/pcm.c int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, · line 1179

Quoted 9 lines
src/topology/pcm.c +8 -0
+			/* For backwards capability,
+			 * "master" == "codec is slave"
+			 */
+			if (!strcmp(val, "master") ||
+			    !strcmp(val, "codec_slave"))
+				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CS;
+			else if (!strcmp(val, "codec_master"))
+				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CM;

Should we warn on use of "master" since it's being deprecated here (and might be confusing for users)?

Maybe. OTOH, it looks fully backward-compatible, so far, so it's not that confusing yet.

thanks,

Takashi

maintainer
#15 lore raw

Re: [PATCH, alsa-lib] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

Quoted 7 lines · Takashi Iwai
Quoted 2 lines · Mark Brown

Should we warn on use of "master" since it's being deprecated here (and might be confusing for users)?

Maybe. OTOH, it looks fully backward-compatible, so far, so it's not that confusing yet.

Not a compatibility issue, yeah - more just that we've clearly already got people confused so pushing people to the more explicit name might avoid further issues down the line.

#16 lore raw

Re: [PATCH, alsa-lib] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

@Pierre-Louis

Quoted 3 lines

That looks acceptable to me, Xiuli can you test with with the matching change in the SOF topology macros (we can keep the 'slave' in M4 files but expand to 'codec_slave' in the .conf to avoid making this exception visible).

I don't see any comments from Pan Xiuli in the whole mailing thread. Do we still wait for his feedback?

@Mark

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Should we warn on use of "master" since it's being deprecated here (and might be confusing for users)?

Maybe. OTOH, it looks fully backward-compatible, so far, so it's not that confusing yet.

Not a compatibility issue, yeah - more just that we've clearly already got people confused so pushing people to the more explicit name might avoid further issues down the line.

Agree with that. I will add a warning and send it as a patch v2.

@Takashi

Quoted 2 lines

Yep, please at the next time. (And, don't stick with an old thread, but refresh a new thread.)

Yes, I will do so. I want to do this clean, so let me clarify before I start:

1. I will start a new thread, with linux [patch v2]
2. I will send the [patch, alsa-lib v2] in-reply to that linux [patch v2]
3. I will add all currently involved people as CC

Does it look correct?

Best Regards,
Kirill

#17 lore raw

Re: [PATCH, alsa-lib] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

Quoted 11 lines · Kirill Marinushkin
Quoted 3 lines

Yep, please at the next time. (And, don't stick with an old thread, but refresh a new thread.)

Yes, I will do so. I want to do this clean, so let me clarify before I start:

1. I will start a new thread, with linux [patch v2]
2. I will send the [patch, alsa-lib v2] in-reply to that linux [patch v2]
3. I will add all currently involved people as CC

Does it look correct?

Yes, should be OK.

Takashi

author
#18 lore raw

Re: [PATCH, alsa-lib] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

In reply to Kirill Marinushkin
Quoted 7 lines · Kirill Marinushkin

@Pierre-Louis

Quoted 3 lines

That looks acceptable to me, Xiuli can you test with with the matching change in the SOF topology macros (we can keep the 'slave' in M4 files but expand to 'codec_slave' in the .conf to avoid making this exception visible).

I don't see any comments from Pan Xiuli in the whole mailing thread. Do we still wait for his feedback?

Sorry about the late reply, I have some wrong setting with my mail client and found all the mails related in the junk folder.
Thanks Pierre to remind me. I will do the test with the SOF topology and sent patch later.
The patches look good to me, we need to keep the old things work. The modify is simple but efficient. I will also send a reminder letter about these alsa-lib changes to our sof developer.

Quoted 17 lines

@Mark

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Should we warn on use of "master" since it's being deprecated here (and might be confusing for users)?

Maybe. OTOH, it looks fully backward-compatible, so far, so it's not that confusing yet.

Not a compatibility issue, yeah - more just that we've clearly already got people confused so pushing people to the more explicit name might avoid further issues down the line.

Agree with that. I will add a warning and send it as a patch v2.

@Takashi

Quoted 2 lines

Yep, please at the next time. (And, don't stick with an old thread, but refresh a new thread.)

Quoted 7 lines

Yes, I will do so. I want to do this clean, so let me clarify before I start:

1. I will start a new thread, with linux [patch v2]
2. I will send the [patch, alsa-lib v2] in-reply to that linux [patch v2]
3. I will add all currently involved people as CC

Does it look correct?

I will look forward to test with new patches.

Thanks
Xiuli

Quoted 2 lines

Best Regards,
Kirill

#19 lore raw

Re: [PATCH, alsa-lib] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

Hello Mark, Takashi, Xiuli, Pierre-Louis,

The patch series v2 is available in the new mailing thread, subject "[PATCH v2] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()".

Best Regards,
Kirill

Quoted 47 lines · Xiuli
Quoted 7 lines · Kirill Marinushkin

@Pierre-Louis

Quoted 3 lines

That looks acceptable to me, Xiuli can you test with with the matching change in the SOF topology macros (we can keep the 'slave' in M4 files but expand to 'codec_slave' in the .conf to avoid making this exception visible).

I don't see any comments from Pan Xiuli in the whole mailing thread. Do we still wait for his feedback?

Sorry about the late reply, I have some wrong setting with my mail client and found all the mails related in the junk folder.
Thanks Pierre to remind me. I will do the test with the SOF topology and sent patch later.
The patches look good to me, we need to keep the old things work. The modify is simple but efficient. I will also send a reminder letter about these alsa-lib changes to our sof developer.

Quoted 17 lines

@Mark

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Should we warn on use of "master" since it's being deprecated here (and might be confusing for users)?

Maybe. OTOH, it looks fully backward-compatible, so far, so it's not that confusing yet.

Not a compatibility issue, yeah - more just that we've clearly already got people confused so pushing people to the more explicit name might avoid further issues down the line.

Agree with that. I will add a warning and send it as a patch v2.

@Takashi

Quoted 2 lines

Yep, please at the next time. (And, don't stick with an old thread, but refresh a new thread.)

Quoted 7 lines

Yes, I will do so. I want to do this clean, so let me clarify before I start:

1. I will start a new thread, with linux [patch v2]
2. I will send the [patch, alsa-lib v2] in-reply to that linux [patch v2]
3. I will add all currently involved people as CC

Does it look correct?

I will look forward to test with new patches.

Thanks
Xiuli

Quoted 2 lines

Best Regards,
Kirill

maintainer
#20 lore raw

Applied "ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()" to the asoc tree

In reply to Kirill Marinushkin

The patch

ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

has been applied to the asoc tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From a941e2fab3207cb0d57dc4ec47b1b12c8ea78b84 Mon Sep 17 00:00:00 2001

From: Kirill Marinushkin <[email protected]>
Date: Wed, 4 Apr 2018 06:19:37 +0200
Subject: [PATCH] ASoC: topology: Fix bclk and fsync inversion in
set_link_hw_format()

The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config:

alsa-lib/src/conf/topology/broadwell/broadwell.conf

This commit provides the backwards-compatible solution to fix this misuse.

---
 include/uapi/sound/asoc.h | 16 ++++++++++++++--
 sound/soc/soc-topology.c  | 12 +++++++-----
 2 files changed, 21 insertions(+), 7 deletions(-)
include/uapi/sound/asoc.h +14 -2
index 69c37ecbff7e..f0e5e21efa54 100644
@@ -160,6 +160,18 @@
 #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS    (1 << 2)
 #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP            (1 << 3)
 
+/* DAI topology BCLK parameter
+ * For the backwards capability, by default codec is bclk master
+ */
+#define SND_SOC_TPLG_BCLK_CM         0 /* codec is bclk master */
+#define SND_SOC_TPLG_BCLK_CS         1 /* codec is bclk slave */
+
+/* DAI topology FSYNC parameter
+ * For the backwards capability, by default codec is fsync master
+ */
+#define SND_SOC_TPLG_FSYNC_CM         0 /* codec is fsync master */
+#define SND_SOC_TPLG_FSYNC_CS         1 /* codec is fsync slave */
+
 /*
  * Block Header.
  * This header precedes all object and object arrays below.
@@ -315,8 +327,8 @@ struct snd_soc_tplg_hw_config {
 	__u8 clock_gated;	/* 1 if clock can be gated to save power */
 	__u8 invert_bclk;	/* 1 for inverted BCLK, 0 for normal */
 	__u8 invert_fsync;	/* 1 for inverted frame clock, 0 for normal */
-	__u8 bclk_master;	/* 1 for master of BCLK, 0 for slave */
-	__u8 fsync_master;	/* 1 for master of FSYNC, 0 for slave */
+	__u8 bclk_master;	/* SND_SOC_TPLG_BCLK_ value */
+	__u8 fsync_master;	/* SND_SOC_TPLG_FSYNC_ value */
 	__u8 mclk_direction;    /* 0 for input, 1 for output */
 	__le16 reserved;	/* for 32bit alignment */
 	__le32 mclk_rate;	/* MCLK or SYSCLK freqency in Hz */
sound/soc/soc-topology.c +7 -5
index 942c6e5eb4b7..1c55252641f3 100644
@@ -2019,13 +2019,15 @@ static void set_link_hw_format(struct snd_soc_dai_link *link,
 			link->dai_fmt |= SND_SOC_DAIFMT_IB_IF;
 
 		/* clock masters */
-		bclk_master = hw_config->bclk_master;
-		fsync_master = hw_config->fsync_master;
-		if (!bclk_master && !fsync_master)
+		bclk_master = (hw_config->bclk_master ==
+			       SND_SOC_TPLG_BCLK_CM);
+		fsync_master = (hw_config->fsync_master ==
+				SND_SOC_TPLG_FSYNC_CM);
+		if (bclk_master && fsync_master)
 			link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
-		else if (bclk_master && !fsync_master)
-			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
 		else if (!bclk_master && fsync_master)
+			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
+		else if (bclk_master && !fsync_master)
 			link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
 		else
 			link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
Signature · 1 line
2.17.0
#21 lore raw

Re: [alsa-devel] [PATCH 0/1] Re: Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

In reply to Kirill Marinushkin
Quoted 5 lines · Kirill Marinushkin

Hello Mark, Pierre-Louis, Pan, Liam,

As there are too much open questions regarding the bclk and fsync inversion in set_link_hw_format(), I would like to suggest the alternative solution.

Quoted 7 lines

This solution will fit both use-cases:

* existing use-cases (Broadwell, etc.)
* new use-cases (Sound Open Firmware, etc.)

The solution includes 1 patch for linux + 1 patch for alsa-lib. I will send them to this mailing thread.

That looks acceptable to me, Xiuli can you test with with the matching change in the SOF topology macros (we can keep the 'slave' in M4 files but expand to 'codec_slave' in the .conf to avoid making this exception visible).

Quoted 16 lines

Kirill Marinushkin (1):
ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()

  include/uapi/sound/asoc.h | 16 ++++++++++++++--
  sound/soc/soc-topology.c  | 12 +++++++-----
  2 files changed, 21 insertions(+), 7 deletions(-)
#22 lore raw

Re: Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

In reply to Mark Brown
Quoted 11 lines · Mark Brown
Quoted 9 lines · Pierre-Louis Bossart
Quoted 8 lines · Mark Brown
Quoted 3 lines · Pierre-Louis Bossart

This issue was found during the development of SOF (Sound Open Firmware) where we get the reverse of the intended behavior when using the same conventions in topology files as in machine drivers.

Is this perhaps something that the earlier firmware is handling inside the firmware?

Quoted 7 lines
Quoted 3 lines

For SKL+ the SSP settings come from binary blobs read from ACPI/NHLT tables so I am wondering if this inversion is compensated for in the tools used to generate the blobs.

Ugh, I'm confused here. Is this a case of SoF differing from the regular firmware somehow - presumably the stuff coming from the NHLT table is the same for both firmwares?

no we are not using the NHLT info for now but using the one provided in topology files. the SOF firmware does not rely on blobs but programs the registers based on masks and settings passed. This difference is precisely how we exposed a difference in behavior.

maintainer
#23 lore raw

Re: Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

In reply to Kirill Marinushkin
Quoted 4 lines · Kirill Marinushkin

Hello Mark Brown, Pan Xiuli,

As far as I understand, the suggested commit *breaks* the functionality instead of fixing it, and should not be applied. Please correct me if I am wrong.

This discussion ground to a halt a bit (nobody from Intel seems to have looked at Kirill's patches?) so I'm going to drop this patch for now, I'll keep a copy around at test/topology.

#24 lore raw

Re: [alsa-devel] Applied "ASoC: topology: Fix logical inversion in set_link_hw_format()" to the asoc tree

Quoted 9 lines · Mark Brown
Quoted 4 lines · Kirill Marinushkin

Hello Mark Brown, Pan Xiuli,

As far as I understand, the suggested commit *breaks* the functionality instead of fixing it, and should not be applied. Please correct me if I am wrong.

This discussion ground to a halt a bit (nobody from Intel seems to have looked at Kirill's patches?) so I'm going to drop this patch for now, I'll keep a copy around at test/topology.

Sorry, we did look at Kirill's patches but wanted to test further, and of course we are caught in the middle of a release. It's fine to drop this for now.