Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1640984ybh; Mon, 20 Jul 2020 03:37:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP2Ydqq1nuACqhk46W5Iyqof0+Hf+L1gTSGZOzc6LDZdw1LDi2TYDKMAWJBJrCoBc73Va8 X-Received: by 2002:a17:906:e215:: with SMTP id gf21mr19408335ejb.310.1595241429517; Mon, 20 Jul 2020 03:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595241429; cv=none; d=google.com; s=arc-20160816; b=PadkK6yNQSn3qi8MUGx2pyeK1P7/uRDtub8GJM0LpKpFEgjNZnBEXm6DdF4EMMY45A XqHrI6cgq2fnRqfIMC1bZ0sdB/bnT57GVv60K7bHN15ko7v7Rj7dW4XF12mW4EQzwMx7 R0XPu1UMgIaNQObjgw4lEiAxRd3c6tyDZvvnh6jXtNiToH9wMIxLpRwlSXjFV3qvnNck aFZHnkpeufXbuFfrX09RHuOc04Jl810/P9LmuThX6MUSZ3md4gK7SgxXUzjtJGkQrE23 xp9qw0Ge+vgNiGp6G0uqEpta0xWTuvpXRksOeZvnNkc8JHP9LeN1pnr70pXVeX0tZQ2Q gYCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=VKpYBbrlnZWFZ3b9/7gPTVvr7uUXN2uw4/yc1h13XyM=; b=ruVE9tTVU40tJ2p58o2rTZDN3c3T5ynNmjJWZ5fkdFMVC6Vh40sCRKNL3gDjAl6GDZ Q6hOX6Lk//FaYgzg8qWoBVcabzXwAMTG2Hz2d8Xpm6AvmaDTD3LHkcM3FAEwJquXhajJ EnkUDgG9j66fG+XWvJfuQCFpvt+MKe2CQo1aDK1SUBwKJhBvsYy1p6AvXAtmNlraHZ3Z jyDOVkk7LNmIjtqnkDrp0YHYIKwnnr3ketr0x/SmN/D5Sm1J6TgH6CKYVFE9YpZnwrCU 8hOJQrLcxKikkuWDbgYlmUaPWKQNQmLOHaogCtYbxRKqREIFRfMYlDnNFip20Po/rtJB broQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Xw1t7clZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca5si10272989edb.511.2020.07.20.03.36.46; Mon, 20 Jul 2020 03:37:09 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=Xw1t7clZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728426AbgGTKe0 (ORCPT + 99 others); Mon, 20 Jul 2020 06:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728001AbgGTKeY (ORCPT ); Mon, 20 Jul 2020 06:34:24 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC98C061794 for ; Mon, 20 Jul 2020 03:34:22 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id p7so7108660qvl.4 for ; Mon, 20 Jul 2020 03:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VKpYBbrlnZWFZ3b9/7gPTVvr7uUXN2uw4/yc1h13XyM=; b=Xw1t7clZzNAezWxkwn6uMU0INMdckgeJj/r5KWBOP378438MNB0l3z/9VRnhE1E2qq tzaKFj3rmwyD2Dwft0ESb1tjUlGoovmduHcJ7jGDN9fkY3X16C+hN7+RLDZfc+U0J3rM NRcFsn8ALuGmUfT8cYHONuBWuepXrWm08QgmHEouegAHcD6fBjt9YVpUxT4Xo1QoU0Up 0m58/28f30BkP/vYkU8yKlITL5F0hl5xLUmGofmKs8boxHsL79OMmW7VPvOEzddgO+DV FyIcM86Z/mI1/iMd7f8YtgiF1TMy0AWxj5Mbb/YW0hDh1F6cOjktTPPke8SzVaG3tL3x 43nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VKpYBbrlnZWFZ3b9/7gPTVvr7uUXN2uw4/yc1h13XyM=; b=LBJ9XRH7ik6/kH7pVwOdsDxHEipEu+GBPLl9B+q7UXZCTdfeEnlKJ+vNzMtslu8N79 QIApLPGYxUpW1v+ZdjtNWvDq7CAPbZE6kEdqH5KmblS3S+iwZ3yFQFr53EZbITwFwGFU 21JBthcirv886EThJLxehWyZPsVNGE7iWaazpgOo3xV6QXDKUmUHIxOaxPzvLED9/WC8 5jLEp7p4knEl390xqFP3wnSU4ZXduEqOmrVpazxqMLpnfDTg1J1n/0XEss3TivK6rN8I hQqqgFM9maH9zoxU56G8rp3SQ9iWxwVcCUHXk72V5iyq8oNXhC6AmKzQ1NGFxhIZuKUz q9dA== X-Gm-Message-State: AOAM533CZ+d4tn62Nq7S10PmsmG1Cgky+hcwGaV2M5ViIL28EiQZ+I4O v3D54YgoPCPgDylWfpuoYHpXUVOgHGcjn91R7To= X-Received: by 2002:a0c:eac1:: with SMTP id y1mr20806707qvp.32.1595241261541; Mon, 20 Jul 2020 03:34:21 -0700 (PDT) MIME-Version: 1.0 References: <20200716232000.GA27246@Asurada-Nvidia> <20200717103857.31877-1-arnaud.ferraris@collabora.com> <20200717103857.31877-2-arnaud.ferraris@collabora.com> In-Reply-To: <20200717103857.31877-2-arnaud.ferraris@collabora.com> From: Shengjiu Wang Date: Mon, 20 Jul 2020 18:34:10 +0800 Message-ID: Subject: Re: [PATCH v3 1/1] ASoC: fsl_asrc: make sure the input and output clocks are different To: Arnaud Ferraris Cc: Linux-ALSA , Timur Tabi , Nicolin Chen , Xiubo Li , Fabio Estevam , Liam Girdwood , Mark Brown , linux-kernel , kernel@collabora.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 17, 2020 at 6:40 PM Arnaud Ferraris wrote: > > The current clock selection algorithm might select the same clock for > both input and output when, for instance, the output sample rate is a > multiple of the input rate. > > In that case, both selectable clocks will be multiples of both the input > and output sample rates, and therefore the first of these clocks will be > selected for both input and output, leading to miscalculation of the > dividers for either the input or output side. > > Example: > Input uses clock A (512kHz) and has a sample rate of 8kHz > Output uses clock B (1024kHz) and has a sample rate of 16kHz > > In this case, the algorithm will select clock A for both input and > output: the input divider will therefore be calculated properly > (512 / 8 => 64), but the output divider's value will be only half > the expected value (512 / 16 => 32 instead of 1024 / 16 => 64). > (input divider, output divider) = (64, 32) for the same clock source (512kHz) looks no problem. could you explain more detail why (64, 32) can't work? > This patch makes sure it always selects distinct input and output > clocks. There should be no such constraint for this IP, do you have any evidence for we should use distinct input and output clocks? > > Signed-off-by: Arnaud Ferraris > --- > sound/soc/fsl/fsl_asrc.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c > index 02c81d2e34ad..de10c208d3c8 100644 > --- a/sound/soc/fsl/fsl_asrc.c > +++ b/sound/soc/fsl/fsl_asrc.c > @@ -608,8 +608,8 @@ static void fsl_asrc_select_clk(struct fsl_asrc_priv *asrc_priv, > { > struct fsl_asrc_pair_priv *pair_priv = pair->private; > struct asrc_config *config = pair_priv->config; > - int rate[2], select_clk[2]; /* Array size 2 means IN and OUT */ > - int clk_rate, clk_index; > + int rate[2], select_clk[2], clk_index[2]; /* Array size 2 means IN and OUT */ > + int clk_rate; > int i = 0, j = 0; > > rate[IN] = in_rate; > @@ -618,11 +618,15 @@ static void fsl_asrc_select_clk(struct fsl_asrc_priv *asrc_priv, > /* Select proper clock source for internal ratio mode */ > for (j = 0; j < 2; j++) { > for (i = 0; i < ASRC_CLK_MAP_LEN; i++) { > - clk_index = asrc_priv->clk_map[j][i]; > - clk_rate = clk_get_rate(asrc_priv->asrck_clk[clk_index]); > - /* Only match a perfect clock source with no remainder */ > + clk_index[j] = asrc_priv->clk_map[j][i]; > + clk_rate = clk_get_rate(asrc_priv->asrck_clk[clk_index[j]]); > + /* > + * Only match a perfect clock source with no remainder > + * and make sure the input & output clocks are different > + */ > if (clk_rate != 0 && (clk_rate / rate[j]) <= 1024 && > - (clk_rate % rate[j]) == 0) > + (clk_rate % rate[j]) == 0 && > + (j == 0 || clk_index[j] != clk_index[j - 1])) > break; > } > > -- > 2.27.0 >