From patchwork Thu Mar 20 09:52:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Francois Moine X-Patchwork-Id: 3865051 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5EBE3BF540 for ; Thu, 20 Mar 2014 11:07:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74BE220225 for ; Thu, 20 Mar 2014 11:07:15 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 37C1620179 for ; Thu, 20 Mar 2014 11:07:14 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1B73C26527E; Thu, 20 Mar 2014 12:07:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 1C79126522D; Thu, 20 Mar 2014 12:06:30 +0100 (CET) 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 E9063265249; Thu, 20 Mar 2014 12:06:27 +0100 (CET) Received: from smtp3-g21.free.fr (smtp3-g21.free.fr [212.27.42.3]) by alsa0.perex.cz (Postfix) with ESMTP id 64A972650C0 for ; Thu, 20 Mar 2014 12:06:20 +0100 (CET) Received: from localhost (unknown [IPv6:2a01:e35:2f5c:9de0:212:bfff:fe1e:9ce4]) by smtp3-g21.free.fr (Postfix) with ESMTP id B7D74A627D; Thu, 20 Mar 2014 12:06:14 +0100 (CET) X-Mailbox-Line: From c13dd9ff3dd912409efca130685856a9a2a301ef Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Jean-Francois Moine Date: Thu, 20 Mar 2014 10:52:41 +0100 To: Jyri Sarha Cc: alsa-devel@alsa-project.org, Mark Brown Subject: [alsa-devel] [PARTIAL PATCH 1/3] ASoC: simple-card: dynamically allocate the DAI link and properties 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 The DAI link array and the properties (fmt, sysclk slots) are hard-coded for a single CPU / CODEC link. This patch dynamically allocates the DAI link array and the properties with the aim of supporting many DAI links. Signed-off-by: Jean-Francois Moine --- sound/soc/generic/simple-card.c | 42 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 2ee8ed5..1e865c5 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -20,9 +20,11 @@ struct simple_card_data { struct snd_soc_card snd_card; - struct asoc_simple_dai cpu_dai; - struct asoc_simple_dai codec_dai; - struct snd_soc_dai_link snd_link; + struct simple_dai_props { + struct asoc_simple_dai cpu_dai; + struct asoc_simple_dai codec_dai; + } *dai_props; + struct snd_soc_dai_link dai_link[]; /* dynamically allocated */ }; static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, @@ -70,11 +72,11 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) struct snd_soc_dai *cpu = rtd->cpu_dai; int ret; - ret = __asoc_simple_card_dai_init(codec, &priv->codec_dai); + ret = __asoc_simple_card_dai_init(codec, &priv->dai_props->codec_dai); if (ret < 0) return ret; - ret = __asoc_simple_card_dai_init(cpu, &priv->cpu_dai); + ret = __asoc_simple_card_dai_init(cpu, &priv->dai_props->cpu_dai); if (ret < 0) return ret; @@ -151,8 +153,8 @@ static int asoc_simple_card_parse_of(struct device_node *node, struct device *dev) { struct snd_soc_dai_link *dai_link = priv->snd_card.dai_link; - struct asoc_simple_dai *codec_dai = &priv->codec_dai; - struct asoc_simple_dai *cpu_dai = &priv->cpu_dai; + struct asoc_simple_dai *codec_dai = &priv->dai_props->codec_dai; + struct asoc_simple_dai *cpu_dai = &priv->dai_props->cpu_dai; struct device_node *np; char *name; unsigned int daifmt; @@ -284,7 +286,10 @@ static int asoc_simple_card_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + /* allocate the private data and the DAI link array */ + priv = devm_kzalloc(dev, + sizeof(*priv) + sizeof(*dai_link), + GFP_KERNEL); if (!priv) return -ENOMEM; @@ -293,10 +298,17 @@ static int asoc_simple_card_probe(struct platform_device *pdev) */ priv->snd_card.owner = THIS_MODULE; priv->snd_card.dev = dev; - dai_link = &priv->snd_link; + dai_link = priv->dai_link; priv->snd_card.dai_link = dai_link; priv->snd_card.num_links = 1; + /* get room for the other properties */ + priv->dai_props = devm_kzalloc(dev, + sizeof(*priv->dai_props), + GFP_KERNEL); + if (!priv->dai_props) + return -ENOMEM; + if (np && of_device_is_available(np)) { ret = asoc_simple_card_parse_of(np, priv, dev); @@ -330,13 +342,13 @@ static int asoc_simple_card_probe(struct platform_device *pdev) dai_link->codec_name = cinfo->codec; dai_link->cpu_dai_name = cinfo->cpu_dai.name; dai_link->codec_dai_name = cinfo->codec_dai.name; - memcpy(&priv->cpu_dai, &cinfo->cpu_dai, - sizeof(priv->cpu_dai)); - memcpy(&priv->codec_dai, &cinfo->codec_dai, - sizeof(priv->codec_dai)); + memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai, + sizeof(priv->dai_props->cpu_dai)); + memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai, + sizeof(priv->dai_props->codec_dai)); - priv->cpu_dai.fmt |= cinfo->daifmt; - priv->codec_dai.fmt |= cinfo->daifmt; + priv->dai_props->cpu_dai.fmt |= cinfo->daifmt; + priv->dai_props->codec_dai.fmt |= cinfo->daifmt; } /*