From patchwork Tue Mar 24 09:08:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Flax X-Patchwork-Id: 11454901 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4A9C1392 for ; Tue, 24 Mar 2020 09:11:28 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B1D5208CA for ; Tue, 24 Mar 2020 09:11:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="S4zHP11M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B1D5208CA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=flatmax.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 92C1815F8; Tue, 24 Mar 2020 10:10:42 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 92C1815F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1585041086; bh=Qn845Yl6tTZk1kz7s+fGTqMh6JS6MnZxcGBAy8fC3Yw=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=S4zHP11M/cyoJmu2EvZoiMdIvEevON+Jpy167yTUy72S+9yND5Qacnmrx1Us66NMp +dYu+icBTU/ROerJjfSuV36RPJ+lsFbxgE7SLqmlnwEmkvJyHTzH7yKJORNH5W6GYv xGQpZG9bD1oK+k7m1DI8Z7F1FZIrsSm87Ev4Wu2A= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id F2995F801F8; Tue, 24 Mar 2020 10:10:41 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 44B0BF800B9; Tue, 24 Mar 2020 10:10:40 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_SOFTFAIL,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from pecan2.exetel.com.au (pecan2-mail.exetel.com.au [220.233.0.71]) by alsa1.perex.cz (Postfix) with ESMTP id 6A062F800B9 for ; Tue, 24 Mar 2020 10:10:32 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6A062F800B9 Received: from 41.68.233.220.static.exetel.com.au ([220.233.68.41] helo=localhost.localdomain) by pecan2.exetel.com.au with esmtp (Exim 4.91) (envelope-from ) id 1jGfZc-0000Zd-ME; Tue, 24 Mar 2020 20:10:12 +1100 From: Matt Flax To: Subject: [PATCH] ASoC: bcm2835-i2s: substream alignment now independent in hwparams Date: Tue, 24 Mar 2020 20:08:21 +1100 Message-Id: <20200324090823.20754-1-flatmax@flatmax.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Cc: Kate Stewart , alsa-devel@alsa-project.org, Florian Fainelli , linux-kernel@vger.kernel.org, Scott Branden , Liam Girdwood , linux-arm-kernel@lists.infradead.org, Ray Jui , YueHaibing , Takashi Iwai , Mark Brown , bcm-kernel-feedback-list@broadcom.com, Allison Randal , Greg Kroah-Hartman , Thomas Gleixner , Matt Flax , Nicolas Saenz Julienne , linux-rpi-kernel@lists.infradead.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" Substream sample alignment was being set in hwparams for both substreams at the same time. This became a problem when the Audio Injector isolated sound card needed to offset sample alignment for high sample rates. The latency difference between playback and capture occurs because of the digital isolation chip propagation time, particularly when the codec is master and the DAC return is twice delayed. This patch sets sample alignment registers based on the substream direction in hwparams. This gives the machine driver more control over sample alignment in the bcm2835 i2s driver. Signed-off-by: Matt Flax --- sound/soc/bcm/bcm2835-i2s.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c index e6a12e271b07..9db542699a13 100644 --- a/sound/soc/bcm/bcm2835-i2s.c +++ b/sound/soc/bcm/bcm2835-i2s.c @@ -493,11 +493,6 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - bcm2835_i2s_calc_channel_pos(&rx_ch1_pos, &rx_ch2_pos, - rx_mask, slot_width, data_delay, odd_slot_offset); - bcm2835_i2s_calc_channel_pos(&tx_ch1_pos, &tx_ch2_pos, - tx_mask, slot_width, data_delay, odd_slot_offset); - /* * Transmitting data immediately after frame start, eg * in left-justified or DSP mode A, only works stable @@ -508,19 +503,26 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, "Unstable slave config detected, L/R may be swapped"); /* - * Set format for both streams. - * We cannot set another frame length - * (and therefore word length) anyway, - * so the format will be the same. + * Set format on a per stream basis. + * The alignment format can be different depending on direction. */ - regmap_write(dev->i2s_regmap, BCM2835_I2S_RXC_A_REG, - format - | BCM2835_I2S_CH1_POS(rx_ch1_pos) - | BCM2835_I2S_CH2_POS(rx_ch2_pos)); - regmap_write(dev->i2s_regmap, BCM2835_I2S_TXC_A_REG, - format - | BCM2835_I2S_CH1_POS(tx_ch1_pos) - | BCM2835_I2S_CH2_POS(tx_ch2_pos)); + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + bcm2835_i2s_calc_channel_pos(&rx_ch1_pos, &rx_ch2_pos, + rx_mask, slot_width, data_delay, odd_slot_offset); + regmap_write(dev->i2s_regmap, BCM2835_I2S_RXC_A_REG, + format + | BCM2835_I2S_CH1_POS(rx_ch1_pos) + | BCM2835_I2S_CH2_POS(rx_ch2_pos)); + } + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + bcm2835_i2s_calc_channel_pos(&tx_ch1_pos, &tx_ch2_pos, + tx_mask, slot_width, data_delay, odd_slot_offset); + regmap_write(dev->i2s_regmap, BCM2835_I2S_TXC_A_REG, + format + | BCM2835_I2S_CH1_POS(tx_ch1_pos) + | BCM2835_I2S_CH2_POS(tx_ch2_pos)); + } /* Setup the I2S mode */