Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1684724pxb; Wed, 9 Feb 2022 02:08:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxx9kTmlXhGY38Y1ahnNd1XfZrFhhaSt5d2vGAdHiuXBX67zd30FDmdHvX/wR3x1IqacQae X-Received: by 2002:a17:90a:d58b:: with SMTP id v11mr2604195pju.100.1644401285907; Wed, 09 Feb 2022 02:08:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644401285; cv=none; d=google.com; s=arc-20160816; b=LxfPwwWL3JvqBB8+yJFQsutzwhQYSLMx5J8+FWbbMDpx8ea9S0j+bnpHWhZRXBEbMa IvvuRbBwOuv2nHtR675ZlcX5LwU0ydkL/Kn9PLf/ryQQKhIT4lVIOvCXZVXEoIwY54cf tLq2r9WvuUt4R4dX5MNrnk8vojU8m8ttt85Cr4UMFY0MLugxh/JgRrsa+ziW4XfjqHPz 4kv3ydGQ2bj/QKCSJWxFwV4k++kbR6WpGhH3I/SdBgBPEqxizWob9fiXtBIP+jYARJjT eGQZekVHyQnHnfQtB3pQ0y02LiCL20qeR8Vun2u+l/ZHoHdRhTPHf/ov0QAtNK0f8Obg u3qA== 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=KqTVpDDfp+YonwtbX0AGBS8RuUrXM/H4W+PwNfmS3rY=; b=jaSAEr7cG/2+PbZJHBed8TzKPxD/DGcPtd7WhRbAopjHcpQ44b6l6q36t06bZGfK0V MmttWqnL9bCEwVuz0c1Mzv0KXHEXit8VRmM3l+I7+mQ7VqcTDWXgghMhYCjSZOsm0z22 2VQtLYBR7QUQynozMUDpmjYIG5USVEzgGSat6IqefMDoXjsEexwOgijYYdyBezwZAKoz oD5aM3BQtq5PzpTGd24s9mm7547euEvhr4dXOHPD/A/yEEegXebM0mQcKtPfoEgEdvx1 3ehr1ho7ii2JW6YzNbZYYNv2Qi97+l4QAZBqRGJ68piERMga/uFR+WyIWOMcV6Q3vJa7 tlaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q+Gaw+kn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si11966608pgm.621.2022.02.09.02.07.52; Wed, 09 Feb 2022 02:08:05 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q+Gaw+kn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385113AbiBGLbM (ORCPT + 99 others); Mon, 7 Feb 2022 06:31:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382679AbiBGLUj (ORCPT ); Mon, 7 Feb 2022 06:20:39 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A1BBC0401CC; Mon, 7 Feb 2022 03:20:17 -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 D944BB811AF; Mon, 7 Feb 2022 11:20:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22399C004E1; Mon, 7 Feb 2022 11:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232814; bh=Fglqxzgr+A1WzQ28mgY6xGCSQNbOtNgjhGgd95zp0VQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q+Gaw+knzEdXEtWhfiXl2h8diAfu1E/TsznmZQ0OKfLCpc0/t1XvbswS72hhI7hav So05/wYCkFo1DlwG66fEBqvpy+BCbzobFYDPWmF2RhMiAAeh4SM6sKEu9+DkwK4n+0 gW/FAK/AgUou8Bs3CtqB7XddnV2A0Bec8TkYf8N8= 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.4 33/44] ASoC: xilinx: xlnx_formatter_pcm: Make buffer bytes multiple of period bytes Date: Mon, 7 Feb 2022 12:06:49 +0100 Message-Id: <20220207103754.230959617@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103753.155627314@linuxfoundation.org> References: <20220207103753.155627314@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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) @@ -370,12 +371,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; }