linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shengjiu Wang <shengjiu.wang@gmail.com>
To: Nicolin Chen <nicoleotsuka@gmail.com>
Cc: Shengjiu Wang <shengjiu.wang@nxp.com>,
	Linux-ALSA <alsa-devel@alsa-project.org>,
	Timur Tabi <timur@kernel.org>, Xiubo Li <Xiubo.Lee@gmail.com>,
	linuxppc-dev@lists.ozlabs.org, Takashi Iwai <tiwai@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Fabio Estevam <festevam@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ASoC: fsl_asrc: Add an option to select internal ratio mode
Date: Tue, 30 Jun 2020 13:31:15 +0800	[thread overview]
Message-ID: <CAA+D8APOd2MxO08nnK9UE03bMj25fyMfMnF-neBzdyoykbjAKA@mail.gmail.com> (raw)
In-Reply-To: <20200629200813.GB27967@Asurada-Nvidia>

On Tue, Jun 30, 2020 at 4:09 AM Nicolin Chen <nicoleotsuka@gmail.com> 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 <shengjiu.wang@nxp.com>
> > ---
>
> > +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

  reply	other threads:[~2020-06-30  5:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-29 13:58 [PATCH] ASoC: fsl_asrc: Add an option to select internal ratio mode Shengjiu Wang
2020-06-29 20:08 ` Nicolin Chen
2020-06-30  5:31   ` Shengjiu Wang [this message]
2020-06-30 12:36 ` Fabio Estevam
2020-06-30 13:30   ` Shengjiu Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAA+D8APOd2MxO08nnK9UE03bMj25fyMfMnF-neBzdyoykbjAKA@mail.gmail.com \
    --to=shengjiu.wang@gmail.com \
    --cc=Xiubo.Lee@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=festevam@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=nicoleotsuka@gmail.com \
    --cc=shengjiu.wang@nxp.com \
    --cc=timur@kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).