From patchwork Sat Mar 15 11:09:39 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: 3836821 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 3F861BF540 for ; Sat, 15 Mar 2014 11:43:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 410C420373 for ; Sat, 15 Mar 2014 11:43:23 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id EB0292034F for ; Sat, 15 Mar 2014 11:43:21 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id DA53D265581; Sat, 15 Mar 2014 12:43:20 +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 1CB212650F7; Sat, 15 Mar 2014 12:42:42 +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 633292650BA; Sat, 15 Mar 2014 12:42:32 +0100 (CET) Received: from smtp2-g21.free.fr (smtp2-g21.free.fr [212.27.42.2]) by alsa0.perex.cz (Postfix) with ESMTP id 805CD26506D for ; Sat, 15 Mar 2014 12:42:04 +0100 (CET) Received: from localhost (unknown [IPv6:2a01:e35:2f5c:9de0:212:bfff:fe1e:9ce4]) by smtp2-g21.free.fr (Postfix) with ESMTP id 5F9724B0019; Sat, 15 Mar 2014 12:41:55 +0100 (CET) X-Mailbox-Line: From 1cf50fea2306bcb05987533042dbf1495b2c6f07 Mon Sep 17 00:00:00 2001 Message-Id: <1cf50fea2306bcb05987533042dbf1495b2c6f07.1394883134.git.moinejf@free.fr> In-Reply-To: References: From: Jean-Francois Moine Date: Sat, 15 Mar 2014 12:09:39 +0100 To: Mark Brown Cc: alsa-devel@alsa-project.org, Xiubo Li , linux-kernel@vger.kernel.org, Kuninori Morimoto Subject: [alsa-devel] [PATCH v3 2/4] 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 | 49 +++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index ca7e63e..a55dc46 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_dais { + struct asoc_simple_dai cpu_dai; + struct asoc_simple_dai codec_dai; + } *dais; + 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->dais->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->dais->cpu_dai); if (ret < 0) return ret; @@ -184,7 +186,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, np = of_get_child_by_name(node, "simple-audio-card,cpu"); if (np) { ret = asoc_simple_card_sub_parse_of(np, daifmt, - &priv->cpu_dai, + &priv->dais->cpu_dai, &dai_link->cpu_of_node, &dai_link->cpu_dai_name); of_node_put(np); @@ -197,7 +199,7 @@ static int asoc_simple_card_parse_of(struct device_node *node, np = of_get_child_by_name(node, "simple-audio-card,codec"); if (np) { ret = asoc_simple_card_sub_parse_of(np, daifmt, - &priv->codec_dai, + &priv->dais->codec_dai, &dai_link->codec_of_node, &dai_link->codec_dai_name); of_node_put(np); @@ -226,12 +228,12 @@ static int asoc_simple_card_parse_of(struct device_node *node, dev_dbg(dev, "platform : %04x\n", daifmt); dev_dbg(dev, "cpu : %s / %04x / %d\n", dai_link->cpu_dai_name, - priv->cpu_dai.fmt, - priv->cpu_dai.sysclk); + priv->dais->cpu_dai.fmt, + priv->dais->cpu_dai.sysclk); dev_dbg(dev, "codec : %s / %04x / %d\n", dai_link->codec_dai_name, - priv->codec_dai.fmt, - priv->codec_dai.sysclk); + priv->dais->codec_dai.fmt, + priv->dais->codec_dai.sysclk); /* * soc_bind_dai_link() will check cpu name @@ -276,7 +278,9 @@ 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); + priv = devm_kzalloc(dev, + sizeof(*priv) + sizeof(*dai_link), + GFP_KERNEL); if (!priv) return -ENOMEM; @@ -285,10 +289,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->dais = devm_kzalloc(dev, + sizeof(*priv->dais), + GFP_KERNEL); + if (!priv->dais) + return -ENOMEM; + if (np && of_device_is_available(np)) { ret = asoc_simple_card_parse_of(np, priv, dev); @@ -322,13 +333,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->dais->cpu_dai, &cinfo->cpu_dai, + sizeof(priv->dais->cpu_dai)); + memcpy(&priv->dais->codec_dai, &cinfo->codec_dai, + sizeof(priv->dais->codec_dai)); - priv->cpu_dai.fmt |= cinfo->daifmt; - priv->codec_dai.fmt |= cinfo->daifmt; + priv->dais->cpu_dai.fmt |= cinfo->daifmt; + priv->dais->codec_dai.fmt |= cinfo->daifmt; } /*