Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1056911pxb; Tue, 8 Feb 2022 08:19:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJybduk7KPr1S2HBwvIvPtpi0WwGS+PN//9IlVEocFo+nooaefnVI60HYFimQ5oott00LjY4 X-Received: by 2002:aa7:8745:: with SMTP id g5mr5141518pfo.1.1644337184650; Tue, 08 Feb 2022 08:19:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644337184; cv=none; d=google.com; s=arc-20160816; b=d/f6nUJJ4vlIv37S4PU1d52aPblygIxUGZHEBM8LJ573OPlKTgqX9OJmgL0jRTUdcf RztUYS0Xkg30tQ5fEtYsSQ5InpW3hMU36PJPPoGeXZ0+u3h5EbR2jGJcVa7ZljWoCbX4 VJHF9sD/DAWyHVoZIufpF9gqIxfKe7ICZl6FLuO/cMFrys4tQxUU4jQN7ppDpY4JyJaz l5Qtk9l97LiI2+WC9EmidYlqYRGzdc3J8m0Rl69vqcdx7pnQQ4sW4PGEIhePGkHjOwed DPnCXnMwGtSK2SXBfXQtd7+4r5FngET6xAOSPLTQ4srh+dAk1kYKjL7F62v/4NKysPJ1 tWXA== 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=qsWmwJBZKRRXT7c3e1eAaNtgaARVFuEVxGJjZRNrY1V86ARKsNViaUldYJb4mZ9uhT GpRyuU8LWYysFSK3dvA/HoJfgk8TkFy+T50q0bnxMjmmQhGy7ZZtGm+Zm3feS3AiMvDB eNGf0cS6mXGXxIrEi0jocLIXG0ngzxcDjR9eOUdFwD7j5LI9Wz8uj9tuEv5ln50LNHR7 jkvRlgmxSPIjXjSFMGSl2cVBSxORAat72hGThiax++TdbSNYDVKl8lToUvsLGOh8F/hQ YRrZadG/n1krmwdVhaT/X7+nmcaQ0G6FGY9KqqalLW3IfS6H5H1ZpFYRoacKvd/SjGkE tE8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JjPnq30q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f131si13197557pgc.849.2022.02.08.08.19.30; Tue, 08 Feb 2022 08:19:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JjPnq30q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1384738AbiBGL3v (ORCPT + 99 others); Mon, 7 Feb 2022 06:29:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383502AbiBGLWq (ORCPT ); Mon, 7 Feb 2022 06:22:46 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 317FCC043181; Mon, 7 Feb 2022 03:22:46 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C851961380; Mon, 7 Feb 2022 11:22:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87F0BC004E1; Mon, 7 Feb 2022 11:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232965; bh=fQ6HmfmTWZIJTOD7EvLAW2lH/Y8C1gMM3DzkQZuDHbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JjPnq30qzdSm/XPVr1VECdL8S1zvh+/1iJhUtWxY0Qquq5eEk5r9InXGOptuMs2xg UzuI4YlyebEfTeqvMD3uQQCKN6yeKFSpPQHaaq6Iw0T0Ksa5Fj7NIMK0GT4AJUzqzk jLLu+ScPnyIZ4OTsudi4vEIOk6VnixUrTITxfnKk= 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.10 46/74] ASoC: xilinx: xlnx_formatter_pcm: Make buffer bytes multiple of period bytes Date: Mon, 7 Feb 2022 12:06:44 +0100 Message-Id: <20220207103758.733259813@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.232676988@linuxfoundation.org> References: <20220207103757.232676988@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) @@ -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; }