From patchwork Mon Aug 10 14:48:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lin, Mengdong" X-Patchwork-Id: 6985181 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F20C0C05AC for ; Mon, 10 Aug 2015 14:38:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 10ED2203F7 for ; Mon, 10 Aug 2015 14:38:16 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id BFB12203AC for ; Mon, 10 Aug 2015 14:38:14 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 406DD265AEC; Mon, 10 Aug 2015 16:38:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 5DA302659B6; Mon, 10 Aug 2015 16:36:21 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 4357D2659B6; Mon, 10 Aug 2015 16:36:20 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id 18EFB265A58 for ; Mon, 10 Aug 2015 16:35:02 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 10 Aug 2015 07:35:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,645,1432623600"; d="scan'208";a="745692215" Received: from amanda-hsw-pc.sh.intel.com ([10.239.159.75]) by orsmga001.jf.intel.com with ESMTP; 10 Aug 2015 07:35:01 -0700 From: mengdong.lin@intel.com To: alsa-devel@alsa-project.org Date: Mon, 10 Aug 2015 22:48:19 +0800 Message-Id: <66ecc438c3f464ec6baeb892b1cab674c935f6db.1439217448.git.mengdong.lin@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Cc: tiwai@suse.de, Mengdong Lin , broonie@kernel.org, liam.r.girdwood@intel.com Subject: [alsa-devel] [PATCH v2 07/10] ASoC: Support adding a DAI dynamically X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mengdong Lin API snd_soc_add_dai() is defined to register a DAI dynamically, create its DAI widget, and notify the machine driver. This API can be used by the topology core to add DAIs dynamically. And a callback add_dai() is defined for the soc card. The machine driver can implement this callback. Adding a new DAI dynmaically will trigger this callback, and the machine driver can create relavant DAI link in the callback context. Signed-off-by: Mengdong Lin diff --git a/include/sound/soc.h b/include/sound/soc.h index 7e04ec0..2a474c8 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1081,6 +1081,7 @@ struct snd_soc_card { int (*set_bias_level_post)(struct snd_soc_card *, struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level); + int (*add_dai)(struct snd_soc_card *, struct snd_soc_dai_driver*); long pmdown_time; @@ -1634,6 +1635,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 #ifdef CONFIG_DEBUG_FS diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 2818709..b330676 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2792,6 +2792,98 @@ 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_card *card = component->card; + 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); + } + + /* Notify the machine driver a new DAI is added, so the machine driver + * can add new DAI links in the callback context. + */ + if (card && card->add_dai) + card->add_dai(card, dai_drv); + + 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) {