Skip to contentSkip to conversation

ASoC: nau8821: new driver

PATCH In review Seven Lee 4 participants 6 messages Aug 9, 2021 – Aug 20, 2021

Subsystems (3)
lore
Share & tools
lore

Seven Lee

author
#0 lore raw

PATCH 1/1 ASoC: nau8821: new driver

Add driver for NAU88L21.

---
 .../devicetree/bindings/sound/nau8821.txt     |   55 +
 sound/soc/codecs/Kconfig                      |    5 +
 sound/soc/codecs/Makefile                     |    2 +
 sound/soc/codecs/nau8821.c                    | 1818 +++++++++++++++++
 sound/soc/codecs/nau8821.h                    |  533 +++++
 5 files changed, 2413 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/nau8821.txt
 create mode 100644 sound/soc/codecs/nau8821.c
 create mode 100644 sound/soc/codecs/nau8821.h
Documentation/devicetree/bindings/sound/nau8821.txt new file +55 -0
new file mode 100644
index 000000000000..6c3baf7a5f21
@@ -0,0 +1,55 @@
+Nuvoton NAU88L21 audio codec
+
+This device supports I2C only.
+
+Required properties:
+  - compatible : Must be "nuvoton,nau8821"
+
+  - reg : the I2C address of the device. This is either 0x1B (CSB=0) or 0x54 (CSB=1).
+
+Optional properties:
+  - nuvoton,jkdet-enable: Enable jack detection via JKDET pin.
+  - nuvoton,jkdet-pull-enable: Enable JKDET pin pull. If set - pin pull enabled,
+      otherwise pin in high impedance state.
+  - nuvoton,jkdet-pull-up: Pull-up JKDET pin. If set then JKDET pin is pull up, otherwise pull down.
+  - nuvoton,jkdet-polarity: JKDET pin polarity. 0 - active high, 1 - active low.
+
+  - nuvoton,vref-impedance: VREF Impedance selection
+      0 - Open
+      1 - 25 kOhm
+      2 - 125 kOhm
+      3 - 2.5 kOhm
+
+  - nuvoton,micbias-voltage: Micbias voltage level.
+      0 - VDDA
+      1 - VDDA
+      2 - VDDA * 1.1
+      3 - VDDA * 1.2
+      4 - VDDA * 1.3
+      5 - VDDA * 1.4
+      6 - VDDA * 1.53
+      7 - VDDA * 1.53
+
+  - nuvoton,jack-insert-debounce: number from 0 to 7 that sets debounce time to 2^(n+2) ms
+  - nuvoton,jack-eject-debounce: number from 0 to 7 that sets debounce time to 2^(n+2) ms
+
+  - nuvoton,dmic-clk-threshold: the ADC threshold of DMIC clock.
+
+
+Example:
+
+  headset: nau8821@1b {
+      compatible = "nuvoton,nau8821";
+      reg = <0x1b>;
+      interrupt-parent = <&gpio>;
+      interrupts = <23 IRQ_TYPE_LEVEL_LOW>;
+      nuvoton,jkdet-enable;
+      nuvoton,jkdet-pull-enable;
+      nuvoton,jkdet-pull-up;
+      nuvoton,jkdet-polarity = <GPIO_ACTIVE_LOW>;
+      nuvoton,vref-impedance = <2>;
+      nuvoton,micbias-voltage = <6>;
+      nuvoton,jack-insert-debounce = <7>;
+      nuvoton,jack-eject-debounce = <7>;
+      nuvoton,dmic-clk-threshold = 3072000;
+  };
sound/soc/codecs/Kconfig +5 -0
index fe5e558635ad..6757f30779ff 100644
@@ -136,6 +136,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_NAU8315
 	imply SND_SOC_NAU8540
 	imply SND_SOC_NAU8810
+        imply SND_SOC_NAU8821
 	imply SND_SOC_NAU8822
 	imply SND_SOC_NAU8824
 	imply SND_SOC_NAU8825
@@ -1904,6 +1905,10 @@ config SND_SOC_NAU8810
 	tristate "Nuvoton Technology Corporation NAU88C10 CODEC"
 	depends on I2C
 
+config SND_SOC_NAU8821
+        tristate "Nuvoton Technology Corporation NAU88L21 CODEC"
+        depends on I2C
+
 config SND_SOC_NAU8822
 	tristate "Nuvoton Technology Corporation NAU88C22 CODEC"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index 8dcea2c4604a..5cb0bbaba1a5 100644
@@ -141,6 +141,7 @@ snd-soc-mt6660-objs := mt6660.o
 snd-soc-nau8315-objs := nau8315.o
 snd-soc-nau8540-objs := nau8540.o
 snd-soc-nau8810-objs := nau8810.o
+snd-soc-nau8821-objs := nau8821.o
 snd-soc-nau8822-objs := nau8822.o
 snd-soc-nau8824-objs := nau8824.o
 snd-soc-nau8825-objs := nau8825.o
@@ -468,6 +469,7 @@ obj-$(CONFIG_SND_SOC_MT6660)	+= snd-soc-mt6660.o
 obj-$(CONFIG_SND_SOC_NAU8315)   += snd-soc-nau8315.o
 obj-$(CONFIG_SND_SOC_NAU8540)   += snd-soc-nau8540.o
 obj-$(CONFIG_SND_SOC_NAU8810)   += snd-soc-nau8810.o
+obj-$(CONFIG_SND_SOC_NAU8821)   += snd-soc-nau8821.o
 obj-$(CONFIG_SND_SOC_NAU8822)   += snd-soc-nau8822.o
 obj-$(CONFIG_SND_SOC_NAU8824)   += snd-soc-nau8824.o
 obj-$(CONFIG_SND_SOC_NAU8825)   += snd-soc-nau8825.o
sound/soc/codecs/nau8821.c new file +1818 -0

1,818 lines not on this page · raw message

sound/soc/codecs/nau8821.h new file +533 -0

533 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · Seven Lee

Add driver for NAU88L21.

---

...

Quoted 23 lines
sound/soc/codecs/nau8821.c new file +23 -0
+
+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;

sound/soc/codecs/nau8821.c line 454

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -0
+	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?

Quoted 20 lines
sound/soc/codecs/nau8821.c new file +20 -0
+
+	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;
+}
+

...

Quoted 5 lines
sound/soc/codecs/nau8821.c new file +5 -0
+
+static int nau8821_clock_check(struct nau8821 *nau8821,
+	int stream, int rate, int osr)
+{
+	int osrate = 0;

sound/soc/codecs/nau8821.c line 731

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -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.

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -0
+
+	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;
+}
+

...

#2 lore raw

Hi,

Quoted 37 lines · Amadeusz Sławiński
Quoted 4 lines · Seven Lee

Add driver for NAU88L21.

---

...

Quoted 29 lines
sound/soc/codecs/nau8821.c new file +29 -0
+
+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;
Quoted 9 lines
Quoted 4 lines

+    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.

Quoted 23 lines
Quoted 20 lines
sound/soc/codecs/nau8821.c new file +20 -0
+
+    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;
+}
+

...

Quoted 17 lines
Quoted 5 lines
sound/soc/codecs/nau8821.c new file +5 -0
+
+static int nau8821_clock_check(struct nau8821 *nau8821,
+    int stream, int rate, int osr)
+{
+    int osrate = 0;

sound/soc/codecs/nau8821.c line 731

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -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.

Quoted 12 lines
Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -0
+
+    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;
+}
+

...

#3 lore raw
Quoted 92 lines · John Hsu

Hi,

Quoted 37 lines · Amadeusz Sławiński
Quoted 4 lines · Seven Lee

Add driver for NAU88L21.

---

...

Quoted 29 lines
sound/soc/codecs/nau8821.c new file +29 -0
+
+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;
Quoted 9 lines
Quoted 4 lines

+    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.

Quoted 23 lines
Quoted 20 lines
sound/soc/codecs/nau8821.c new file +20 -0
+
+    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;
+}
+

...

Quoted 17 lines
Quoted 5 lines
sound/soc/codecs/nau8821.c new file +5 -0
+
+static int nau8821_clock_check(struct nau8821 *nau8821,
+    int stream, int rate, int osr)
+{
+    int osrate = 0;

sound/soc/codecs/nau8821.c line 731

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -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.

Quoted 5 lines

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.

Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -0
+
+    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;
+}
+

...

#4 lore raw
In reply to Amadeusz Sławiński

Amadeusz Sławiński 於 2021/8/9 下午 06:44 寫道:

Quoted 37 lines · Seven Lee
Quoted 4 lines

Add driver for NAU88L21.

---

...

Quoted 29 lines
sound/soc/codecs/nau8821.c new file +29 -0
+
+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;
Quoted 8 lines
Quoted 4 lines

+    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.

Quoted 24 lines
Quoted 21 lines
sound/soc/codecs/nau8821.c new file +20 -0
+
+    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;
+}
+

...

Quoted 16 lines
Quoted 5 lines
sound/soc/codecs/nau8821.c new file +5 -0
+
+static int nau8821_clock_check(struct nau8821 *nau8821,
+    int stream, int rate, int osr)
+{
+    int osrate = 0;

sound/soc/codecs/nau8821.c line 731

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -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.

Quoted 13 lines
Quoted 11 lines
sound/soc/codecs/nau8821.c new file +10 -0
+
+    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;
+}
+

...

#5 lore raw

PATCH 1/1 ASoC: nau8821: new driver

In reply to Amadeusz Sławiński

Amadeusz Sławiński 於 2021/8/9 下午 06:44 寫道:

Quoted 37 lines · Seven Lee
Quoted 4 lines

Add driver for NAU88L21.

---

...

Quoted 29 lines
sound/soc/codecs/nau8821.c new file +29 -0
+
+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;
Quoted 8 lines
Quoted 4 lines

+    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.

Quoted 24 lines
Quoted 21 lines
sound/soc/codecs/nau8821.c new file +20 -0
+
+    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;
+}
+

...

Quoted 16 lines
Quoted 5 lines
sound/soc/codecs/nau8821.c new file +5 -0
+
+static int nau8821_clock_check(struct nau8821 *nau8821,
+    int stream, int rate, int osr)
+{
+    int osrate = 0;

sound/soc/codecs/nau8821.c line 731

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -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.

Quoted 13 lines
Quoted 11 lines
sound/soc/codecs/nau8821.c new file +10 -0
+
+    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;
+}
+

...