alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: mengdong.lin@linux.intel.com
To: alsa-devel@alsa-project.org
Cc: Mengdong Lin <mengdong.lin@linux.intel.com>,
	tiwai@suse.de, hardik.t.shah@intel.com,
	guneshwor.o.singh@intel.com, liam.r.girdwood@linux.intel.com,
	vinod.koul@intel.com, broonie@kernel.org, mengdong.lin@intel.com
Subject: [PATCH 14/22] topology: Parse HW configurations of physical DAI links in text conf file
Date: Thu, 27 Oct 2016 15:13:55 +0800	[thread overview]
Message-ID: <554154dd9a7d28c1a868b8cad66ef1169b6c5741.1477549962.git.mengdong.lin@linux.intel.com> (raw)
In-Reply-To: <cover.1477549962.git.mengdong.lin@linux.intel.com>

From: Mengdong Lin <mengdong.lin@linux.intel.com>

Users can configure the runtime supported HW configurations of a physical
link by SectionHWConfig. A physical link can refer multiple HW config
sections in SectionLink.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>

diff --git a/include/topology.h b/include/topology.h
index 8323dd9..cf25de5 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -632,10 +632,31 @@ extern "C" {
  *
  *	id "0"				# used for binding to the link
  *
+ *	hw_configs [	# runtime supported HW configurations, optional
+ *		"config1"
+ *		"config2"
+ *		...
+ *	]
+ *
+ *	default_hw_conf_id "1"		#default HW config ID for init
+ *
  *	data "name"			# optional private data
  * }
  * </pre>
  *
+ * A physical link can refer to multiple runtime supported hardware
+ * configurations, which is defined by SectionHWConfig.
+ *
+ * <pre>
+ * SectionHWConfig."name" {
+ *
+ *	id "1"				# used for binding to the config
+ *	format "I2S"			# physical audio format.
+ *	bclk   "master"			# Platform is master of bit clock
+ *	fsync  "slave"			# Platform is slave of fsync
+ * }
+ * </pre>
+ *
  * <h4>Manifest Private Data</h4>
  * Manfiest may have private data. Users need to define a manifest section
  * and add the references to 1 or multiple data sections. Please refer to
@@ -677,6 +698,7 @@ enum snd_tplg_type {
 	SND_TPLG_TYPE_TOKEN,		/*!< Vendor tokens */
 	SND_TPLG_TYPE_TUPLE,		/*!< Vendor tuples */
 	SND_TPLG_TYPE_LINK,		/*!< Physical DAI link */
+	SND_TPLG_TYPE_HW_CONFIG,	/*!< Link HW config */
 };
 
 /**
diff --git a/src/topology/elem.c b/src/topology/elem.c
index f7ff070..01dce1f 100644
--- a/src/topology/elem.c
+++ b/src/topology/elem.c
@@ -208,6 +208,10 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
 		list_add_tail(&elem->list, &tplg->tuple_list);
 		elem->free = tplg_free_tuples;
 		break;
+	case SND_TPLG_TYPE_HW_CONFIG:
+		list_add_tail(&elem->list, &tplg->hw_cfg_list);
+		obj_size = sizeof(struct snd_soc_tplg_hw_config);
+		break;
 	default:
 		free(elem);
 		return NULL;
diff --git a/src/topology/parser.c b/src/topology/parser.c
index 238943c..7d0486c 100644
--- a/src/topology/parser.c
+++ b/src/topology/parser.c
@@ -133,6 +133,14 @@ static int tplg_parse_config(snd_tplg_t *tplg, snd_config_t *cfg)
 			continue;
 		}
 
+		if (strcmp(id, "SectionHWConfig") == 0) {
+			err = tplg_parse_compound(tplg, n, tplg_parse_hw_config,
+				NULL);
+			if (err < 0)
+				return err;
+			continue;
+		}
+
 		if (strcmp(id, "SectionLink") == 0
 			|| strcmp(id, "SectionBE") == 0) {
 			err = tplg_parse_compound(tplg, n, tplg_parse_link,
@@ -455,6 +463,7 @@ snd_tplg_t *snd_tplg_new(void)
 	INIT_LIST_HEAD(&tplg->bytes_ext_list);
 	INIT_LIST_HEAD(&tplg->token_list);
 	INIT_LIST_HEAD(&tplg->tuple_list);
+	INIT_LIST_HEAD(&tplg->hw_cfg_list);
 
 	return tplg;
 }
@@ -480,6 +489,7 @@ void snd_tplg_free(snd_tplg_t *tplg)
 	tplg_elem_free_list(&tplg->bytes_ext_list);
 	tplg_elem_free_list(&tplg->token_list);
 	tplg_elem_free_list(&tplg->tuple_list);
+	tplg_elem_free_list(&tplg->hw_cfg_list);
 
 	free(tplg);
 }
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
index 58efc2f..9e5bb8e 100644
--- a/src/topology/pcm.c
+++ b/src/topology/pcm.c
@@ -162,6 +162,34 @@ static int build_link(snd_tplg_t *tplg, struct tplg_elem *elem)
 	if (err < 0)
 		return err;
 
+	/* hw configs */
+	base = &elem->ref_list;
+	list_for_each(pos, base) {
+
+		ref = list_entry(pos, struct tplg_ref, list);
+
+		switch (ref->type) {
+		case SND_TPLG_TYPE_HW_CONFIG:
+			ref->elem = tplg_elem_lookup(&tplg->hw_cfg_list,
+					ref->id, SND_TPLG_TYPE_HW_CONFIG);
+			if (!ref->elem) {
+				SNDERR("error: cannot find HW config '%s'"
+				" referenced by link '%s'\n",
+				ref->id, elem->id);
+				return -EINVAL;
+			}
+
+			memcpy(&link->hw_config[num_hw_configs],
+				ref->elem->hw_cfg,
+				sizeof(struct snd_soc_tplg_hw_config));
+			num_hw_configs++;
+			break;
+
+		default:
+			break;
+		}
+	}
+
 	/* add link to manifest */
 	tplg->manifest.dai_link_elems++;
 
@@ -541,6 +569,54 @@ int tplg_parse_pcm(snd_tplg_t *tplg,
 	return 0;
 }
 
+/* parse physical link runtime supported HW configs in text conf file */
+static int parse_hw_config_refs(snd_tplg_t *tplg, snd_config_t *cfg,
+				struct tplg_elem *elem)
+{
+	struct snd_soc_tplg_link_config *link = elem->link;
+	snd_config_type_t  type;
+	snd_config_iterator_t i, next;
+	snd_config_t *n;
+	const char *id, *val = NULL;
+
+	if (snd_config_get_id(cfg, &id) < 0)
+		return -EINVAL;
+	type = snd_config_get_type(cfg);
+
+	/* refer to a single HW config */
+	if (type == SND_CONFIG_TYPE_STRING) {
+		if (snd_config_get_string(cfg, &val) < 0)
+			return -EINVAL;
+
+		link->num_hw_configs = 1;
+		return tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val);
+	}
+
+	if (type != SND_CONFIG_TYPE_COMPOUND) {
+		SNDERR("error: compound type expected for %s", id);
+		return -EINVAL;
+	}
+
+	/* refer to a list of HW configs */
+	snd_config_for_each(i, next, cfg) {
+		const char *val;
+
+		n = snd_config_iterator_entry(i);
+		if (snd_config_get_string(n, &val) < 0)
+			continue;
+
+		if (link->num_hw_configs >= SND_SOC_TPLG_HW_CONFIG_MAX) {
+			SNDERR("error: exceed max hw configs for link %s", id);
+			return -EINVAL;
+		}
+
+		link->num_hw_configs++;
+		return tplg_ref_add(elem, SND_TPLG_TYPE_HW_CONFIG, val);
+	}
+
+	return 0;
+}
+
 /* Parse a physical link element in text conf file */
 int tplg_parse_link(snd_tplg_t *tplg,
 	snd_config_t *cfg, void *private ATTRIBUTE_UNUSED)
@@ -591,6 +667,21 @@ int tplg_parse_link(snd_tplg_t *tplg,
 			continue;
 		}
 
+		if (strcmp(id, "hw_configs") == 0) {
+			err = parse_hw_config_refs(tplg, n, elem);
+			if (err < 0)
+				return err;
+			continue;
+		}
+
+		if (strcmp(id, "default_hw_conf_id") == 0) {
+			if (snd_config_get_string(n, &val) < 0)
+				return -EINVAL;
+
+			link->default_hw_config_id = atoi(val);
+			continue;
+		}
+
 		if (strcmp(id, "data") == 0) {
 			err = tplg_parse_data_refs(n, elem);
 			if (err < 0)
@@ -656,6 +747,110 @@ int tplg_parse_cc(snd_tplg_t *tplg,
 	return 0;
 }
 
+static int get_audio_hw_format(const char *val)
+{
+	if (!strlen(val))
+		return -EINVAL;
+
+	if (!strcmp(val, "I2S"))
+		return SND_SOC_DAI_FORMAT_I2S;
+
+	if (!strcmp(val, "RIGHT_J"))
+		return SND_SOC_DAI_FORMAT_RIGHT_J;
+
+	if (!strcmp(val, "LEFT_J"))
+		return SND_SOC_DAI_FORMAT_LEFT_J;
+
+	if (!strcmp(val, "DSP_A"))
+		return SND_SOC_DAI_FORMAT_DSP_A;
+
+	if (!strcmp(val, "LEFT_B"))
+		return SND_SOC_DAI_FORMAT_DSP_B;
+
+	if (!strcmp(val, "AC97"))
+		return SND_SOC_DAI_FORMAT_AC97;
+
+	if (!strcmp(val, "PDM"))
+		return SND_SOC_DAI_FORMAT_PDM;
+
+	SNDERR("error: invalid audio HW format %s\n", val);
+	return -EINVAL;
+}
+
+int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
+			 void *private ATTRIBUTE_UNUSED)
+{
+
+	struct snd_soc_tplg_hw_config *hw_cfg;
+	struct tplg_elem *elem;
+	snd_config_iterator_t i, next;
+	snd_config_t *n;
+	const char *id, *val = NULL;
+	int ret;
+
+	elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_HW_CONFIG);
+	if (!elem)
+		return -ENOMEM;
+
+	hw_cfg = elem->hw_cfg;
+	hw_cfg->size = elem->size;
+
+	tplg_dbg(" Link HW config: %s\n", elem->id);
+
+	snd_config_for_each(i, next, cfg) {
+
+		n = snd_config_iterator_entry(i);
+		if (snd_config_get_id(n, &id) < 0)
+			continue;
+
+		/* skip comments */
+		if (strcmp(id, "comment") == 0)
+			continue;
+		if (id[0] == '#')
+			continue;
+
+		if (strcmp(id, "id") == 0) {
+			if (snd_config_get_string(n, &val) < 0)
+				return -EINVAL;
+
+			hw_cfg->id = atoi(val);
+			tplg_dbg("\t%s: %d\n", id, hw_cfg->id);
+			continue;
+		}
+
+		if (strcmp(id, "format") == 0) {
+			if (snd_config_get_string(n, &val) < 0)
+				return -EINVAL;
+
+			ret = get_audio_hw_format(val);
+			if (ret < 0)
+				return ret;
+			hw_cfg->fmt = ret;
+			continue;
+		}
+
+		if (strcmp(id, "bclk") == 0) {
+			if (snd_config_get_string(n, &val) < 0)
+				return -EINVAL;
+
+			if (!strcmp(val, "master"))
+				hw_cfg->bclk_master = true;
+			continue;
+		}
+
+		if (strcmp(id, "fsync") == 0) {
+			if (snd_config_get_string(n, &val) < 0)
+				return -EINVAL;
+
+			if (!strcmp(val, "master"))
+				hw_cfg->fsync_master = true;
+			continue;
+		}
+	}
+
+	return 0;
+}
+
 /* copy stream object */
 static void tplg_add_stream_object(struct snd_soc_tplg_stream *strm,
 				struct snd_tplg_stream_template *strm_tpl)
diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 947f27e..9e67bf8 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -74,6 +74,7 @@ struct snd_tplg {
 	struct list_head manifest_list;
 	struct list_head pcm_config_list;
 	struct list_head pcm_caps_list;
+	struct list_head hw_cfg_list;
 
 	/* type-specific control lists */
 	struct list_head mixer_list;
@@ -148,6 +149,7 @@ struct tplg_elem {
 		struct snd_soc_tplg_dapm_graph_elem *route;
 		struct snd_soc_tplg_stream *stream_cfg;
 		struct snd_soc_tplg_stream_caps *stream_caps;
+		struct snd_soc_tplg_hw_config *hw_cfg;
 
 		/* these do not map to UAPI structs but are internal only */
 		struct snd_soc_tplg_ctl_tlv *tlv;
@@ -226,6 +228,9 @@ int tplg_parse_link(snd_tplg_t *tplg,
 int tplg_parse_cc(snd_tplg_t *tplg,
 	snd_config_t *cfg, void *private ATTRIBUTE_UNUSED);
 
+int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
+			 void *private ATTRIBUTE_UNUSED);
+
 int tplg_build_data(snd_tplg_t *tplg);
 int tplg_build_manifest_data(snd_tplg_t *tplg);
 int tplg_build_controls(snd_tplg_t *tplg);
-- 
2.5.0

  parent reply	other threads:[~2016-10-27  7:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27  7:09 [PATCH 00/22] topology: Remaining user space patches of ABI v5 mengdong.lin
2016-10-27  7:11 ` [PATCH 01/22] topology: ABI - Update stream caps and PCM objects to " mengdong.lin
2016-10-27  7:11 ` [PATCH 02/22] topology: Parse sig_bits of stream caps mengdong.lin
2016-10-27  7:11 ` [PATCH 03/22] topology: Parse flags for PCM mengdong.lin
2016-10-27  7:11 ` [PATCH 04/22] topology: Define a function to build a single PCM element mengdong.lin
2016-10-27  7:11 ` [PATCH 05/22] topology: Parse and build private data for PCM mengdong.lin
2016-10-27  7:12 ` [PATCH 06/22] topology: tplg_elem_lookup() checks parameter before searching mengdong.lin
2016-10-27  7:12 ` [PATCH 07/22] topology: Merge an element's be & cc pointer to one link pointer mengdong.lin
2016-10-27  7:12 ` [PATCH 08/22] topology: Define a function to build a single physical DAI link mengdong.lin
2016-10-27  7:13 ` [PATCH 09/22] topology: ABI - Define DAI physical PCM data formats mengdong.lin
2016-10-27  7:13 ` [PATCH 10/22] topology: ABI - Update physical DAI link configurations to ABI v5 mengdong.lin
2016-10-27  7:13 ` [PATCH 11/22] topology: Rename varaibles for add physical links by C API mengdong.lin
2016-10-27  7:13 ` [PATCH 12/22] topology: Define new type and section name to configure physical links mengdong.lin
2016-10-27  7:13 ` [PATCH 13/22] topology: Parse HW configurations of physical DAI links defined by C API mengdong.lin
2016-10-27  7:13 ` mengdong.lin [this message]
2016-10-27  7:14 ` [PATCH 15/22] topology: Parse link flags of physical DAI links mengdong.lin
2016-10-27  7:14 ` [PATCH 16/22] topology: Parse and build private data of physical links mengdong.lin
2016-10-27  7:14 ` [PATCH 17/22] topology: Parse name and stream name of physical DAI links mengdong.lin
2016-10-27  7:14 ` [PATCH 18/22] topology: ABI - Update manifest to ABI v5 mengdong.lin
2016-10-27  7:14 ` [PATCH 19/22] topology: ABI - Define new types for physical DAI mengdong.lin
2016-10-27  7:14 ` [PATCH 20/22] topology: Parse physical DAIs in text conf file mengdong.lin
2016-10-27  7:15 ` [PATCH 21/22] topology: Support configuring physical DAIs by C API mengdong.lin
2016-10-27  7:15 ` [PATCH 22/22] topology: Export physical DAIs to the binary for kernel mengdong.lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=554154dd9a7d28c1a868b8cad66ef1169b6c5741.1477549962.git.mengdong.lin@linux.intel.com \
    --to=mengdong.lin@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=guneshwor.o.singh@intel.com \
    --cc=hardik.t.shah@intel.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=mengdong.lin@intel.com \
    --cc=tiwai@suse.de \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).