Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3309145ybt; Mon, 29 Jun 2020 22:34:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPpiDh2e/x5zJON9IAf5qjtnOrI7CF7/A//VuDWZdR4qSjvLJ2egM3Dvh9TYZK6UKDJC1H X-Received: by 2002:a17:906:1c4b:: with SMTP id l11mr16423576ejg.307.1593495279328; Mon, 29 Jun 2020 22:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593495279; cv=none; d=google.com; s=arc-20160816; b=lehM3WHHhV58uMjTdATse2mc0hym3ru/Rh1pkpAqyNjXI/Xpy+G+g4n20UrbOzBYRb GTFKd9MlY4kdEaFtRKR8544wOxB6bfrbnrhi17cRbxPfervZj8NtPO8XegfxZAXm4GOj S3Pt2K3py9Cbw4nnBwBFuRiA8+4MHNDISka2wkQM+rHNK/c7D29no1TFVWqIguWH7Dbx /iTSMm+fNuvADswapOfnwdsKQ3XAz3JF7i0VTY34MmKeQLflzds+cTRBBnWLGJ8Y/SmP Ah39a0bbYG1Ezc6FOEOq2+iuaxPIqyyqLZGchr2k8uSEIe+bGmAD6Jcp088o+kKCDV3y wJaA== 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=RQ4+/e636DjU53ZutFkneDCxV7N9AiA63WewmD4xQRo=; b=vfEnsdLXL4NKVu/036GzktOe+JrreDgEJ+D64Sk3smOcpsHFvNRH3cGkrboWZGyxNQ 1OXLTx40xoxlujS/NSc85GuRoMxHJt4s+Xac7dp/2LfYU5VoK2QT/Hj5f/fwQN1jl0tg 2NuehmV0MEta5oJbpnMLMGgFbCNfk8SbOPD4w52uPC4UzdbF8vk+aH0rPEFJlNzQqDCa YuM8pcOK5eJS4DjXeG4K8Yu1bBYS4qpBGTnotiYQ0TAfR5dGd4fZ4FTxs33oGapT8jgY TfSSAdTen7pBB90PWejoMEq7pPCXLm6BP2ojFOuUru1QXi8IyTPwfoV1bLqTiaP92PhQ ReGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="H/Y2LEm0"; 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 m15si1088410eje.623.2020.06.29.22.34.15; Mon, 29 Jun 2020 22:34:39 -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="H/Y2LEm0"; 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 S1729603AbgF3Fb2 (ORCPT + 99 others); Tue, 30 Jun 2020 01:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgF3Fb1 (ORCPT ); Tue, 30 Jun 2020 01:31:27 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90150C061755 for ; Mon, 29 Jun 2020 22:31:27 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id v19so14670500qtq.10 for ; Mon, 29 Jun 2020 22:31:27 -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=RQ4+/e636DjU53ZutFkneDCxV7N9AiA63WewmD4xQRo=; b=H/Y2LEm0lur0oZA8cMF+qOfMdmDEufwHt8gopg4rg6MJFdWZkdZjG5EJjRH3nfkJDF DKMJqCadNNnqvKBtaN3rHZkQVyKtfXSz4U90upgH1YbAExNl/mdq46fT9HMq7Wd9JQjY 0kx7V1ODrnNe93ASuiXATDjIk8RNPyGXqBDgrrEwUKHITq9bmkpjSfcpBWjJi6o7mR8L MFMgZGfxkogIeoUm2AsGug0PM1LeGfBhG4P9xC3agZ0WkGRyLxJiPRPKjl4nIW5pjQSM M4+K92DwUmXuiwAOKUFqO0Vf1wnCac1Gynjv5OLh30l+ftlAydyu9xSZj5WJGqxFcfXS o46g== 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=RQ4+/e636DjU53ZutFkneDCxV7N9AiA63WewmD4xQRo=; b=ZDdqQ+9Ufjg76IsZW35oiHSPae+U8YOHiObeE+W4/V+jt4Q3WsP0Hkc8PsGOFOkO7z Ptx8VA/CcPkEgMXhf/WWpdUylOo9AChTtEUHjuB1SMzcLrGNf1CFV+mqIyU/bjVFo0zm rH4CX9oGLs08HsNJkBvHeE5SdwToDuR1xRPrpbsfSGYSWfoIZ8GgKAw3s3/EPafN3Ae9 huiFAyKXj5KZbfsNoVNC6kUPcafc/sivaLOtYakbJuO+E9EwEppJ7fHXZjnHXYrfmN63 GtTS7gE/m0/HTFmMNK5Oshoune+YnNnQ3HiyU4Iyyh9w141ZkLrYZw4w+2x4Blc2y+JJ Jd7w== X-Gm-Message-State: AOAM533Ur/ppYCVG7vUqSgUFckkl1uBmBI+pLTH6XPQB6ON+vhQusbJ4 OIQyfFbtrf2lbgqjgl/PXXE2oGu5TvgJ6oBqkQU= X-Received: by 2002:ac8:33d7:: with SMTP id d23mr19287396qtb.204.1593495086854; Mon, 29 Jun 2020 22:31:26 -0700 (PDT) MIME-Version: 1.0 References: <1593439115-19282-1-git-send-email-shengjiu.wang@nxp.com> <20200629200813.GB27967@Asurada-Nvidia> In-Reply-To: <20200629200813.GB27967@Asurada-Nvidia> From: Shengjiu Wang Date: Tue, 30 Jun 2020 13:31:15 +0800 Message-ID: Subject: Re: [PATCH] ASoC: fsl_asrc: Add an option to select internal ratio mode To: Nicolin Chen Cc: Shengjiu Wang , Linux-ALSA , Timur Tabi , Xiubo Li , linuxppc-dev@lists.ozlabs.org, Takashi Iwai , Liam Girdwood , Mark Brown , Fabio Estevam , linux-kernel 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 Tue, Jun 30, 2020 at 4:09 AM Nicolin Chen wrote: > > On Mon, Jun 29, 2020 at 09:58:35PM +0800, Shengjiu Wang wrote: > > The ASRC not only supports ideal ratio mode, but also supports > > internal ratio mode. > > > > For internal rato mode, the rate of clock source should be divided > > with no remainder by sample rate, otherwise there is sound > > distortion. > > > > Add function fsl_asrc_select_clk() to find proper clock source for > > internal ratio mode, if the clock source is available then internal > > ratio mode will be selected. > > > > With change, the ideal ratio mode is not the only option for user. > > > > Signed-off-by: Shengjiu Wang > > --- > > > +static int fsl_asrc_select_clk(struct fsl_asrc_priv *asrc_priv, > > + struct fsl_asrc_pair *pair, > > + int in_rate, > > + int out_rate) > > +{ > > + 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 i = 0, j = 0; > > + bool clk_sel[2]; > > + > > + rate[0] = in_rate; > > + rate[1] = out_rate; > > + > > + /* 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 */ > > > + if (clk_rate != 0 && (clk_rate / rate[j]) <= 1024 && > > + (clk_rate % rate[j]) == 0) > > + break; > > + } > > + > > + if (i == ASRC_CLK_MAP_LEN) { > > + select_clk[j] = OUTCLK_ASRCK1_CLK; > > + clk_sel[j] = false; > > + } else { > > + select_clk[j] = i; > > + clk_sel[j] = true; > > + } > > + } > > + > > + /* Switch to ideal ratio mode if there is no proper clock source */ > > + if (!clk_sel[IN] || !clk_sel[OUT]) > > + select_clk[IN] = INCLK_NONE; > > Could get rid of clk_set: > > for (j) { > for (i) { > if (match) > break; > } > > clk[j] = i; > } > > if (clk[IN] == ASRC_CLK_MAP_LEN || clk[OUT] == ASRC_CLK_MAP_LEN) > > And it only overrides clk[IN] setting but leaving clk[OUT] to > to the searching result. This means that clk[OUT] may be using > a clock source other than OUTCLK_ASRCK1_CLK if sel[IN] happens > to be false while sel[OUT] happens to be true. Not sure if it > is intended...but I feel it would probably be safer to use the > previous settings: INCLK_NONE + OUTCLK_ASRCK1_CLK? ok, will update the patch. best regards wang shengjiu