Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>
To: John Hsu <supercraig0719@gmail.com>, Seven Lee <wtli@nuvoton.com>,
	broonie@kernel.org
Cc: alsa-devel@alsa-project.org, scott6986@gmail.com,
	KCHSU0@nuvoton.com, lgirdwood@gmail.com, YHCHuang@nuvoton.com,
	CTLIN0@nuvoton.com, dardar923@gmail.com
Subject: Re: [PATCH] ASoC: nau8821: new driver
Date: Wed, 18 Aug 2021 09:23:51 +0200	[thread overview]
Message-ID: <cda3fd5c-a30f-ae26-c7a5-9c1dd520b913@linux.intel.com> (raw)
In-Reply-To: <fde36a45-849b-59f8-f2f4-282ddb161262@gmail.com>

On 8/18/2021 5:30 AM, John Hsu wrote:
> Hi,
> 
> On 8/9/2021 6:44 PM, Amadeusz Sławiński wrote:
>> On 8/9/2021 12:10 PM, Seven Lee wrote:
>>> Add driver for NAU88L21.
>>>
>>> Signed-off-by: Seven Lee <wtli@nuvoton.com>
>>> ---
>>
>> ...
>>
>>> +
>>> +static int dmic_clock_control(struct snd_soc_dapm_widget *w,
>>> +        struct snd_kcontrol *k, int  event)
>>> +{
>>> +    struct snd_soc_component *component =
>>> +        snd_soc_dapm_to_component(w->dapm);
>>> +    struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
>>> +    int i, speed_selection, clk_adc_src, clk_adc;
>>> +    unsigned int clk_divider_r03;
>>> +
>>> +    /* The DMIC clock is gotten from adc clock divided by
>>> +     * CLK_DMIC_SRC (1, 2, 4, 8). The clock has to be equal or
>>> +     * less than nau8821->dmic_clk_threshold.
>>> +     */
>>> +    regmap_read(nau8821->regmap, NAU8821_R03_CLK_DIVIDER,
>>> +        &clk_divider_r03);
>>> +    clk_adc_src = (clk_divider_r03 & NAU8821_CLK_ADC_SRC_MASK)
>>> +        >> NAU8821_CLK_ADC_SRC_SFT;
>>> +
>>> +    switch (clk_adc_src) {
>>> +    case 0:
>>> +        clk_adc = nau8821->fs * 256;
>>> +        break;
>>> +    case 1:
>>> +        clk_adc = (nau8821->fs * 256) >> 1;
>>> +        break;
>>> +    case 2:
>>> +        clk_adc = (nau8821->fs * 256) >> 2;
>>> +        break;
>>> +    case 3:
>>> +        clk_adc = (nau8821->fs * 256) >> 3;
>>> +        break;
>>> +    }
>>
>> Just do:
>> clk_adc = (nau8821->fs * 256) >> clk_adc_src;
>> instead of whole switch?
>>
> 
> Yes, you are right. I will fix it.
>>> +
>>> +    for (i = 0 ; i < 4 ; i++) {
>>> +        if ((clk_adc >> dmic_speed_sel[i].param) <=
>>> +            nau8821->dmic_clk_threshold) {
>>> +            speed_selection = dmic_speed_sel[i].val;
>>> +            break;
>>> +        }
>>> +    }
>>> +
>>> +    dev_dbg(nau8821->dev,
>>> +        "clk_adc=%d, dmic_clk_threshold = %d, param=%d, val = %d\n",
>>> +        clk_adc, nau8821->dmic_clk_threshold,
>>> +        dmic_speed_sel[i].param, dmic_speed_sel[i].val);
>>> +    regmap_update_bits(nau8821->regmap, NAU8821_R13_DMIC_CTRL,
>>> +        NAU8821_DMIC_SRC_MASK,
>>> +        (speed_selection << NAU8821_DMIC_SRC_SFT));
>>> +
>>> +    return 0;
>>> +}
>>> +
>>
>> ...
>>
>>> +
>>> +static int nau8821_clock_check(struct nau8821 *nau8821,
>>> +    int stream, int rate, int osr)
>>> +{
>>> +    int osrate = 0;
>>> +
>>> +    if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
>>> +        if (osr >= ARRAY_SIZE(osr_dac_sel))
>>> +            return -EINVAL;
>>> +        osrate = osr_dac_sel[osr].osr;
>>> +    } else {
>>> +        if (osr >= ARRAY_SIZE(osr_adc_sel))
>>> +            return -EINVAL;
>>> +        osrate = osr_adc_sel[osr].osr;
>>> +    }
>> true and false cases seem to be the same here, you can remove the "if 
>> else" and just leave one of them.
>>
> 
> The OSR of DAC and ADC can be different. And the ratio corresponding
> to the bit is also different. They are two different tables for
> osr_dac_sel and osr_adc_sel. Then it should be noted that the OSR and
> Fs must be selected carefully so that the max frequency of CLK_ADC or
> CLK_DAC are less than or equal to 6.144MHz.

Right, I somehow did misread dac and adc, and thought that they are the 
same table.

>>> +
>>> +    if (!osrate || rate * osrate > CLK_DA_AD_MAX) {
>>> +        dev_err(nau8821->dev,
>>> +        "exceed the maximum frequency of CLK_ADC or CLK_DAC\n");
>>> +        return -EINVAL;
>>> +    }
>>> +
>>> +    return 0;
>>> +}
>>> +
>>
>> ...


  reply	other threads:[~2021-08-18  7:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09 10:10 [PATCH] ASoC: nau8821: new driver Seven Lee
2021-08-09 10:44 ` Amadeusz Sławiński
2021-08-17  5:58   ` Seven Lee
2021-08-18  3:19   ` Seven Lee
2021-08-18  3:30   ` John Hsu
2021-08-18  7:23     ` Amadeusz Sławiński [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-10-01 10:31 Seven Lee
2021-10-02  1:37 ` Mark Brown

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=cda3fd5c-a30f-ae26-c7a5-9c1dd520b913@linux.intel.com \
    --to=amadeuszx.slawinski@linux.intel.com \
    --cc=CTLIN0@nuvoton.com \
    --cc=KCHSU0@nuvoton.com \
    --cc=YHCHuang@nuvoton.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=dardar923@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=scott6986@gmail.com \
    --cc=supercraig0719@gmail.com \
    --cc=wtli@nuvoton.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