Skip to contentSkip to conversation

alsa-lib: ASoC: topology: Improve hw_configs

PATCH In review Kirill Marinushkin 3 participants 8 messages Apr 16, 2018 – Apr 20, 2018 Sound

lore
Share & tools
lore
#0 lore raw

v4 cover alsa-lib: ASoC: topology: Improve hw_configs

Hello Takashi,

This patch series waits since 20th of February, because it modifies UAPI headers and should be done in sync with Linux and ALSA. I see that previously there was no clear understanding, how to do this in sync.

We discussed with you on 02 Apr 2018, and you suggested the following steps:

Step 1. A person from Intel, who knows the topic (Pierre), adds his "Reviewed-by" or "Acked-by" tags
Step 2. I clarify with Mark to apply the Linux part (different patch series) Step 3. After that, I clarify with you to apply the ALSA part (this patch series)

The step 1 is done. Old patches are reviewed by Pierre, so they have his "Reviewed-by" tag. New patches are suggested by him, and we agreed on the implementation, so they have his "Acked-by" tag.

The step 2 is done. Mark applied the corresponding part to his Linux tree [1].

Now we are on the step 3. If you don't have anything against this patch series, please apply it to ALSA.

Best Regards,
Kirill

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

Kirill Marinushkin (4):
ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()
ASoC: topology: Add missing clock gating parameter when parsing
hw_configs
ASoC: topology: Add definitions for mclk_direction values
ASoC: topology: Add alias conf parameter names for hw_configs

 include/sound/asoc.h                       | 29 +++++++++--
 include/topology.h                         |  8 +--
 src/conf/topology/broadwell/broadwell.conf |  4 +-
 src/topology/pcm.c                         | 81 +++++++++++++++++++++++-------
 4 files changed, 95 insertions(+), 27 deletions(-)
Signature · 1 line
2.13.6
#1 lore raw

PATCH v4 1/4 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.

---
 include/sound/asoc.h                       | 16 ++++++++++++++--
 include/topology.h                         |  4 ++--
 src/conf/topology/broadwell/broadwell.conf |  4 ++--
 src/topology/pcm.c                         | 30 ++++++++++++++++++++++++++----
 4 files changed, 44 insertions(+), 10 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 */
include/topology.h +2 -2
index 8779da4d..5d7b46df 100644
@@ -1000,8 +1000,8 @@ struct snd_tplg_hw_config_template {
 	unsigned char clock_gated;      /* 1 if clock can be gated to save power */
 	unsigned char  invert_bclk;     /* 1 for inverted BCLK, 0 for normal */
 	unsigned char  invert_fsync;    /* 1 for inverted frame clock, 0 for normal */
-	unsigned char  bclk_master;     /* 1 for master of BCLK, 0 for slave */
-	unsigned char  fsync_master;    /* 1 for master of FSYNC, 0 for slave */
+	unsigned char  bclk_master;     /* SND_SOC_TPLG_BCLK_ value */
+	unsigned char  fsync_master;    /* SND_SOC_TPLG_FSYNC_ value */
 	unsigned char  mclk_direction;  /* 0 for input, 1 for output */
 	unsigned short reserved;        /* for 32bit alignment */
 	unsigned int 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 +26 -4
index bb47b9af..d0395182 100644
@@ -1141,8 +1141,19 @@ 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;
+			if (!strcmp(val, "master")) {
+				/* For backwards capability,
+				 * "master" == "codec is slave"
+				 */
+				SNDERR("warning: deprecated bclk value '%s'\n",
+				       val);
+
+				hw_cfg->bclk_master = SND_SOC_TPLG_BCLK_CS;
+			} else if (!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;
 		}
 
@@ -1167,8 +1178,19 @@ 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;
+			if (!strcmp(val, "master")) {
+				/* For backwards capability,
+				 * "master" == "codec is slave"
+				 */
+				SNDERR("warning: deprecated fsync value '%s'\n",
+				       val);
+
+				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CS;
+			} else if (!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
#2 lore raw

PATCH v4 2/4 ASoC: topology: Add missing clock gating parameter when parsing hw_configs

In reply to Kirill Marinushkin

Clock gating parameter is a part of dai_fmt. It is supported by alsa-lib when creating a topology binary file, but ignored by kernel when loading this topology file.

After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored.

snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT

For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported:

~~~~
SectionHWConfig."CodecHWConfig" {
id "1"
format "I2S" # physical audio format.
pm_gate_clocks "true" # clock can be gated
}

SectionLink."Codec" {

        # used for binding to the physical link
        id "0"
        hw_configs [
                "CodecHWConfig"
        ]

        default_hw_conf_id "1"
}

~~~~

---
 include/sound/asoc.h | 7 ++++++-
 include/topology.h   | 2 +-
 src/topology/pcm.c   | 6 +++++-
 3 files changed, 12 insertions(+), 3 deletions(-)
include/sound/asoc.h +6 -1
index 89b00703..297e837c 100644
@@ -135,6 +135,11 @@
 #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS      (1 << 1)
 #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS    (1 << 2)
 
+/* DAI clock gating */
+#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED	0
+#define SND_SOC_TPLG_DAI_CLK_GATE_GATED	1
+#define SND_SOC_TPLG_DAI_CLK_GATE_CONT		2
+
 /* DAI physical PCM data formats.
  * Add new formats to the end of the list.
  */
@@ -320,7 +325,7 @@ struct snd_soc_tplg_hw_config {
 	__le32 size;            /* in bytes of this structure */
 	__le32 id;		/* unique ID - - used to match */
 	__le32 fmt;		/* SND_SOC_DAI_FORMAT_ format value */
-	__u8 clock_gated;	/* 1 if clock can be gated to save power */
+	__u8 clock_gated;	/* SND_SOC_TPLG_DAI_CLK_GATE_ value */
 	__u8 invert_bclk;	/* 1 for inverted BCLK, 0 for normal */
 	__u8 invert_fsync;	/* 1 for inverted frame clock, 0 for normal */
 	__u8 bclk_master;	/* SND_SOC_TPLG_BCLK_ value */
include/topology.h +1 -1
index 5d7b46df..3793115c 100644
@@ -997,7 +997,7 @@ struct snd_tplg_pcm_template {
 struct snd_tplg_hw_config_template {
 	int id;                         /* unique ID - - used to match */
 	unsigned int fmt;               /* SND_SOC_DAI_FORMAT_ format value */
-	unsigned char clock_gated;      /* 1 if clock can be gated to save power */
+	unsigned char clock_gated;      /* SND_SOC_TPLG_DAI_CLK_GATE_ value */
 	unsigned char  invert_bclk;     /* 1 for inverted BCLK, 0 for normal */
 	unsigned char  invert_fsync;    /* 1 for inverted frame clock, 0 for normal */
 	unsigned char  bclk_master;     /* SND_SOC_TPLG_BCLK_ value */
src/topology/pcm.c +5 -1
index d0395182..b53f6b03 100644
@@ -1233,7 +1233,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 				return -EINVAL;
 
 			if (!strcmp(val, "true"))
-				hw_cfg->clock_gated = true;
+				hw_cfg->clock_gated =
+					SND_SOC_TPLG_DAI_CLK_GATE_GATED;
+			else
+				hw_cfg->clock_gated =
+					SND_SOC_TPLG_DAI_CLK_GATE_CONT;
 			continue;
 		}
 
Signature · 1 line
2.13.6
#3 lore raw

PATCH v4 3/4 ASoC: topology: Add definitions for mclk_direction values

In reply to Kirill Marinushkin

Current comment makes not clear the direction of mclk. Previously, similar description caused a misunderstanding for bclk_master and fsync_master.

This commit solves the potential confusion the same way it is solved for bclk_master and fsync_master.

---
 include/sound/asoc.h |  6 +++++-
 include/topology.h   |  2 +-
 src/topology/pcm.c   | 15 +++++++++++++--
 3 files changed, 19 insertions(+), 4 deletions(-)
include/sound/asoc.h +5 -1
index 297e837c..bb8aec78 100644
@@ -140,6 +140,10 @@
 #define SND_SOC_TPLG_DAI_CLK_GATE_GATED	1
 #define SND_SOC_TPLG_DAI_CLK_GATE_CONT		2
 
+/* DAI mclk_direction */
+#define SND_SOC_TPLG_MCLK_CO            0 /* for codec, mclk is output */
+#define SND_SOC_TPLG_MCLK_CI            1 /* for codec, mclk is input */
+
 /* DAI physical PCM data formats.
  * Add new formats to the end of the list.
  */
@@ -330,7 +334,7 @@ struct snd_soc_tplg_hw_config {
 	__u8 invert_fsync;	/* 1 for inverted frame clock, 0 for normal */
 	__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 */
+	__u8 mclk_direction;    /* SND_SOC_TPLG_MCLK_ value */
 	__le16 reserved;	/* for 32bit alignment */
 	__le32 mclk_rate;	/* MCLK or SYSCLK freqency in Hz */
 	__le32 bclk_rate;	/* BCLK freqency in Hz */
include/topology.h +1 -1
index 3793115c..27da7308 100644
@@ -1002,7 +1002,7 @@ struct snd_tplg_hw_config_template {
 	unsigned char  invert_fsync;    /* 1 for inverted frame clock, 0 for normal */
 	unsigned char  bclk_master;     /* SND_SOC_TPLG_BCLK_ value */
 	unsigned char  fsync_master;    /* SND_SOC_TPLG_FSYNC_ value */
-	unsigned char  mclk_direction;  /* 0 for input, 1 for output */
+	unsigned char  mclk_direction;  /* SND_SOC_TPLG_MCLK_ value */
 	unsigned short reserved;        /* for 32bit alignment */
 	unsigned int mclk_rate;	        /* MCLK or SYSCLK freqency in Hz */
 	unsigned int bclk_rate;	        /* BCLK freqency in Hz */
src/topology/pcm.c +13 -2
index b53f6b03..2ce1651b 100644
@@ -1223,8 +1223,19 @@ 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->mclk_direction = true;
+			if (!strcmp(val, "master")) {
+				/* For backwards capability,
+				 * "master" == "for codec, mclk is input"
+				 */
+				SNDERR("warning: deprecated mclk value '%s'\n",
+				       val);
+
+				hw_cfg->mclk_direction = SND_SOC_TPLG_MCLK_CI;
+			} else if (!strcmp(val, "codec_mclk_in")) {
+				hw_cfg->mclk_direction = SND_SOC_TPLG_MCLK_CI;
+			} else if (!strcmp(val, "codec_mclk_out")) {
+				hw_cfg->mclk_direction = SND_SOC_TPLG_MCLK_CO;
+			}
 			continue;
 		}
 
Signature · 1 line
2.13.6
#4 lore raw

PATCH v4 4/4 ASoC: topology: Add alias conf parameter names for hw_configs

In reply to Kirill Marinushkin

Currently, some parameter names in conf differ from field names in struct. These look like typos.

This commit suggests to add aliases for such parameters, so that the names in conf are similar to names in struct. This solution is backwards compatible.

If the difference between conf names and struct names is done on purpose - this commit can be dropped.

---
 src/topology/pcm.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
src/topology/pcm.c +20 -10
index 2ce1651b..8ebfafd8 100644
@@ -1126,7 +1126,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "format") == 0) {
+		if (strcmp(id, "format") == 0 ||
+		    strcmp(id, "fmt") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1137,7 +1138,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "bclk") == 0) {
+		if (strcmp(id, "bclk") == 0 ||
+		    strcmp(id, "bclk_master") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1157,7 +1159,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "bclk_freq") == 0) {
+		if (strcmp(id, "bclk_freq") == 0 ||
+		    strcmp(id, "bclk_rate") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1165,7 +1168,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "bclk_invert") == 0) {
+		if (strcmp(id, "bclk_invert") == 0 ||
+		    strcmp(id, "invert_bclk") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1174,7 +1178,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "fsync") == 0) {
+		if (strcmp(id, "fsync") == 0 ||
+		    strcmp(id, "fsync_master") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1194,7 +1199,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "fsync_invert") == 0) {
+		if (strcmp(id, "fsync_invert") == 0 ||
+		    strcmp(id, "invert_fsync") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1203,7 +1209,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "fsync_freq") == 0) {
+		if (strcmp(id, "fsync_freq") == 0 ||
+		    strcmp(id, "fsync_rate") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1211,7 +1218,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "mclk_freq") == 0) {
+		if (strcmp(id, "mclk_freq") == 0 ||
+		    strcmp(id, "mclk_rate") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1219,7 +1227,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "mclk") == 0) {
+		if (strcmp(id, "mclk") == 0 ||
+		    strcmp(id, "mclk_direction") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
@@ -1239,7 +1248,8 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
 			continue;
 		}
 
-		if (strcmp(id, "pm_gate_clocks") == 0) {
+		if (strcmp(id, "pm_gate_clocks") == 0 ||
+		    strcmp(id, "clock_gated") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
Signature · 1 line
2.13.6
#5 lore raw
In reply to Kirill Marinushkin
Quoted 15 lines · Kirill Marinushkin

Hello Takashi,

This patch series waits since 20th of February, because it modifies UAPI headers and should be done in sync with Linux and ALSA. I see that previously there was no clear understanding, how to do this in sync.

We discussed with you on 02 Apr 2018, and you suggested the following steps:

Step 1. A person from Intel, who knows the topic (Pierre), adds his "Reviewed-by" or "Acked-by" tags
Step 2. I clarify with Mark to apply the Linux part (different patch series) Step 3. After that, I clarify with you to apply the ALSA part (this patch series)

Quoted 8 lines

The step 1 is done. Old patches are reviewed by Pierre, so they have his "Reviewed-by" tag. New patches are suggested by him, and we agreed on the implementation, so they have his "Acked-by" tag.

The step 2 is done. Mark applied the corresponding part to his Linux tree [1].

Now we are on the step 3. If you don't have anything against this patch series, please apply it to ALSA.

Ideally, Mark should send the pull request for the uapi changes he applied so that they are "fixated" before going further to user-space patches.

But this topology change is no intrusive ABI breakage, so I applied now as is.

thanks,

Takashi

#6 lore raw
Quoted 3 lines · Takashi Iwai

Ideally, Mark should send the pull request for the uapi changes he applied so that they are "fixated" before going further to user-space patches.

Unfortunately that's a bit annoying to do now without using topic branches...

Quoted 2 lines

But this topology change is no intrusive ABI breakage, so I applied now as is.

Yeah, it didn't look like there was an actual dependency which was why I didn't immediately push anything.

#7 lore raw
In reply to Takashi Iwai
Quoted 22 lines · Takashi Iwai
Quoted 20 lines · Kirill Marinushkin

Hello Takashi,

This patch series waits since 20th of February, because it modifies UAPI headers and should be done in sync with Linux and ALSA. I see that previously there was no clear understanding, how to do this in sync.

We discussed with you on 02 Apr 2018, and you suggested the following steps:

Step 1. A person from Intel, who knows the topic (Pierre), adds his "Reviewed-by" or "Acked-by" tags
Step 2. I clarify with Mark to apply the Linux part (different patch series) Step 3. After that, I clarify with you to apply the ALSA part (this patch series)

The step 1 is done. Old patches are reviewed by Pierre, so they have his "Reviewed-by" tag. New patches are suggested by him, and we agreed on the implementation, so they have his "Acked-by" tag.

The step 2 is done. Mark applied the corresponding part to his Linux tree [1].

Quoted 8 lines
Quoted 2 lines

Now we are on the step 3. If you don't have anything against this patch series, please apply it to ALSA.

Ideally, Mark should send the pull request for the uapi changes he applied so that they are "fixated" before going further to user-space patches.

But this topology change is no intrusive ABI breakage, so I applied now as is.

Thank you

Quoted 5 lines

thanks,

Takashi