Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1515690ybt; Thu, 2 Jul 2020 07:24:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfZpizD1J0rXsw3fPxx5f6LnQOgV+DJpoKoRbTJyiTp9IY/Bu6kw7G0NhlZ4Uvtf83nbA5 X-Received: by 2002:a05:6402:1ac4:: with SMTP id ba4mr33694717edb.60.1593699874590; Thu, 02 Jul 2020 07:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593699874; cv=none; d=google.com; s=arc-20160816; b=czC150eJ5Q1cgsPhJq8hMuzJTkSFf31quNnu+K3iR/g2c0bSYGr9pRL7i7NYNMYSic E2py09TP2OsQFk+fJvzw+qqqD8/1Fr06gyzTZsjZK61288YeWOIotAn9w6yqVVvWg4IL /zP+S4mMzAwfTDBDki1ojBskyw2lYpOdQQkDn9b0FE0YTxtzZp2knHpLj6fPa5CdrHW5 R/OQg1C+UIS8MYItFTogzIJ68ZJS/B+A/EDdVKeRIowxmKHa1TjaGBPcJzwr2cOl/iBT Vp5iaKoQKuSE7QO61soJR7MAkalelk5qBtk2kaWVPhjx4h9bg4WvIrjj58ExZ/df8jOh HhPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from; bh=DMTvYJSmzc1gK627Lofmzmyoqfyyeo4hxWqIS6TQzpA=; b=qd9Yx7zZR+Cq+qnUxtYtVeASh0uaDAFCNBETyhG34y9Quq1bUzd5PcE0ZpbyZ1zF7I T1Fs32IPNS1XN6+DfnI4/R3ZP6AYZ+OBcpsiwl5ABqn35mMtbwDSrfzXOOaOatNlOoiS CGIjXa38ss2P18j5qBf6dY+xlRIQorSI/1X+5JkurTWwr5u9CXRVPs6KQk4rxYuEZeRu nnC2JAkziq5FELynZIynqr5ie44gRrt7H4EywlXHzJy8tfOTuPeZb3DBvRzXAqAKyda+ 1r89DUwlxDKhQHaKC4evsVO8zPzG9bXuDo06UO3CPUkxUjoJ1EiD99y/ID1tR8IKCTA7 CQ9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d9si5714609ejz.107.2020.07.02.07.24.11; Thu, 02 Jul 2020 07:24:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729857AbgGBOXQ (ORCPT + 99 others); Thu, 2 Jul 2020 10:23:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729399AbgGBOXM (ORCPT ); Thu, 2 Jul 2020 10:23:12 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE67FC08C5C1; Thu, 2 Jul 2020 07:23:11 -0700 (PDT) Received: from xps.home (unknown [IPv6:2a01:e35:2fb5:1510:315a:ecf0:6250:a3ed]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: aferraris) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 34A3E2A5EC7; Thu, 2 Jul 2020 15:23:10 +0100 (BST) From: Arnaud Ferraris Cc: kernel@collabora.com, Arnaud Ferraris , Liam Girdwood , Mark Brown , Rob Herring , Timur Tabi , Nicolin Chen , Xiubo Li , Fabio Estevam , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH 4/4] ASoC: fsl_asrc: swap input and output clocks in capture mode Date: Thu, 2 Jul 2020 16:22:35 +0200 Message-Id: <20200702142235.235869-5-arnaud.ferraris@collabora.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200702142235.235869-1-arnaud.ferraris@collabora.com> References: <20200702142235.235869-1-arnaud.ferraris@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The input clock is the reference clock we need to convert the stream to, which therefore has to be the clock of the origin stream/device. When the stream is bi-directional and we want ASRC to act on both directions, we need to swap the input and output clocks between the playback and capture streams. As some of the clocks have different ID's depending on whether they are used as input or output, this requires adding a new function to find the output clock ID corresponding to a given input clock. Signed-off-by: Arnaud Ferraris --- sound/soc/fsl/fsl_asrc.c | 50 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index 65e7307a3df0..5aeab1fbcdd9 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -506,6 +506,50 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair, bool use_ideal_rate) return fsl_asrc_set_ideal_ratio(pair, inrate, outrate); } +/** + * Select the output clock corresponding to a given input clock (and vice-versa) + * + * If we want to setup a capture channel, the input and output clocks have to + * be swapped. + * However, even if most of the clocks have the same index when used as input + * or output, some of them (ESAI, SSI* and SPDIF) are different: + * - the TX output clock has the index of the corresponding RX input clock + * - the RX output clock has the index of the corresponding TX input clock + * + * This function makes sure that we use the proper clock index when swapping + * the input and output clocks. + */ +static enum asrc_outclk fsl_asrc_get_capture_clock(enum asrc_inclk inclk) +{ + enum asrc_outclk outclk; + + switch (inclk) { + case INCLK_ESAI_RX: + case INCLK_SSI1_RX: + case INCLK_SSI2_RX: + case INCLK_SPDIF_RX: + outclk = inclk + 0x8; + break; + case INCLK_SSI3_RX: + outclk = OUTCLK_SSI3_RX; + break; + case INCLK_ESAI_TX: + case INCLK_SSI1_TX: + case INCLK_SSI2_TX: + case INCLK_SPDIF_TX: + outclk = inclk - 0x8; + break; + case INCLK_SSI3_TX: + outclk = OUTCLK_SSI3_TX; + break; + default: + outclk = inclk; + break; + } + + return outclk; +} + /** * Start the assigned ASRC pair * @@ -604,15 +648,17 @@ static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream, config.pair = pair->index; config.channel_num = channels; - config.inclk = asrc->inclk; - config.outclk = asrc->outclk; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + config.inclk = asrc->inclk; + config.outclk = asrc->outclk; config.input_format = params_format(params); config.output_format = asrc->asrc_format; config.input_sample_rate = rate; config.output_sample_rate = asrc->asrc_rate; } else { + config.inclk = fsl_asrc_get_capture_clock(asrc->outclk); + config.outclk = fsl_asrc_get_capture_clock(asrc->inclk); config.input_format = asrc->asrc_format; config.output_format = params_format(params); config.input_sample_rate = asrc->asrc_rate; -- 2.27.0