From patchwork Mon Aug 10 06:13:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lin, Mengdong" X-Patchwork-Id: 6979511 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 2B6B4C05AC for ; Mon, 10 Aug 2015 06:06:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 433DA20769 for ; Mon, 10 Aug 2015 06:06:47 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id EFE5920773 for ; Mon, 10 Aug 2015 06:06:45 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id EE8712655E3; Mon, 10 Aug 2015 08:06:44 +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 DB3A62657B1; Mon, 10 Aug 2015 08:03:34 +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 F01FB2657AB; Mon, 10 Aug 2015 08:03:32 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by alsa0.perex.cz (Postfix) with ESMTP id A524E265205 for ; Mon, 10 Aug 2015 08:00:41 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 09 Aug 2015 23:00:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,643,1432623600"; d="scan'208";a="780992240" Received: from amanda-hsw-pc.sh.intel.com ([10.239.159.75]) by orsmga002.jf.intel.com with ESMTP; 09 Aug 2015 23:00:38 -0700 From: mengdong.lin@intel.com To: alsa-devel@alsa-project.org Date: Mon, 10 Aug 2015 14:13:57 +0800 Message-Id: <1439187237-1368-1-git-send-email-mengdong.lin@intel.com> X-Mailer: git-send-email 1.9.1 Cc: tiwai@suse.de, Mengdong Lin , broonie@kernel.org, liam.r.girdwood@intel.com Subject: [alsa-devel] [RFC PATCH 10/10] ASOC: topology: Add PCM DAIs dynamically when loading them 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 Add PCM DAIs to ASoC core when loading them from topology. Embed dobj in the DAI to free it when unloading. Signed-off-by: Mengdong Lin diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index 2df96b1..e8f0404 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -207,6 +207,7 @@ struct snd_soc_dai_driver { const char *name; unsigned int id; unsigned int base; + struct snd_soc_dobj dobj; /* DAI driver callbacks */ int (*probe)(struct snd_soc_dai *dai); diff --git a/include/sound/soc-topology.h b/include/sound/soc-topology.h index 5405f64..a49c134 100644 --- a/include/sound/soc-topology.h +++ b/include/sound/soc-topology.h @@ -71,7 +71,6 @@ struct snd_soc_dobj { union { struct snd_soc_dobj_control control; struct snd_soc_dobj_widget widget; - struct snd_soc_dobj_pcm_dai pcm_dai; }; void *private; /* core does not touch this */ }; diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 0f8fa0d..6c0dd3f 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -499,6 +499,9 @@ static void remove_widget(struct snd_soc_component *comp, static void remove_pcm_dai(struct snd_soc_component *comp, struct snd_soc_dobj *dobj, int pass) { + struct snd_soc_dai_driver *dai = + container_of(dobj, struct snd_soc_dai_driver, dobj); + if (pass != SOC_TPLG_PASS_PCM_DAI) return; @@ -506,7 +509,7 @@ static void remove_pcm_dai(struct snd_soc_component *comp, dobj->ops->pcm_dai_unload(comp, dobj); list_del(&dobj->list); - kfree(dobj); + kfree(dai); } /* bind a kcontrol to it's IO handlers */ @@ -1558,12 +1561,75 @@ static int soc_tplg_dapm_complete(struct soc_tplg *tplg) return 0; } +static unsigned int get_rates(unsigned int rate_min, unsigned int rate_max) +{ + static int pcm_rates[] = { + 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, + 64000, 88200, 96000, 176400, 192000, + }; + unsigned int rates = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(pcm_rates); i++) { + if (pcm_rates[i] >= rate_min && pcm_rates[i] <= rate_max) + rates |= 1 << i; + } + + return rates; +} + +static int soc_tplg_pcm_dai_create(struct soc_tplg *tplg, + struct snd_soc_tplg_pcm_dai *dai) +{ + struct snd_soc_dai_driver *dai_drv; + struct snd_soc_pcm_stream *stream; + struct snd_soc_tplg_stream_caps *caps; + + dai_drv = kzalloc(sizeof(struct snd_soc_dai_driver), GFP_KERNEL); + if (dai_drv == NULL) + return -ENOMEM; + + dai_drv->name = dai->name; + dai_drv->id = dai->id; + dai_drv->compress_dai = dai->compress; + + if (dai->playback) { + stream = &dai_drv->playback; + caps = &dai->capconf[SND_SOC_TPLG_STREAM_PLAYBACK].caps; + + stream->stream_name = kstrdup(caps->name, GFP_KERNEL); + stream->channels_min = caps->channels_min; + stream->channels_max = caps->channels_max; + stream->rates = get_rates(caps->rate_min, caps->rate_max); + stream->formats = caps->formats; + } + + if (dai->capture) { + stream = &dai_drv->capture; + caps = &dai->capconf[SND_SOC_TPLG_STREAM_CAPTURE].caps; + + stream->stream_name = kstrdup(caps->name, GFP_KERNEL); + stream->channels_min = caps->channels_min; + stream->channels_max = caps->channels_max; + stream->rates = get_rates(caps->rate_min, caps->rate_max); + stream->formats = caps->formats; + } + + dai_drv->dobj.index = tplg->index; + dai_drv->dobj.ops = tplg->ops; + dai_drv->dobj.type = SND_SOC_DOBJ_PCM; + list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list); + + return snd_soc_add_dai(tplg->comp, dai_drv); +} + static int soc_tplg_pcm_dai_elems_load(struct soc_tplg *tplg, struct snd_soc_tplg_hdr *hdr) { struct snd_soc_tplg_pcm_dai *pcm_dai; struct snd_soc_dobj *dobj; int count = hdr->count; + int i; int ret; if (tplg->pass != SOC_TPLG_PASS_PCM_DAI) @@ -1579,26 +1645,21 @@ static int soc_tplg_pcm_dai_elems_load(struct soc_tplg *tplg, return -EINVAL; } - dev_dbg(tplg->dev, "ASoC: adding %d PCM DAIs\n", count); - tplg->pos += sizeof(struct snd_soc_tplg_pcm_dai) * count; - - dobj = kzalloc(sizeof(struct snd_soc_dobj), GFP_KERNEL); - if (dobj == NULL) - return -ENOMEM; - - /* Call the platform driver call back to register the dais */ + /* pass control to driver for optional further init */ ret = soc_tplg_pcm_dai_load(tplg, pcm_dai, count); if (ret < 0) { dev_err(tplg->comp->dev, "ASoC: PCM DAI loading failed\n"); goto err; } - dobj->type = get_dobj_type(hdr, NULL); - dobj->pcm_dai.count = count; - dobj->pcm_dai.pd = pcm_dai; - dobj->ops = tplg->ops; - dobj->index = tplg->index; - list_add(&dobj->list, &tplg->comp->dobj_list); + /* register the dais */ + for (i = 0; i < count; i++) { + soc_tplg_pcm_dai_create(tplg, pcm_dai); + pcm_dai++; + } + + dev_dbg(tplg->dev, "ASoC: adding %d PCM DAIs\n", count); + tplg->pos += sizeof(struct snd_soc_tplg_pcm_dai) * count; return 0; err: