All of lore.kernel.org
 help / color / mirror / Atom feed
From: mengdong.lin@linux.intel.com
To: alsa-devel@alsa-project.org, broonie@kernel.org
Cc: Mengdong Lin <mengdong.lin@linux.intel.com>,
	tiwai@suse.de, mengdong.lin@intel.com,
	liam.r.girdwood@linux.intel.com, vinod.koul@intel.com,
	jeeja.kp@intel.com, subhransu.s.prusty@intel.com
Subject: [PATCH v2 10/13] ASoC: Support adding a DAI dynamically
Date: Thu,  5 Nov 2015 17:59:50 +0800	[thread overview]
Message-ID: <9c1204fda157a42123471a71897fec264f359cf3.1446717205.git.mengdong.lin@linux.intel.com> (raw)
In-Reply-To: <cover.1446717205.git.mengdong.lin@linux.intel.com>

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

API snd_soc_add_dai() is defined to register a DAI dynamically and
create its DAI widget. This API can be used by the topology core
to add DAIs.

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

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 13e1409..a6e6a1b 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1667,6 +1667,9 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,
 void snd_soc_add_dai_link(struct snd_soc_card *card,
 				struct snd_soc_dai_link *dai_link);
 
+int snd_soc_add_dai(struct snd_soc_component *component,
+	struct snd_soc_dai_driver *dai_drv);
+
 #include <sound/soc-dai.h>
 
 #ifdef CONFIG_DEBUG_FS
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 23d067ae..f4bf26c 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2786,6 +2786,91 @@ err:
 	return ret;
 }
 
+static struct snd_soc_dai *soc_register_dai(struct snd_soc_component *component,
+	struct snd_soc_dai_driver *dai_drv,
+	bool legacy_dai_naming)
+{
+	struct device *dev = component->dev;
+	struct snd_soc_dai *dai;
+	int ret;
+
+	dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
+
+	dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
+	if (dai == NULL) {
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	/*
+	 * Back in the old days when we still had component-less DAIs,
+	 * instead of having a static name, component-less DAIs would
+	 * inherit the name of the parent device so it is possible to
+	 * register multiple instances of the DAI. We still need to keep
+	 * the same naming style even though those DAIs are not
+	 * component-less anymore.
+	 */
+	if (legacy_dai_naming) {
+		dai->name = fmt_single_name(dev, &dai->id);
+	} else {
+		dai->name = fmt_multiple_name(dev, dai_drv);
+		if (dai_drv->id)
+			dai->id = dai_drv->id;
+		else
+			dai->id = component->num_dai;
+	}
+	if (dai->name == NULL) {
+		kfree(dai);
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	dai->component = component;
+	dai->dev = dev;
+	dai->driver = dai_drv;
+	if (!dai->driver->ops)
+		dai->driver->ops = &null_dai_ops;
+
+	list_add(&dai->list, &component->dai_list);
+	component->num_dai++;
+
+	dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
+	return dai;
+
+err:
+	kfree(dai);
+	return NULL;
+}
+
+/**
+ * snd_soc_add_dai - Add a DAI dynamically with the ASoC core
+ *
+ * @component: The component the DAIs are registered for
+ * @dai_drv: DAI driver to use for the DAI
+ */
+int snd_soc_add_dai(struct snd_soc_component *component,
+	struct snd_soc_dai_driver *dai_drv)
+{
+	struct snd_soc_dapm_context *dapm =
+		snd_soc_component_get_dapm(component);
+	struct snd_soc_dai *dai;
+	int ret;
+
+	lockdep_assert_held(&client_mutex);
+	dai = soc_register_dai(component, dai_drv, false);
+	if (!dai)
+		return -ENOMEM;
+
+	ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
+	if (ret != 0) {
+		dev_err(component->dev,
+			"Failed to create DAI widgets %d\n", ret);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_add_dai);
+
 static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm,
 	enum snd_soc_dapm_type type, int subseq)
 {
-- 
1.9.1

  parent reply	other threads:[~2015-11-05  9:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05  9:58 [PATCH v2 00/13] ASoC: topology: Add support for PCM, BE & CC links mengdong.lin
2015-11-05  9:58 ` [PATCH v2 01/13] ASoC: Vendor drivers get a link's runtime by snd_soc_get_pcm_runtime() mengdong.lin
2015-11-05  9:58 ` [PATCH v2 02/13] ASoC: Change the PCM runtime array to a list mengdong.lin
2015-11-05  9:58 ` [PATCH v2 03/13] ASoC: Define soc_init_dai_link() to wrap link intialization mengdong.lin
2015-11-05  9:58 ` [PATCH v2 04/13] ASoC: Change 2nd argument of soc_bind_dai_link() to DAI link pointer mengdong.lin
2015-11-25 17:57   ` Applied "ASoC: Change 2nd argument of soc_bind_dai_link() to DAI link pointer" to the asoc tree Mark Brown
2015-11-05  9:59 ` [PATCH v2 05/13] ASoC: Implement DAI links in a list & define API to add a link mengdong.lin
2015-11-05  9:59 ` [PATCH v2 06/13] ASoC: Add add_dai_link ops for a soc card mengdong.lin
2015-11-05  9:59 ` [PATCH v2 07/13] ASoC: soc_bind_dai_link() directly returns success for a bound DAI link mengdong.lin
2015-12-08 19:11   ` Applied "ASoC: soc_bind_dai_link() directly returns success for a bound DAI link" to the asoc tree Mark Brown
2015-11-05  9:59 ` [PATCH v2 08/13] ASoC: Bind new DAI links after probing components mengdong.lin
2015-12-08 19:11   ` Applied "ASoC: Bind new DAI links after probing components" to the asoc tree Mark Brown
2015-11-05  9:59 ` [PATCH v2 09/13] ASoC: The soc card can have auxiliary components mengdong.lin
2015-11-26 12:57   ` Lars-Peter Clausen
2015-11-05  9:59 ` mengdong.lin [this message]
2015-11-05  9:59 ` [PATCH v2 11/13] ASoC: topology: Add PCM DAIs dynamically when loading them mengdong.lin
2015-11-05 10:00 ` [PATCH v2 12/13] ASoC: topology: Add support for FE DAI links mengdong.lin
2015-11-05 10:00 ` [PATCH v2 13/13] ASoC: topology: Add support for BE and CC DAI Links mengdong.lin
2015-11-05 10:15 ` [PATCH v2 00/13] ASoC: topology: Add support for PCM, BE & CC 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=9c1204fda157a42123471a71897fec264f359cf3.1446717205.git.mengdong.lin@linux.intel.com \
    --to=mengdong.lin@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=jeeja.kp@intel.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=mengdong.lin@intel.com \
    --cc=subhransu.s.prusty@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.