Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1682257pxb; Wed, 9 Feb 2022 02:04:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAf9ikpNzFLhkzLVi+YyaQBv597wGkP4ntYWmr7N9sbwYmUfJc27EHVa9GYTDa+jVwJSc1 X-Received: by 2002:a63:2a53:: with SMTP id q80mr1306015pgq.143.1644401068157; Wed, 09 Feb 2022 02:04:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644401068; cv=none; d=google.com; s=arc-20160816; b=RuRV/mWt51ytqCCmG82VY8jLaQ4j0i7yaC/nEUFmj8ZA+1dAG2fP7D8+er4FepJiLg LYZoL+UfzLXINWyOWcKbjIo19sfW1oJD0QIr+z8uQc/e86G9K1HpXzO+l3drgZWLtQqR ufcrQVLdetc6eYjmTN1ud6N9oS6H3H64GjraML4vLziR3EGbplcUe6HAX7fRjU33IbKJ BCyjs4oh8fUHTkP651UAH3xX1rc6vL+NCnsW0w4C5saSLBRvg8u43J+P7EBtPSLJmM+B 93W1X5ar+8c3Gv1Eka/sAY2wsnAY2/ygjQA1WJmeVy/VVYB97xNEuGtZ8jcbULLa3cQl /Zew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UieykIv+boSp5OusCIrL/bEVeBxzSiS/okrTirY3d20=; b=hQOBm3NnPteU/L0RMZx/8IDqGTdgTw441DvadBPmB0itcZseMpVZjmPoB+Q6UmDYDw JBbYTfa/y4BaJX/OJFxH8J92ijCy1bfM1L9IidknxVQ5unAoDEob0QZyubI0cwtzwOD6 H0rhq0nmpEgYU9+Bj78vlEo0MrGWais/NY5Of8C3YoNp+7xWifUPfOTNFVedtwfWIM5Y 2FJnzsFbVOeDazR70evgG9ctjIY8XBO3ZVy86RcBzThQvsA5Z1VYEFKfeRc1JetqqWW1 BK4xDOBF9JbsDrGu89Jjr5mPbEdfCc0ewxKVN2p0ETWnBhrHLy+qMmGGoXbduLhK12YT hGKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="m1Eb7/Nr"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o20si14733732pgv.148.2022.02.09.02.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 02:04:28 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="m1Eb7/Nr"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02329E07FD8E; Wed, 9 Feb 2022 01:13:26 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389333AbiBGLsE (ORCPT + 99 others); Mon, 7 Feb 2022 06:48:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386466AbiBGLel (ORCPT ); Mon, 7 Feb 2022 06:34:41 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D79ECC043188; Mon, 7 Feb 2022 03:34:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 83428B8102E; Mon, 7 Feb 2022 11:34:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DF56C004E1; Mon, 7 Feb 2022 11:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233678; bh=fQ6HmfmTWZIJTOD7EvLAW2lH/Y8C1gMM3DzkQZuDHbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m1Eb7/Nr8lZkZDw6JN1b+uS7apohpv2bZaC8i7YRlGS98pPkXkG75RnGkmF218Dke NgAcoE6GNx3izqk6I7+232bfpU3mHrY1sSJjcaZlSg7iKBdwf2keDZfRkwKzXMhf2h DN+o+OZGBk60zDqTyilxtoCxUik/5wQ7CDcFX+MU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Devarsh Thakkar , Robert Hancock , Mark Brown Subject: [PATCH 5.16 085/126] ASoC: xilinx: xlnx_formatter_pcm: Make buffer bytes multiple of period bytes Date: Mon, 7 Feb 2022 12:06:56 +0100 Message-Id: <20220207103807.036853878@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robert Hancock commit e958b5884725dac86d36c1e7afe5a55f31feb0b2 upstream. This patch is based on one in the Xilinx kernel tree, "ASoc: xlnx: Make buffer bytes multiple of period bytes" by Devarsh Thakkar. The same issue exists in the mainline version of the driver. The original patch description is as follows: "The Xilinx Audio Formatter IP has a constraint on period bytes to be multiple of 64. This leads to driver changing the period size to suitable frames such that period bytes are multiple of 64. Now since period bytes and period size are updated but not the buffer bytes, this may make the buffer bytes unaligned and not multiple of period bytes. When this happens we hear popping noise as while DMA is being done the buffer bytes are not enough to complete DMA access for last period of frame within the application buffer boundary. To avoid this, align buffer bytes too as multiple of 64, and set another constraint to always enforce number of periods as integer. Now since, there is already a rule in alsa core to enforce Buffer size = Number of Periods * Period Size this automatically aligns buffer bytes as multiple of period bytes." Fixes: 6f6c3c36f091 ("ASoC: xlnx: add pcm formatter platform driver") Cc: Devarsh Thakkar Signed-off-by: Robert Hancock Link: https://lore.kernel.org/r/20220107214711.1100162-2-robert.hancock@calian.com Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- sound/soc/xilinx/xlnx_formatter_pcm.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) --- a/sound/soc/xilinx/xlnx_formatter_pcm.c +++ b/sound/soc/xilinx/xlnx_formatter_pcm.c @@ -37,6 +37,7 @@ #define XLNX_AUD_XFER_COUNT 0x28 #define XLNX_AUD_CH_STS_START 0x2C #define XLNX_BYTES_PER_CH 0x44 +#define XLNX_AUD_ALIGN_BYTES 64 #define AUD_STS_IOC_IRQ_MASK BIT(31) #define AUD_STS_CH_STS_MASK BIT(29) @@ -368,12 +369,32 @@ static int xlnx_formatter_pcm_open(struc snd_soc_set_runtime_hwparams(substream, &xlnx_pcm_hardware); runtime->private_data = stream_data; - /* Resize the period size divisible by 64 */ + /* Resize the period bytes as divisible by 64 */ err = snd_pcm_hw_constraint_step(runtime, 0, - SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64); + SNDRV_PCM_HW_PARAM_PERIOD_BYTES, + XLNX_AUD_ALIGN_BYTES); if (err) { dev_err(component->dev, - "unable to set constraint on period bytes\n"); + "Unable to set constraint on period bytes\n"); + return err; + } + + /* Resize the buffer bytes as divisible by 64 */ + err = snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_BUFFER_BYTES, + XLNX_AUD_ALIGN_BYTES); + if (err) { + dev_err(component->dev, + "Unable to set constraint on buffer bytes\n"); + return err; + } + + /* Set periods as integer multiple */ + err = snd_pcm_hw_constraint_integer(runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + if (err < 0) { + dev_err(component->dev, + "Unable to set constraint on periods to be integer\n"); return err; }