Skip to contentSkip to conversation

topology: Fix parsing config with multiple hw_configs

PATCH Superseded Kirill Marinushkin 2 participants 7 messages Feb 19, 2018 – Feb 20, 2018 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 topology: Fix parsing config with multiple hw_configs

Currently, if the config file includes several hw_configs sections, parse_hw_config_refs() returns after parsing only the first section.

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

~~~~
SectionHWConfig."CodecHWConfig" {
id "1"
format "I2S" # physical audio format.
bclk "master" # Platform is master of bit clock
fsync "master" # platform is master of fsync
}

SectionHWConfig."CodecHWConfig2" {
        id "2"
        format "AC97"
}

SectionLink."Codec" {

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

        default_hw_conf_id "2"
}

~~~~

---
 src/topology/pcm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/topology/pcm.c +4 -1
index 58cee31d..d3836677 100644
@@ -882,6 +882,7 @@ static int parse_hw_config_refs(snd_tplg_t *tplg, snd_config_t *cfg,
 	/* refer to a list of HW configs */
 	snd_config_for_each(i, next, cfg) {
 		const char *val;
+		int err;
 
 		n = snd_config_iterator_entry(i);
 		if (snd_config_get_string(n, &val) < 0)
@@ -893,7 +894,9 @@ static int parse_hw_config_refs(snd_tplg_t *tplg, snd_config_t *cfg,
 		}
 
 		link->num_hw_configs++;
-		return tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val);
+		err = tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val);
+		if (err < 0)
+			return err;
 	}
 
 	return 0;
Signature · 1 line
2.13.6
#1 lore raw

PATCH 2/2 ASoC: topology: Rename clock_gated to clock_cont in snd_soc_tplg_hw_config

In kernel soc-dai.h, DAI clock gating is defined as following:

~~~~
\#define SND_SOC_DAIFMT_CONT (1 << 4) /* continuous clock */
\#define SND_SOC_DAIFMT_GATED (0 << 4) /* clock is gated */
~~~~

Therefore, the corresponding field of struct snd_soc_tplg_hw_config should be inverted compared to the current logic:

clock_count = 1 => SND_SOC_DAIFMT_CONT
clock_count = 0 => SND_SOC_DAIFMT_GATED

---
 include/sound/asoc.h | 4 +++-
 include/topology.h   | 4 +++-
 src/topology/pcm.c   | 6 +++---
 3 files changed, 9 insertions(+), 5 deletions(-)
include/sound/asoc.h +3 -1
index 0f5d9f9a..9f601ef0 100644
@@ -308,7 +308,9 @@ 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_cont;	/* 1 if clock is continuous, and can not 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 */
include/topology.h +3 -1
index 8779da4d..630fee21 100644
@@ -997,7 +997,9 @@ 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_cont;	/* 1 if clock is continuous, and can not
+					 * 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 */
src/topology/pcm.c +3 -3
index d3836677..7f280ed0 100644
@@ -1205,12 +1205,12 @@ 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_cont_clock") == 0) {
 			if (snd_config_get_string(n, &val) < 0)
 				return -EINVAL;
 
 			if (!strcmp(val, "true"))
-				hw_cfg->clock_gated = true;
+				hw_cfg->clock_cont = true;
 			continue;
 		}
 
@@ -1376,7 +1376,7 @@ static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg,
 	cfg->id = tpl->id;
 
 	cfg->fmt = tpl->fmt;
-	cfg->clock_gated = tpl->clock_gated;
+	cfg->clock_cont = tpl->clock_cont;
 	cfg->invert_bclk = tpl->invert_bclk;
 	cfg->invert_fsync = tpl->invert_fsync;
 	cfg->bclk_master = tpl->bclk_master;
Signature · 1 line
2.13.6
#2 lore raw

Re: [PATCH, alsa-lib 2/2] ASoC: topology: Rename clock_gated to clock_cont in snd_soc_tplg_hw_config

Hi,

Quoted 13 lines · Kirill Marinushkin

In kernel soc-dai.h, DAI clock gating is defined as following:

~~~~
\#define SND_SOC_DAIFMT_CONT (1 << 4) /* continuous clock */
\#define SND_SOC_DAIFMT_GATED (0 << 4) /* clock is gated */
~~~~

Therefore, the corresponding field of struct snd_soc_tplg_hw_config should be inverted compared to the current logic:

clock_count = 1 => SND_SOC_DAIFMT_CONT
clock_count = 0 => SND_SOC_DAIFMT_GATED

Quoted 8 lines
---
  include/sound/asoc.h | 4 +++-
  include/topology.h   | 4 +++-
  src/topology/pcm.c   | 6 +++---
  3 files changed, 9 insertions(+), 5 deletions(-)

This change is based on breakage of ABI compatibility which I pointed in this message[1]. Please take backward compatibility in account when working for any change for interfaces between kernel/user spaces.

Quoted 50 lines
include/sound/asoc.h +3 -1
index 0f5d9f9a..9f601ef0 100644
@@ -308,7 +308,9 @@ 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_cont;	/* 1 if clock is continuous, and can not 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 */
include/topology.h +3 -1
index 8779da4d..630fee21 100644
@@ -997,7 +997,9 @@ 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_cont;	/* 1 if clock is continuous, and can not
+					 * 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 */
src/topology/pcm.c +2 -2
index d3836677..7f280ed0 100644
@@ -1205,12 +1205,12 @@ 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_cont_clock") == 0) {
  			if (snd_config_get_string(n, &val) < 0)
  				return -EINVAL;
 
  			if (!strcmp(val, "true"))
-				hw_cfg->clock_gated = true;
+				hw_cfg->clock_cont = true;
  			continue;
  		}
 

src/topology/pcm.c static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg, · line 1382

Quoted 8 lines
src/topology/pcm.c +1 -1
@@ -1376,7 +1376,7 @@ static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg,
  	cfg->id = tpl->id;
 
  	cfg->fmt = tpl->fmt;
-	cfg->clock_gated = tpl->clock_gated;
+	cfg->clock_cont = tpl->clock_cont;
  	cfg->invert_bclk = tpl->invert_bclk;
  	cfg->invert_fsync = tpl->invert_fsync;
  	cfg->bclk_master = tpl->bclk_master;

[1] [alsa-devel] [PATCH 1/2] ASoC: topology: Rename clock_gated to clock_cont in snd_soc_tplg_hw_config
http://mailman.alsa-project.org/pipermail/alsa-devel/2018-February/132264.html

Regards

Takashi Sakamoto

#3 lore raw

Re: [PATCH, alsa-lib 2/2] ASoC: topology: Rename clock_gated to clock_cont in snd_soc_tplg_hw_config

Quoted 86 lines · Takashi Sakamoto

Hi,

Quoted 13 lines · Kirill Marinushkin

In kernel soc-dai.h, DAI clock gating is defined as following:

~~~~
\#define SND_SOC_DAIFMT_CONT            (1 << 4) /* continuous clock */ \#define SND_SOC_DAIFMT_GATED           (0 << 4) /* clock is gated */
~~~~

Therefore, the corresponding field of struct snd_soc_tplg_hw_config should be inverted compared to the current logic:

clock_count = 1 => SND_SOC_DAIFMT_CONT
clock_count = 0 => SND_SOC_DAIFMT_GATED

Quoted 8 lines

---
  include/sound/asoc.h | 4 +++-
  include/topology.h   | 4 +++-
  src/topology/pcm.c   | 6 +++---

  3 files changed, 9 insertions(+), 5 deletions(-)

This change is based on breakage of ABI compatibility which I pointed in this message[1]. Please take backward compatibility in account when working for any change for interfaces between kernel/user spaces.

Quoted 48 lines
include/sound/asoc.h +0 -0
index 0f5d9f9a..9f601ef0 100644
@@ -308,7 +308,9 @@ 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_cont;    /* 1 if clock is continuous, and can not 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 */

include/topology.h +0 -0
index 8779da4d..630fee21 100644
@@ -997,7 +997,9 @@ 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_cont;    /* 1 if clock is continuous, and can not +                     * 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 */

src/topology/pcm.c +2 -1
index d3836677..7f280ed0 100644
@@ -1205,12 +1205,12 @@ 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_cont_clock") == 0) {
               if (snd_config_get_string(n, &val) < 0)
                   return -EINVAL;
                 if (!strcmp(val, "true"))
-                hw_cfg->clock_gated = true;
+                hw_cfg->clock_cont = true;
               continue;
           }
   @@ -1376,7 +1376,7 @@ static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg,
       cfg->id = tpl->id;
Quoted 6 lines

        cfg->fmt = tpl->fmt;
-    cfg->clock_gated = tpl->clock_gated;
+    cfg->clock_cont = tpl->clock_cont;
      cfg->invert_bclk = tpl->invert_bclk;
      cfg->invert_fsync = tpl->invert_fsync;
      cfg->bclk_master = tpl->bclk_master;

[1] [alsa-devel] [PATCH 1/2] ASoC: topology: Rename clock_gated to clock_cont in snd_soc_tplg_hw_config
http://mailman.alsa-project.org/pipermail/alsa-devel/2018-February/132264.html

Quoted 3 lines

Regards

Takashi Sakamoto

Hello Takashi Sakamoto,

I will propose a backwards-compatible solution as a PATCH v2.

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

#4 lore raw

PATCH v2 1/2 topology: Fix parsing config with multiple hw_configs

In reply to Takashi Sakamoto

Currently, if the config file includes several hw_configs sections, parse_hw_config_refs() returns after parsing only the first section.

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

~~~~
SectionHWConfig."CodecHWConfig" {
id "1"
format "I2S" # physical audio format.
bclk "master" # Platform is master of bit clock
fsync "master" # platform is master of fsync
}

SectionHWConfig."CodecHWConfig2" {
        id "2"
        format "AC97"
}

SectionLink."Codec" {

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

        default_hw_conf_id "2"
}

~~~~

---
 src/topology/pcm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/topology/pcm.c +4 -1
index 58cee31d..d3836677 100644
@@ -882,6 +882,7 @@ static int parse_hw_config_refs(snd_tplg_t *tplg, snd_config_t *cfg,
 	/* refer to a list of HW configs */
 	snd_config_for_each(i, next, cfg) {
 		const char *val;
+		int err;
 
 		n = snd_config_iterator_entry(i);
 		if (snd_config_get_string(n, &val) < 0)
@@ -893,7 +894,9 @@ static int parse_hw_config_refs(snd_tplg_t *tplg, snd_config_t *cfg,
 		}
 
 		link->num_hw_configs++;
-		return tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val);
+		err = tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val);
+		if (err < 0)
+			return err;
 	}
 
 	return 0;
Signature · 1 line
2.13.6
#5 lore raw

PATCH v2 2/2 ASoC: topology: Add defines for snd_soc_tplg_hw_config.clock_gated

In kernel soc-dai.h, DAI clock gating is defined as following:

~~~~
\#define SND_SOC_DAIFMT_CONT (1 << 4) /* continuous clock */
\#define SND_SOC_DAIFMT_GATED (0 << 4) /* clock is gated */
~~~~

The corresponding field of struct snd_soc_tplg_hw_config cannot be used as bool values due to the inverted logic. Therefore this commit adds the defines for this field.

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

---
 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 0f5d9f9a..8f3d7bac 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.
  */
@@ -308,7 +313,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;	/* 1 for master of BCLK, 0 for slave */
include/topology.h +1 -1
index 8779da4d..80d959be 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;     /* 1 for master of BCLK, 0 for slave */
src/topology/pcm.c +5 -1
index d3836677..973f3028 100644
@@ -1210,7 +1210,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
#6 lore raw
In reply to Kirill Marinushkin
Quoted 53 lines · Kirill Marinushkin

Currently, if the config file includes several hw_configs sections, parse_hw_config_refs() returns after parsing only the first section.

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

~~~~
SectionHWConfig."CodecHWConfig" {
id "1"
format "I2S" # physical audio format.
bclk "master" # Platform is master of bit clock
fsync "master" # platform is master of fsync
}

SectionHWConfig."CodecHWConfig2" {
        id "2"
        format "AC97"
}

SectionLink."Codec" {

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

        default_hw_conf_id "2"
}

~~~~

---
 src/topology/pcm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/topology/pcm.c +1 -0
index 58cee31d..d3836677 100644
@@ -882,6 +882,7 @@ static int parse_hw_config_refs(snd_tplg_t *tplg, snd_config_t *cfg,
 	/* refer to a list of HW configs */
 	snd_config_for_each(i, next, cfg) {
 		const char *val;
+		int err;
 
 		n = snd_config_iterator_entry(i);
 		if (snd_config_get_string(n, &val) < 0)

src/topology/pcm.c static int parse_hw_config_refs(snd_tplg_t *tplg, snd_config_t *cfg, · line 902

Quoted 10 lines
src/topology/pcm.c +3 -1
@@ -893,7 +894,9 @@ static int parse_hw_config_refs(snd_tplg_t *tplg, snd_config_t *cfg,
 		}
 
 		link->num_hw_configs++;
-		return tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val);
+		err = tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val);
+		if (err < 0)
+			return err;
 	}
 
 	return 0;

This patch is outdated. Patch v2 is sent in a different thread to replace it.

Best Regards,
Kirill