From patchwork Fri Jul 4 16:07:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benoit Cousson X-Patchwork-Id: 4481881 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 2DD2B9F26C for ; Fri, 4 Jul 2014 16:12:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4496C2038C for ; Fri, 4 Jul 2014 16:12:36 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 10DE72034A for ; Fri, 4 Jul 2014 16:12:35 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 13235265A82; Fri, 4 Jul 2014 18:12:34 +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 C6059265A3E; Fri, 4 Jul 2014 18:10:15 +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 9DDFA265A3D; Fri, 4 Jul 2014 18:10:13 +0200 (CEST) Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com [74.125.82.44]) by alsa0.perex.cz (Postfix) with ESMTP id 5BDA7265A32 for ; Fri, 4 Jul 2014 18:09:35 +0200 (CEST) Received: by mail-wg0-f44.google.com with SMTP id k14so1840157wgh.3 for ; Fri, 04 Jul 2014 09:09:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LXTo7JFJjB8XUVa37wE6Xds56GVxtQ9yrs62pvRssgg=; b=ZvlKn4mxF0LS0k/NleqhX8V63xFY6LXYD/bPd2F3m0f7SaO8BL4RPGa16ztbkIVq3a IUmFvpsmyYl+WaxJ2AFQhkQIkNe8bNY4eMsibn6j3JILgZF4AtjEW4jQXBOfEowp5Iz0 Ip6uuvCxBpCUbJgDp90wigZI+M3YZPWe9roJC/AQegHn4hSOMQ/4Ft58p8MtMAQYPHAM zaiQc9OdW1LMCH9HApVfAoyoWwIX+5TyEti8BWWLW4oY9Zh6bUgSBZFurbtizMAeTwP4 Hk115JtIEypdEGIWGqxpM8qdvYs14COIX8PUF05loOima9XqR+BwnZ3hPpBNkHdsFPHH 5q6Q== X-Gm-Message-State: ALoCoQnNvkDcdUQrpG7V1m3ksxjrun9ikxPSqCAQkfI4SFhyZT67vBVswOrPX9P+uogB+uXH7V0u X-Received: by 10.180.90.233 with SMTP id bz9mr18576377wib.42.1404490175120; Fri, 04 Jul 2014 09:09:35 -0700 (PDT) Received: from localhost.localdomain ([46.218.123.34]) by mx.google.com with ESMTPSA id bx2sm69840593wjb.47.2014.07.04.09.09.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Jul 2014 09:09:34 -0700 (PDT) From: Benoit Cousson To: broonie@kernel.org, lgirdwood@gmail.com, lars@metafoo.de Date: Fri, 4 Jul 2014 18:07:55 +0200 Message-Id: <1404490075-24997-6-git-send-email-bcousson@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1404490075-24997-1-git-send-email-bcousson@baylibre.com> References: <1404490075-24997-1-git-send-email-bcousson@baylibre.com> Cc: misael.lopez@ti.com, alsa-devel@alsa-project.org, Benoit Cousson Subject: [alsa-devel] [PATCH v5 5/5] ASoC: pcm: Add soc_dai_hw_params helper 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 Add a function helper to factorize the hw_params code. Suggested by Lars-Peter Clausen Signed-off-by: Benoit Cousson --- include/sound/soc.h | 4 ++++ sound/soc/soc-dapm.c | 28 ++++++++-------------------- sound/soc/soc-pcm.c | 43 ++++++++++++++++++++++++------------------- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/include/sound/soc.h b/include/sound/soc.h index f2142cf..98555f8 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -436,6 +436,10 @@ int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, int snd_soc_platform_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_platform *platform); +int soc_dai_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai); + /* Jack reporting */ int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, struct snd_soc_jack *jack); diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 5c63c3b..9a047f3 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3214,27 +3214,15 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, switch (event) { case SND_SOC_DAPM_PRE_PMU: - if (source->driver->ops && source->driver->ops->hw_params) { - substream.stream = SNDRV_PCM_STREAM_CAPTURE; - ret = source->driver->ops->hw_params(&substream, - params, source); - if (ret != 0) { - dev_err(source->dev, - "ASoC: hw_params() failed: %d\n", ret); - goto out; - } - } + substream.stream = SNDRV_PCM_STREAM_CAPTURE; + ret = soc_dai_hw_params(&substream, params, source); + if (ret < 0) + goto out; - if (sink->driver->ops && sink->driver->ops->hw_params) { - substream.stream = SNDRV_PCM_STREAM_PLAYBACK; - ret = sink->driver->ops->hw_params(&substream, params, - sink); - if (ret != 0) { - dev_err(sink->dev, - "ASoC: hw_params() failed: %d\n", ret); - goto out; - } - } + substream.stream = SNDRV_PCM_STREAM_PLAYBACK; + ret = soc_dai_hw_params(&substream, params, sink); + if (ret < 0) + goto out; break; case SND_SOC_DAPM_POST_PMU: diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 1e13dc3..bf0a1208 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -789,6 +789,24 @@ static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params, interval->max = channels; } +int soc_dai_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + int ret; + + if (dai->driver->ops && dai->driver->ops->hw_params) { + ret = dai->driver->ops->hw_params(substream, params, dai); + if (ret < 0) { + dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n", + dai->name, ret); + return ret; + } + } + + return 0; +} + /* * Called by ALSA when the hardware params are set by application. This * function can also be called multiple times and can allocate buffers @@ -832,17 +850,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, soc_pcm_codec_params_fixup(&codec_params, codec_dai->rx_mask); - if (codec_dai->driver->ops && - codec_dai->driver->ops->hw_params) { - ret = codec_dai->driver->ops->hw_params(substream, - &codec_params, codec_dai); - if (ret < 0) { - dev_err(codec_dai->dev, - "ASoC: can't set %s hw params: %d\n", - codec_dai->name, ret); - goto codec_err; - } - } + ret = soc_dai_hw_params(substream, &codec_params, codec_dai); + if(ret < 0) + goto codec_err; codec_dai->rate = params_rate(&codec_params); codec_dai->channels = params_channels(&codec_params); @@ -850,14 +860,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, params_format(&codec_params)); } - if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_params) { - ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai); - if (ret < 0) { - dev_err(cpu_dai->dev, "ASoC: %s hw params failed: %d\n", - cpu_dai->name, ret); - goto interface_err; - } - } + ret = soc_dai_hw_params(substream, params, cpu_dai); + if (ret < 0) + goto interface_err; if (platform->driver->ops && platform->driver->ops->hw_params) { ret = platform->driver->ops->hw_params(substream, params);