Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4199268ybg; Fri, 25 Oct 2019 15:00:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuOo/CkfCjRHuyNLcW74CPVbY3ODY8+VJz71ryHzg5c8Sssjk/UDojyjI50aDFB/QfPHXc X-Received: by 2002:a50:b6e1:: with SMTP id f30mr6490656ede.212.1572040839773; Fri, 25 Oct 2019 15:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572040839; cv=none; d=google.com; s=arc-20160816; b=bWRBcGzic0m1rgbHykNoAgsCy5PRg5lNureEnt4uywNP68cijhjulFau3h8xkHEHe2 Tuk24dT+252YFLwOnKqtqA49PdGmNGiCoRj/TFKgodR99VmSrIIp2iGejjHquv4FK2CM nQ01s6PlfikxiRFyObDp9f+55YGpd4MyaXu2N/mq9S92z3ip2adWisSt1ETR94qUebpE O34RkJ+MKpL5Aw+v81jWkccUAuoWEpApkNAK15JWI5Xnm0DHy08PgZ9q4swTRAQRcmmV oRotOGDDtYjJRramstXl9T85dfKxhejBvGO2liijrSQYVa5ElnvugUHyX0C6sVNRoqzc cTKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=eW3QcADxWiA9bB+f1V3Z1+dcU/1XE8CGZphcypGekbY=; b=JLWj9v+w/XFfX9ki4BSGR1COUcDqqkWUZB25oKViUMqkvlIJ9nDJc04uZKMFwhOfuq KzCQPbqQVn9pFBzKxfc6cIwhSHXTL1biGccXJh+1G7dTJwXUUY3R13O1CQqYxSjulb7i pIRvH1m2P8MbTtb0UG/+zopMq120js2B7U7EofbcmFg6o0demTGLO6i3wauSYVH0UWZd mDKwnLEzzrir+N+r51mdE5a2mMq8rSyMGnvnaW4EH69wcxXQxis3nj/Inw+Lc2zO9Nr1 OhqBDVaWPeIvX7RqUUNCnFxQiZH4ErUlW55BgLqLx4a4+oADnnc6XSoUbw805yAIkgkQ d8Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qwmWtewK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c14si2080827ejm.48.2019.10.25.15.00.16; Fri, 25 Oct 2019 15:00:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qwmWtewK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726375AbfJYV7l (ORCPT + 99 others); Fri, 25 Oct 2019 17:59:41 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37039 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfJYV7l (ORCPT ); Fri, 25 Oct 2019 17:59:41 -0400 Received: by mail-pf1-f194.google.com with SMTP id y5so2491332pfo.4 for ; Fri, 25 Oct 2019 14:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=eW3QcADxWiA9bB+f1V3Z1+dcU/1XE8CGZphcypGekbY=; b=qwmWtewKTdVLT5daUxPBZ5FzRpQl/egXLrBQ+UeZlpbEcHCiFqCaJklDEfi4dFeioG /XiO73dbDOzSSEE0e8De1pxiRwZ82JdWzsFQbae0oD79Pxhqy6EVKuu4BKTBEkvC1nMa m3nTmAaZ5lJOwxsHqbeokO4CRoYMoCgFlTZrR2iNULK3dzXeUmsnDqhk1sIspgID48YJ jKHqlgxD3nXUuqVQk2uwhEI9NgoalG4q+9bExzO5fTaykJS13q4yv6FQ6bKvkosayM2c ySkyd6GIpHirJ0zV2dZlTAiKIXtdOi7lS9lY13KClqTq1nv1w3qqvyeAPyYB1sKvas75 WFMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=eW3QcADxWiA9bB+f1V3Z1+dcU/1XE8CGZphcypGekbY=; b=nag2HEZaFNXv/noJWxEVhCOww1vIszixzNLPCoWKeEmNkt7zaFYuQt5i6DGwhA7qAv +WdzbC3bGaUMY4DeszJLcvs0xvxFrKw2K+X90Sd4i1Do794R7AtZ85N2UMU21Yf0pnS9 ie3bxPSC1zb05X1+/y17LKYxOuBp0S4M0Ta+gkNUneAp91NEvMT1wtG0qEOzQLe3rZ39 qYjWd09/ca0VXTF38gtAmCzFewgBym2Ba4XAsGHBpHpf51DRRSj5mvIIujFh3M0EjBC4 NOURUCN2LhrBcL4j6ZguiX+l9DrzLiujb6MM0FdkG9wUHVKQhQlAFShg6kk5sfw2klb8 FyIg== X-Gm-Message-State: APjAAAX+bwC24ZO3JBOrE40OBdMbf3I4CiYXZzZSfHYtuT5HwwTqDXoJ EFaXQf/pVMKXu153yCjmaCk= X-Received: by 2002:a17:90a:d351:: with SMTP id i17mr6807596pjx.36.1572040779795; Fri, 25 Oct 2019 14:59:39 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id d5sm2815101pjw.31.2019.10.25.14.59.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Oct 2019 14:59:39 -0700 (PDT) Date: Fri, 25 Oct 2019 14:59:20 -0700 From: Nicolin Chen To: Shengjiu Wang Cc: timur@kernel.org, Xiubo.Lee@gmail.com, festevam@gmail.com, broonie@kernel.org, alsa-devel@alsa-project.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2] ASoC: fsl_asrc: refine the setting of internal clock divider Message-ID: <20191025215919.GB15101@Asurada-Nvidia.nvidia.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 25, 2019 at 03:13:22PM +0800, Shengjiu Wang wrote: > The output divider should align with the output sample > rate, if use ideal sample rate, there will be a lot of overload, > which would cause underrun. > > The maximum divider of asrc clock is 1024, but there is no > judgement for this limitaion in driver, which may cause the divider typo: "limitaion" => "limitation" > setting not correct. > > For non-ideal ratio mode, the clock rate should divide the sample > rate with no remainder, and the quotient should be less than 1024. > > Signed-off-by: Shengjiu Wang And some comments inline. Please add my ack once they are fixed: Acked-by: Nicolin Chen Thanks > diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c > index 0bf91a6f54b9..89cf333154c7 100644 > --- a/sound/soc/fsl/fsl_asrc.c > +++ b/sound/soc/fsl/fsl_asrc.c > @@ -259,8 +259,11 @@ static int fsl_asrc_set_ideal_ratio(struct fsl_asrc_pair *pair, > * It configures those ASRC registers according to a configuration instance > * of struct asrc_config which includes in/output sample rate, width, channel > * and clock settings. > + * > + * Note: > + * use_ideal_rate = true is need by some case which need higher performance. I feel we can have a detailed one here and drop those inline comments, e.g.: + * Note: + * The ideal ratio configuration can work with a flexible clock rate setting. + * Using IDEAL_RATIO_RATE gives a faster converting speed but overloads ASRC. + * For a regular audio playback, the clock rate should not be slower than an + * clock rate aligning with the output sample rate; For a use case requiring + * faster conversion, set use_ideal_rate to have the faster speed. > @@ -351,8 +355,10 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) > /* We only have output clock for ideal ratio mode */ > clk = asrc_priv->asrck_clk[clk_index[ideal ? OUT : IN]]; > > - div[IN] = clk_get_rate(clk) / inrate; > - if (div[IN] == 0) { > + clk_rate = clk_get_rate(clk); > + rem[IN] = do_div(clk_rate, inrate); > + div[IN] = (u32)clk_rate; > + if (div[IN] == 0 || (!ideal && (div[IN] > 1024 || rem[IN] != 0))) { Should have some comments to explain this like: /* * The divider range is [1, 1024], defined by the hardware. For non- * ideal ratio configuration, clock rate has to be strictly aligned * with the sample rate. For ideal ratio configuration, clock rates * only result in different converting speeds. So remainder does not * matter, as long as we keep the divider within its valid range. */ > pair_err("failed to support input sample rate %dHz by asrck_%x\n", > inrate, clk_index[ideal ? OUT : IN]); > return -EINVAL; And move the min() behind this if-condition with no more comments: + div[IN] = min_t(u32, 1024, div[IN]); > @@ -360,18 +366,29 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) > > clk = asrc_priv->asrck_clk[clk_index[OUT]]; > > - /* Use fixed output rate for Ideal Ratio mode (INCLK_NONE) */ > - if (ideal) > - div[OUT] = clk_get_rate(clk) / IDEAL_RATIO_RATE; > + /* > + * Output rate should be align with the out samplerate. If set too > + * high output rate, there will be lots of Overload. > + * But some case need higher performance, then we can use > + * IDEAL_RATIO_RATE specifically for such case. > + */ Can drop this since we have the detailed comments at the top. > + clk_rate = clk_get_rate(clk); > + if (ideal && use_ideal_rate) > + rem[OUT] = do_div(clk_rate, IDEAL_RATIO_RATE); > else > - div[OUT] = clk_get_rate(clk) / outrate; > + rem[OUT] = do_div(clk_rate, outrate); > + div[OUT] = clk_rate; > > - if (div[OUT] == 0) { And add before this if-condition: /* Output divider has the same limitation as the input one */ > + if (div[OUT] == 0 || (!ideal && (div[OUT] > 1024 || rem[OUT] != 0))) { > pair_err("failed to support output sample rate %dHz by asrck_%x\n", > outrate, clk_index[OUT]); > return -EINVAL; > } > > + /* Divider range is [1, 1024] */ Can drop this too. > + div[IN] = min_t(u32, 1024, div[IN]); > + div[OUT] = min_t(u32, 1024, div[OUT]);