From patchwork Thu Aug 13 14:12:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricard Wanderlof X-Patchwork-Id: 7008501 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5ECF4C05AC for ; Thu, 13 Aug 2015 14:13:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 72814206EA for ; Thu, 13 Aug 2015 14:13:43 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 2A278206DE for ; Thu, 13 Aug 2015 14:13:42 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id C0E93261A8B; Thu, 13 Aug 2015 16:13:40 +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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id AB0A4261A8B; Thu, 13 Aug 2015 16:13:31 +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 602C3261A96; Thu, 13 Aug 2015 16:13:30 +0200 (CEST) Received: from bes.se.axis.com (bes.se.axis.com [195.60.68.10]) by alsa0.perex.cz (Postfix) with ESMTP id 8A022261A5A for ; Thu, 13 Aug 2015 16:13:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bes.se.axis.com (Postfix) with ESMTP id 434C62E5BE; Thu, 13 Aug 2015 16:13:13 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bes.se.axis.com Received: from bes.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bes.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id KBWrSh2FWjm9; Thu, 13 Aug 2015 16:13:12 +0200 (CEST) Received: from boulder.se.axis.com (boulder.se.axis.com [10.0.2.104]) by bes.se.axis.com (Postfix) with ESMTP id 47EE42E0C9; Thu, 13 Aug 2015 16:12:57 +0200 (CEST) Received: from boulder.se.axis.com (localhost [127.0.0.1]) by postfix.imss71 (Postfix) with ESMTP id 2EAE213C0; Thu, 13 Aug 2015 16:12:57 +0200 (CEST) Received: from seth.se.axis.com (seth.se.axis.com [10.0.2.172]) by boulder.se.axis.com (Postfix) with ESMTP id 22862ECB; Thu, 13 Aug 2015 16:12:57 +0200 (CEST) Received: from xmail2.se.axis.com (xmail2.se.axis.com [10.0.5.74]) by seth.se.axis.com (Postfix) with ESMTP id 200A73E049; Thu, 13 Aug 2015 16:12:57 +0200 (CEST) Received: from lnxricardw1.se.axis.com (10.88.7.2) by xmail2.se.axis.com (10.0.5.74) with Microsoft SMTP Server (TLS) id 8.3.342.0; Thu, 13 Aug 2015 16:12:56 +0200 Date: Thu, 13 Aug 2015 16:12:56 +0200 From: Ricard Wanderlof X-X-Sender: ricardw@lnxricardw1.se.axis.com To: "alsa-devel@alsa-project.org" , Mark Brown , Liam Girdwood Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Subject: [alsa-devel] [PATCH] ASoc: Handle multiple codecs with split playback / capture 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP (Referring to this thread: http://mailman.alsa-project.org/pipermail/alsa-devel/2015-June/093214.html) This patch adds the capability to use multiple codecs on the same DAI link where one codec is used for playback and another one is used for capture. As noted in the thread, there might be more places where the new snd_soc_dai_stream_valid() function is needed, however, these two were sufficient for our use case (SSM2518 playback and ICS-43432 capture). Signed-off-by: Ricard Wanderlof --- sound/soc/soc-pcm.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 6b0136e..df1f261 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -35,6 +35,32 @@ #define DPCM_MAX_BE_USERS 8 /** + * snd_soc_dai_stream_valid() - check if a DAI supports the given stream + * + * @dai: The DAI to check for stream support + * @stream: The stream type (playback / capture) to check for + * + * Checks if the DAI in question supports the indicated stream type. + * Needed to skip over codecs when iterating over + * snd_soc_pcm_runtime->codec_dais in order to skip codecs that are playback- + * or capture-only, which would otherwise inhibit capture or playback, + * respectively, to the other codec in a multiple codec / common I2S bus + * environment. + */ +static bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int stream) +{ + struct snd_soc_pcm_stream *codec_stream; + + if (stream == SNDRV_PCM_STREAM_PLAYBACK) + codec_stream = &dai->driver->playback; + else + codec_stream = &dai->driver->capture; + + /* If the codec specifies any rate at all, it supports the stream. */ + return !!codec_stream->rates; +} + +/** * snd_soc_runtime_activate() - Increment active count for PCM runtime components * @rtd: ASoC PCM runtime that is activated * @stream: Direction of the PCM stream @@ -371,6 +397,12 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream) /* first calculate min/max only for CODECs in the DAI link */ for (i = 0; i < rtd->num_codecs; i++) { + + /* Skip codecs which don't support the current stream type. */ + if (!snd_soc_dai_stream_valid(rtd->codec_dais[i], + substream->stream)) + continue; + codec_dai_drv = rtd->codec_dais[i]->driver; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) codec_stream = &codec_dai_drv->playback; @@ -827,6 +859,10 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; struct snd_pcm_hw_params codec_params; + /* Skip codecs which don't support the current stream type. */ + if (!snd_soc_dai_stream_valid(codec_dai, substream->stream)) + continue; + /* copy params for each codec */ codec_params = *params;