From patchwork Tue Jul 1 20:13:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 4462001 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 214DF9F26C for ; Tue, 1 Jul 2014 20:15:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C6352037D for ; Tue, 1 Jul 2014 20:15:40 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id C39AA20379 for ; Tue, 1 Jul 2014 20:15:38 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id B9D4526513A; Tue, 1 Jul 2014 22:15:32 +0200 (CEST) Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 1495126513A; Tue, 1 Jul 2014 22:14:08 +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 246102650D1; Tue, 1 Jul 2014 22:14:05 +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=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from smtp-out-155.synserver.de (smtp-out-155.synserver.de [212.40.185.155]) by alsa0.perex.cz (Postfix) with ESMTP id 633912650E1 for ; Tue, 1 Jul 2014 22:14:01 +0200 (CEST) Received: (qmail 17503 invoked by uid 0); 1 Jul 2014 20:14:01 -0000 X-SynServer-TrustedSrc: 1 X-SynServer-AuthUser: lars@metafoo.de X-SynServer-PPID: 17156 Received: from ppp-46-244-166-46.dynamic.mnet-online.de (HELO lars-adi-laptop.fritz.box) [46.244.166.46] by 217.119.54.96 with SMTP; 1 Jul 2014 20:14:00 -0000 From: Lars-Peter Clausen To: Mark Brown , Liam Girdwood Date: Tue, 1 Jul 2014 22:13:48 +0200 Message-Id: <1404245628-30877-5-git-send-email-lars@metafoo.de> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1404245628-30877-1-git-send-email-lars@metafoo.de> References: <1404245628-30877-1-git-send-email-lars@metafoo.de> Cc: alsa-devel@alsa-project.org, Lars-Peter Clausen , Sebastian Reichel , Benoit Cousson Subject: [alsa-devel] [PATCH 4/4] ASoC: Move non-shared code paths out of snd_soc_post_component_init() 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 There are two call sites for snd_soc_post_component_init(), one passes 0 and the other 1 for the 'dailess' parameter of snd_soc_post_component_init(). Depending on whether 'dailess' is 0 or 1 snd_soc_post_component_init() runs different code at the beginning and the end of the function. The patch moves this conditional code out of snd_soc_post_component_init() and into the call sites. This removes the need for snd_soc_post_component_init() to know whether it is called for a DAI link or a aux dev. Also do the initialization of rtd->card when the rtd struct is allocated. Signed-off-by: Lars-Peter Clausen --- sound/soc/soc-core.c | 121 ++++++++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 75 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 0b870bb..6712e2f 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1286,74 +1286,17 @@ static void rtd_release(struct device *dev) kfree(dev); } -static int soc_aux_dev_init(struct snd_soc_card *card, int num) +static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, + const char *name) { - struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; - struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; - int ret; - - rtd->card = card; - - /* do machine specific initialization */ - if (aux_dev->init) { - ret = aux_dev->init(&rtd->codec->dapm); - if (ret < 0) - return ret; - } - - return 0; -} - -static int soc_dai_link_init(struct snd_soc_card *card, int num) -{ - struct snd_soc_dai_link *dai_link = &card->dai_link[num]; - struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; - int ret; - - rtd->card = card; - - /* do machine specific initialization */ - if (dai_link->init) { - ret = dai_link->init(rtd); - if (ret < 0) - return ret; - } - - return 0; -} - -static int soc_post_component_init(struct snd_soc_card *card, - int num, int dailess) -{ - struct snd_soc_dai_link *dai_link = NULL; - struct snd_soc_aux_dev *aux_dev = NULL; - struct snd_soc_pcm_runtime *rtd; - const char *name; int ret = 0; - if (!dailess) { - dai_link = &card->dai_link[num]; - rtd = &card->rtd[num]; - name = dai_link->name; - ret = soc_dai_link_init(card, num); - } else { - aux_dev = &card->aux_dev[num]; - rtd = &card->rtd_aux[num]; - name = aux_dev->name; - ret = soc_aux_dev_init(card, num); - } - - if (ret < 0) { - dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret); - return ret; - } - /* register the rtd device */ rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); if (!rtd->dev) return -ENOMEM; device_initialize(rtd->dev); - rtd->dev->parent = card->dev; + rtd->dev->parent = rtd->card->dev; rtd->dev->release = rtd_release; rtd->dev->init_name = name; dev_set_drvdata(rtd->dev, rtd); @@ -1366,7 +1309,7 @@ static int soc_post_component_init(struct snd_soc_card *card, if (ret < 0) { /* calling put_device() here to free the rtd->dev */ put_device(rtd->dev); - dev_err(card->dev, + dev_err(rtd->card->dev, "ASoC: failed to register runtime device: %d\n", ret); return ret; } @@ -1384,17 +1327,6 @@ static int soc_post_component_init(struct snd_soc_card *card, dev_err(rtd->dev, "ASoC: failed to add codec sysfs files: %d\n", ret); -#ifdef CONFIG_DEBUG_FS - /* add DPCM sysfs entries */ - if (!dailess && !dai_link->dynamic) - goto out; - - ret = soc_dpcm_debugfs_add(rtd); - if (ret < 0) - dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret); - -out: -#endif return 0; } @@ -1546,10 +1478,33 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) if (order != SND_SOC_COMP_ORDER_LAST) return 0; - ret = soc_post_component_init(card, num, 0); + /* do machine specific initialization */ + if (dai_link->init) { + ret = dai_link->init(rtd); + if (ret < 0) { + dev_err(card->dev, "ASoC: failed to init %s: %d\n", + dai_link->name, ret); + return ret; + } + } + + ret = soc_post_component_init(rtd, dai_link->name); if (ret) return ret; +#ifdef CONFIG_DEBUG_FS + /* add DPCM sysfs entries */ + if (dai_link->dynamic) { + ret = soc_dpcm_debugfs_add(rtd); + if (ret < 0) { + dev_err(rtd->dev, + "ASoC: failed to add dpcm sysfs entries: %d\n", + ret); + return ret; + } + } +#endif + ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); if (ret < 0) dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n", @@ -1665,6 +1620,7 @@ static int soc_bind_aux_dev(struct snd_soc_card *card, int num) static int soc_probe_aux_dev(struct snd_soc_card *card, int num) { struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; + struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; int ret; if (rtd->codec->probed) { @@ -1676,7 +1632,17 @@ static int soc_probe_aux_dev(struct snd_soc_card *card, int num) if (ret < 0) return ret; - return soc_post_component_init(card, num, 1); + /* do machine specific initialization */ + if (aux_dev->init) { + ret = aux_dev->init(&rtd->codec->dapm); + if (ret < 0) { + dev_err(card->dev, "ASoC: failed to init %s: %d\n", + aux_dev->name, ret); + return ret; + } + } + + return soc_post_component_init(rtd, aux_dev->name); } static void soc_remove_aux_dev(struct snd_soc_card *card, int num) @@ -3775,8 +3741,13 @@ int snd_soc_register_card(struct snd_soc_card *card) card->num_rtd = 0; card->rtd_aux = &card->rtd[card->num_links]; - for (i = 0; i < card->num_links; i++) + for (i = 0; i < card->num_links; i++) { + card->rtd[i].card = card; card->rtd[i].dai_link = &card->dai_link[i]; + } + + for (i = 0; i < card->num_aux_devs; i++) + card->rtd_aux[i].card = card; INIT_LIST_HEAD(&card->dapm_dirty); card->instantiated = 0;