From patchwork Tue Apr 29 12:51:22 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: 4087321 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 C076C9F169 for ; Tue, 29 Apr 2014 12:51:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E971120121 for ; Tue, 29 Apr 2014 12:51:52 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 6725A200F3 for ; Tue, 29 Apr 2014 12:51:51 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id D879C2650BE; Tue, 29 Apr 2014 14:51:49 +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 alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 9E9A52650A0; Tue, 29 Apr 2014 14:51:38 +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 9F98C2650A4; Tue, 29 Apr 2014 14:51:37 +0200 (CEST) Received: from smtp-out-008.synserver.de (smtp-out-063.synserver.de [212.40.185.63]) by alsa0.perex.cz (Postfix) with ESMTP id A052D26509A for ; Tue, 29 Apr 2014 14:51:29 +0200 (CEST) Received: (qmail 23920 invoked by uid 0); 29 Apr 2014 12:51:27 -0000 X-SynServer-TrustedSrc: 1 X-SynServer-AuthUser: lars@metafoo.de X-SynServer-PPID: 23640 Received: from p4fe6335f.dip0.t-ipconnect.de (HELO lars-adi-laptop.analog.com) [79.230.51.95] by 217.119.54.87 with SMTP; 29 Apr 2014 12:51:26 -0000 From: Lars-Peter Clausen To: Mark Brown , Liam Girdwood Date: Tue, 29 Apr 2014 14:51:22 +0200 Message-Id: <1398775882-2321-1-git-send-email-lars@metafoo.de> X-Mailer: git-send-email 1.8.0 Cc: alsa-devel@alsa-project.org, Lars-Peter Clausen , Benoit Cousson Subject: [alsa-devel] [PATCH] ASoC: dapm: Factor out duplicated code in soc_dapm_stream_event() 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 In soc_dapm_stream_event() we have the same code twice, once for the codec_dai and once for the cpu_dai. This patch factors the duplicated code out into a separate function. This will make it easier to modify the implementation (since there is only one place that needs to be updated) and also easier to add support for more than two DAIs per DAI link. Signed-off-by: Lars-Peter Clausen --- sound/soc/soc-dapm.c | 51 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index a2475e1..1871dfc 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3446,32 +3446,25 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card) } } -static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, +static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream, int event) { + struct snd_soc_dapm_widget *w; - struct snd_soc_dapm_widget *w_cpu, *w_codec; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; - struct snd_soc_dai *codec_dai = rtd->codec_dai; - - if (stream == SNDRV_PCM_STREAM_PLAYBACK) { - w_cpu = cpu_dai->playback_widget; - w_codec = codec_dai->playback_widget; - } else { - w_cpu = cpu_dai->capture_widget; - w_codec = codec_dai->capture_widget; - } - - if (w_cpu) { + if (stream == SNDRV_PCM_STREAM_PLAYBACK) + w = dai->playback_widget; + else + w = dai->capture_widget; - dapm_mark_dirty(w_cpu, "stream event"); + if (w) { + dapm_mark_dirty(w, "stream event"); switch (event) { case SND_SOC_DAPM_STREAM_START: - w_cpu->active = 1; + w->active = 1; break; case SND_SOC_DAPM_STREAM_STOP: - w_cpu->active = 0; + w->active = 0; break; case SND_SOC_DAPM_STREAM_SUSPEND: case SND_SOC_DAPM_STREAM_RESUME: @@ -3480,25 +3473,13 @@ static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, break; } } +} - if (w_codec) { - - dapm_mark_dirty(w_codec, "stream event"); - - switch (event) { - case SND_SOC_DAPM_STREAM_START: - w_codec->active = 1; - break; - case SND_SOC_DAPM_STREAM_STOP: - w_codec->active = 0; - break; - case SND_SOC_DAPM_STREAM_SUSPEND: - case SND_SOC_DAPM_STREAM_RESUME: - case SND_SOC_DAPM_STREAM_PAUSE_PUSH: - case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: - break; - } - } +static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, + int event) +{ + soc_dapm_dai_stream_event(rtd->cpu_dai, stream, event); + soc_dapm_dai_stream_event(rtd->codec_dai, stream, event); dapm_power_widgets(rtd->card, event); }