diff mbox

[3/3] ASoC: topology: Able to create BE DAIs

Message ID 001ecaeba478e2ef863a232c89412b09d4b6de11.1469165422.git.mengdong.lin@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

mengdong.lin@linux.intel.com July 22, 2016, 5:59 a.m. UTC
From: Mengdong Lin <mengdong.lin@linux.intel.com>

Topology will check with ASoC if a BE DAI already exists by checking
its name. If the BE DAI doesn't exist, topology will create a new one
and the dai_load ops will be called for device specific init.

Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com>
Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>

Comments

Lin, Mengdong July 25, 2016, 1:58 a.m. UTC | #1
Sorry for the mistake. I'll fix this warning.

Thanks
Mengdong

> -----Original Message-----
> From: Wu, Fengguang
> Sent: Friday, July 22, 2016 8:48 PM
> To: mengdong.lin@linux.intel.com
> Cc: kbuild-all@01.org; alsa-devel@alsa-project.org; broonie@kernel.org;
> Mengdong Lin; tiwai@suse.de; Shah, Hardik T; Singh, Guneshwor O;
> liam.r.girdwood@linux.intel.com; Lin, Mengdong
> Subject: Re: [PATCH 3/3] ASoC: topology: Able to create BE DAIs
> 
> Hi Mengdong,
> 
> [auto build test WARNING on asoc/for-next] [also build test WARNING on
> v4.7-rc7]
> 
> url:
> https://github.com/0day-ci/linux/commits/mengdong-lin-linux-intel-com/AS
> oC-topology-Add-support-for-BE-DAIs/20160722-160125
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
> for-next
> config: x86_64-randconfig-s0-07221711 (attached as .config)
> compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
> reproduce:
>          # save the attached .config to linux build tree
>          make ARCH=x86_64
> 
> All warnings (new ones prefixed by >>):
> 
>     sound/soc/soc-topology.c: In function 'soc_tplg_be_dai_config':
> >> sound/soc/soc-topology.c:1790: warning: too many arguments for
> format
>     At top level:
>     cc1: warning: unrecognized command line option
> "-Wno-maybe-uninitialized"
> 
> git remote add linux-review https://github.com/0day-ci/linux git remote
> update linux-review git checkout
> 234d57f817caf65062dd97dcd7e44be8f5e721e3
> vim +1790 sound/soc/soc-topology.c
> 
> 234d57f8 Mengdong Lin 2016-07-22  1774   * soc_tplg_be_dai_config -
> Create a new BE DAI or configure an existing one.
> 234d57f8 Mengdong Lin 2016-07-22  1775   * @tplg: topology context
> 234d57f8 Mengdong Lin 2016-07-22  1776   * @be: topology BE DAI
> configs.
> 234d57f8 Mengdong Lin 2016-07-22  1777   *
> 234d57f8 Mengdong Lin 2016-07-22  1778   * The BE dai should already
> be registered by the platform driver. The
> 234d57f8 Mengdong Lin 2016-07-22  1779   * platform driver should
> specify the BE DAI name and ID for matching.
> 234d57f8 Mengdong Lin 2016-07-22  1780   */
> 234d57f8 Mengdong Lin 2016-07-22  1781  static int
> soc_tplg_be_dai_config(struct soc_tplg *tplg,
> 234d57f8 Mengdong Lin 2016-07-22  1782  				  struct
> snd_soc_tplg_be_dai *be)
> 234d57f8 Mengdong Lin 2016-07-22  1783  {
> 234d57f8 Mengdong Lin 2016-07-22  1784  	struct
> snd_soc_dai_link_component dai_component = {0};
> 234d57f8 Mengdong Lin 2016-07-22  1785  	struct snd_soc_dai *dai;
> 234d57f8 Mengdong Lin 2016-07-22  1786  	struct snd_soc_dai_driver
> *dai_drv;
> 234d57f8 Mengdong Lin 2016-07-22  1787
> 234d57f8 Mengdong Lin 2016-07-22  1788  	if (!strlen(be->dai_name)) {
> 234d57f8 Mengdong Lin 2016-07-22  1789  		dev_err(tplg->dev,
> "ASoC: Invalid BE DAI name\n",
> 234d57f8 Mengdong Lin 2016-07-22 @1790  			be->dai_name);
> 234d57f8 Mengdong Lin 2016-07-22  1791  		return -EINVAL;
> 234d57f8 Mengdong Lin 2016-07-22  1792  	}
> 234d57f8 Mengdong Lin 2016-07-22  1793
> 234d57f8 Mengdong Lin 2016-07-22  1794  	dai_component.dai_name =
> be->dai_name;
> 234d57f8 Mengdong Lin 2016-07-22  1795  	dai =
> snd_soc_find_dai(&dai_component);
> 234d57f8 Mengdong Lin 2016-07-22  1796  	if (!dai) /* BE DAI doesn't
> exist, create it */
> 234d57f8 Mengdong Lin 2016-07-22  1797  		return
> soc_tplg_be_dai_create(tplg, be);
> 234d57f8 Mengdong Lin 2016-07-22  1798
> 
> ---
> 0-DAY kernel test infrastructure                Open Source Technology
> Center
> https://lists.01.org/pipermail/kbuild-all                   Intel
> Corporation
diff mbox

Patch

diff --git a/include/sound/soc-topology.h b/include/sound/soc-topology.h
index b897b9d..c7aa6e2 100644
--- a/include/sound/soc-topology.h
+++ b/include/sound/soc-topology.h
@@ -39,6 +39,7 @@  enum snd_soc_dobj_type {
 	SND_SOC_DOBJ_ENUM,
 	SND_SOC_DOBJ_BYTES,
 	SND_SOC_DOBJ_PCM,
+	SND_SOC_DOBJ_BE_DAI,
 	SND_SOC_DOBJ_DAI_LINK,
 	SND_SOC_DOBJ_CODEC_LINK,
 	SND_SOC_DOBJ_WIDGET,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 16369ca..c0ee988 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2872,7 +2872,8 @@  int snd_soc_register_dai(struct snd_soc_component *component,
 	struct snd_soc_dai *dai;
 	int ret;
 
-	if (dai_drv->dobj.type != SND_SOC_DOBJ_PCM) {
+	if (!(dai_drv->dobj.type == SND_SOC_DOBJ_PCM ||
+	    dai_drv->dobj.type == SND_SOC_DOBJ_BE_DAI)) {
 		dev_err(component->dev, "Invalid dai type %d\n",
 			dai_drv->dobj.type);
 		return -EINVAL;
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index 05a18f6..924f370 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -1709,42 +1709,14 @@  static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg,
 	return 0;
 }
 
-/* *
- * soc_tplg_be_dai_config - Find and configure an existing BE DAI.
- * @tplg: topology context
- * @be: topology BE DAI configs.
- *
- * The BE dai should already be registered by the platform driver. The
- * platform driver should specify the BE DAI name and ID for matching.
- */
-static int soc_tplg_be_dai_config(struct soc_tplg *tplg,
+static int config_be_dai(struct soc_tplg *tplg,
+				  struct snd_soc_dai_driver *dai_drv,
 				  struct snd_soc_tplg_be_dai *be)
 {
-	struct snd_soc_dai_link_component dai_component = {0};
-	struct snd_soc_dai *dai;
-	struct snd_soc_dai_driver *dai_drv;
 	struct snd_soc_pcm_stream *stream;
 	struct snd_soc_tplg_stream_caps *caps;
 	int ret;
 
-	dai_component.dai_name = be->dai_name;
-	dai = snd_soc_find_dai(&dai_component);
-	if (!dai) {
-		dev_err(tplg->dev, "ASoC: BE DAI %s not registered\n",
-			be->dai_name);
-		return -EINVAL;
-	}
-
-	if (be->dai_id != dai->id) {
-		dev_err(tplg->dev, "ASoC: BE DAI %s id mismatch\n",
-			be->dai_name);
-		return -EINVAL;
-	}
-
-	dai_drv = dai->driver;
-	if (!dai_drv)
-		return -EINVAL;
-
 	if (be->playback) {
 		stream = &dai_drv->playback;
 		caps = &be->caps[SND_SOC_TPLG_STREAM_PLAYBACK];
@@ -1770,6 +1742,74 @@  static int soc_tplg_be_dai_config(struct soc_tplg *tplg,
 	return 0;
 }
 
+static int soc_tplg_be_dai_create(struct soc_tplg *tplg,
+				  struct snd_soc_tplg_be_dai *be)
+{
+	struct snd_soc_dai_driver *dai_drv;
+	int ret;
+
+	dai_drv = kzalloc(sizeof(struct snd_soc_dai_driver), GFP_KERNEL);
+	if (dai_drv == NULL)
+		return -ENOMEM;
+
+	dai_drv->name = be->dai_name;
+	dai_drv->id = be->dai_id;
+
+	ret = config_be_dai(tplg, dai_drv, be);
+	if (ret < 0) {
+		kfree(dai_drv);
+		return ret;
+	}
+
+	dai_drv->dobj.index = tplg->index;
+	dai_drv->dobj.ops = tplg->ops;
+	dai_drv->dobj.type = SND_SOC_DOBJ_BE_DAI;
+	list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list);
+
+	/* register the DAI to the component */
+	return snd_soc_register_dai(tplg->comp, dai_drv);
+}
+
+/* *
+ * soc_tplg_be_dai_config - Create a new BE DAI or configure an existing one.
+ * @tplg: topology context
+ * @be: topology BE DAI configs.
+ *
+ * The BE dai should already be registered by the platform driver. The
+ * platform driver should specify the BE DAI name and ID for matching.
+ */
+static int soc_tplg_be_dai_config(struct soc_tplg *tplg,
+				  struct snd_soc_tplg_be_dai *be)
+{
+	struct snd_soc_dai_link_component dai_component = {0};
+	struct snd_soc_dai *dai;
+	struct snd_soc_dai_driver *dai_drv;
+
+	if (!strlen(be->dai_name)) {
+		dev_err(tplg->dev, "ASoC: Invalid BE DAI name\n",
+			be->dai_name);
+		return -EINVAL;
+	}
+
+	dai_component.dai_name = be->dai_name;
+	dai = snd_soc_find_dai(&dai_component);
+	if (!dai) /* BE DAI doesn't exist, create it */
+		return soc_tplg_be_dai_create(tplg, be);
+
+	/* configure an existing BE DAI */
+	if (be->dai_id != dai->id) {
+		dev_err(tplg->dev, "ASoC: BE DAI %s id mismatch\n",
+			be->dai_name);
+		return -EINVAL;
+	}
+
+	dai_drv = dai->driver;
+	if (!dai_drv)
+		return -EINVAL;
+
+	return config_be_dai(tplg, dai_drv, be);
+}
+
 static int soc_tplg_be_dai_elems_load(struct soc_tplg *tplg,
 				      struct snd_soc_tplg_hdr *hdr)
 {
@@ -2061,6 +2101,9 @@  int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index)
 			case SND_SOC_DOBJ_PCM:
 				remove_dai(comp, dobj, pass);
 				break;
+			case SND_SOC_DOBJ_BE_DAI:
+				remove_dai(comp, dobj, pass);
+				break;
 			case SND_SOC_DOBJ_DAI_LINK:
 				remove_link(comp, dobj, pass);
 				break;