From: mengdong.lin@linux.intel.com
To: alsa-devel@alsa-project.org, broonie@kernel.org
Cc: Mengdong Lin <mengdong.lin@linux.intel.com>,
vinod.koul@intel.com, hardik.t.shah@intel.com,
liam.r.girdwood@linux.intel.com, mengdong.lin@intel.com,
jeeja.kp@intel.com, subhransu.s.prusty@intel.com
Subject: [PATCH v3 2/2] ASoC: topology: Add FE DAI links dynamically
Date: Tue, 16 Feb 2016 13:43:19 +0800 [thread overview]
Message-ID: <c39e9ff6933477a14f18201ef898f71536e8b89e.1455599774.git.mengdong.lin@linux.intel.com> (raw)
In-Reply-To: <cover.1455599774.git.mengdong.lin@linux.intel.com>
From: Mengdong Lin <mengdong.lin@linux.intel.com>
Topology will also create FE DAI links dynamically from the PCM
objects. These links will be removed when the component is removed
and its topology info is unloaded.
The component driver can implement link_load/unload ops for extra
intialization (e.g. error check) and destruction.
Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
diff --git a/include/sound/soc-topology.h b/include/sound/soc-topology.h
index ec562d0..d318fe4 100644
--- a/include/sound/soc-topology.h
+++ b/include/sound/soc-topology.h
@@ -125,6 +125,12 @@ struct snd_soc_tplg_ops {
int (*dai_unload)(struct snd_soc_component *,
struct snd_soc_dobj *);
+ /* DAI link - used for any driver specific init */
+ int (*link_load)(struct snd_soc_component *,
+ struct snd_soc_dai_link *link);
+ int (*link_unload)(struct snd_soc_component *,
+ struct snd_soc_dobj *);
+
/* callback to handle vendor bespoke data */
int (*vendor_load)(struct snd_soc_component *,
struct snd_soc_tplg_hdr *);
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index f7fe3da..2f7da32 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -340,6 +340,16 @@ static int soc_tplg_dai_load(struct soc_tplg *tplg,
return 0;
}
+/* pass link configurations to component driver for extra intialization */
+static int soc_tplg_dai_link_load(struct soc_tplg *tplg,
+ struct snd_soc_dai_link *link)
+{
+ if (tplg->comp && tplg->ops && tplg->ops->link_load)
+ return tplg->ops->link_load(tplg->comp, link);
+
+ return 0;
+}
+
/* tell the component driver that all firmware has been loaded in this request */
static void soc_tplg_complete(struct soc_tplg *tplg)
{
@@ -512,6 +522,24 @@ static void remove_dai(struct snd_soc_component *comp,
kfree(dai_drv);
}
+/* remove link configurations */
+static void remove_link(struct snd_soc_component *comp,
+ struct snd_soc_dobj *dobj, int pass)
+{
+ struct snd_soc_dai_link *link =
+ container_of(dobj, struct snd_soc_dai_link, dobj);
+
+ if (pass != SOC_TPLG_PASS_PCM_DAI)
+ return;
+
+ if (dobj->ops && dobj->ops->link_unload)
+ dobj->ops->link_unload(comp, dobj);
+
+ list_del(&dobj->list);
+ snd_soc_remove_dai_link(comp->card, link);
+ kfree(link);
+}
+
/* bind a kcontrol to it's IO handlers */
static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr,
struct snd_kcontrol_new *k,
@@ -1603,10 +1631,47 @@ static int soc_tplg_dai_create(struct soc_tplg *tplg,
return snd_soc_register_dai(tplg->comp, dai_drv);
}
+static int soc_tplg_link_create(struct soc_tplg *tplg,
+ struct snd_soc_tplg_pcm *pcm)
+{
+ struct snd_soc_dai_link *link;
+ int ret;
+
+ link = kzalloc(sizeof(struct snd_soc_dai_link), GFP_KERNEL);
+ if (link == NULL)
+ return -ENOMEM;
+
+ link->name = pcm->pcm_name;
+ link->stream_name = pcm->pcm_name;
+
+ /* pass control to component driver for optional further init */
+ ret = soc_tplg_dai_link_load(tplg, link);
+ if (ret < 0) {
+ dev_err(tplg->comp->dev, "ASoC: FE link loading failed\n");
+ kfree(link);
+ return ret;
+ }
+
+ link->dobj.index = tplg->index;
+ link->dobj.ops = tplg->ops;
+ link->dobj.type = SND_SOC_DOBJ_DAI_LINK;
+ list_add(&link->dobj.list, &tplg->comp->dobj_list);
+
+ snd_soc_add_dai_link(tplg->comp->card, link);
+ return 0;
+}
+
+/* create a FE DAI and DAI link from the PCM object */
static int soc_tplg_pcm_create(struct soc_tplg *tplg,
struct snd_soc_tplg_pcm *pcm)
{
- return soc_tplg_dai_create(tplg, pcm);
+ int ret;
+
+ ret = soc_tplg_dai_create(tplg, pcm);
+ if (ret < 0)
+ return ret;
+
+ return soc_tplg_link_create(tplg, pcm);
}
static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg,
@@ -1890,6 +1955,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_DAI_LINK:
+ remove_link(comp, dobj, pass);
+ break;
default:
dev_err(comp->dev, "ASoC: invalid component type %d for removal\n",
dobj->type);
--
2.5.0
next prev parent reply other threads:[~2016-02-16 5:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-16 5:39 [PATCH v3 0/2] ASoC: topology: Add support for FE DAI & DAI links mengdong.lin
2016-02-16 5:42 ` [PATCH v3 1/2] ASoC: topology: Add FE DAIs dynamically mengdong.lin
2016-02-16 5:43 ` mengdong.lin [this message]
2016-02-16 6:17 ` [PATCH v3 0/2] ASoC: topology: Add support for FE DAI & DAI links 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=c39e9ff6933477a14f18201ef898f71536e8b89e.1455599774.git.mengdong.lin@linux.intel.com \
--to=mengdong.lin@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=hardik.t.shah@intel.com \
--cc=jeeja.kp@intel.com \
--cc=liam.r.girdwood@linux.intel.com \
--cc=mengdong.lin@intel.com \
--cc=subhransu.s.prusty@intel.com \
--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).