Skip to contentSkip to conversation

ASoC: nau8821: Add driver for Nuvoton codec NAU88L21

PATCH In review Seven Lee 6 participants 10 messages Aug 24, 2021 – Sep 16, 2021

Subsystems (3)
lore
Share & tools
lore

Seven Lee

author
#0 lore raw

PATCH 1/1 ASoC: nau8821: Add driver for Nuvoton codec NAU88L21

The driver is for codec NAU88L21 of Nuvoton Technology Corporation. The NAU88L21 is an ultra-low power high performance audio codec that supportsboth analog and digital audio functions.
In addition, DMIC function is added to calculate the clock threshold value by device properties.

---
 .../devicetree/bindings/sound/nau8821.txt     |   55 +
 sound/soc/codecs/Kconfig                      |    5 +
 sound/soc/codecs/Makefile                     |    2 +
 sound/soc/codecs/nau8821.c                    | 1804 +++++++++++++++++
 sound/soc/codecs/nau8821.h                    |  533 +++++
 5 files changed, 2399 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 82ee233a269d..11bcf17b5f91 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..55daf5fbc1b7 100644
@@ -142,6 +142,7 @@ snd-soc-nau8315-objs := nau8315.o
 snd-soc-nau8540-objs := nau8540.o
 snd-soc-nau8810-objs := nau8810.o
 snd-soc-nau8822-objs := nau8822.o
+snd-soc-nau8821-objs := nau8821.o
 snd-soc-nau8824-objs := nau8824.o
 snd-soc-nau8825-objs := nau8825.o
 snd-soc-hdmi-codec-objs := hdmi-codec.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 +1804 -0

1,804 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
Thank you for the patch! Perhaps something to improve:

Hi Seven,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on asoc/for-next]
[also build test WARNING on v5.14-rc7 next-20210823]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Seven-Lee/ASoC-nau8821-Add-driver-for-Nuvoton-codec-NAU88L21/20210824-121846
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: riscv-randconfig-r014-20210824 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project d26000e4cc2bc65e207a84fa26cb6e374d60aa12)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/429cd8c43255317cb7b67d614f90d3ddd58ef401
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Seven-Lee/ASoC-nau8821-Add-driver-for-Nuvoton-codec-NAU88L21/20210824-121846 git checkout 429cd8c43255317cb7b67d614f90d3ddd58ef401
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> sound/soc/codecs/nau8821.c:442:15: warning: variable 'speed_selection' is used uninitialized whenever 'for' loop exits because its condition is false [-Wsometimes-uninitialized]
           for (i = 0 ; i < 4 ; i++) {
                        ^~~~~
   sound/soc/codecs/nau8821.c:456:4: note: uninitialized use occurs here
                   (speed_selection << NAU8821_DMIC_SRC_SFT));
                    ^~~~~~~~~~~~~~~
   sound/soc/codecs/nau8821.c:442:15: note: remove the condition if it is always true
           for (i = 0 ; i < 4 ; i++) {
                        ^~~~~~
   sound/soc/codecs/nau8821.c:429:24: note: initialize the variable 'speed_selection' to silence this warning
           int i, speed_selection, clk_adc_src, clk_adc;
                                 ^
                                  = 0

1 warning generated.

vim +442 sound/soc/codecs/nau8821.c

418
419 static const struct snd_kcontrol_new nau8821_adc_ch0_dmic =
420 SOC_DAPM_SINGLE("Switch", NAU8821_R13_DMIC_CTRL,
421 NAU8821_DMIC_EN_SFT, 1, 0);
422
423 static int dmic_clock_control(struct snd_soc_dapm_widget *w,
424 struct snd_kcontrol *k, int event)
425 {
426 struct snd_soc_component *component =
427 snd_soc_dapm_to_component(w->dapm);
428 struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
429 int i, speed_selection, clk_adc_src, clk_adc;
430 unsigned int clk_divider_r03;
431
432 /* The DMIC clock is gotten from adc clock divided by
433 * CLK_DMIC_SRC (1, 2, 4, 8). The clock has to be equal or
434 * less than nau8821->dmic_clk_threshold.
435 */
436 regmap_read(nau8821->regmap, NAU8821_R03_CLK_DIVIDER,
437 &clk_divider_r03);
438 clk_adc_src = (clk_divider_r03 & NAU8821_CLK_ADC_SRC_MASK)
439 >> NAU8821_CLK_ADC_SRC_SFT;
440 clk_adc = (nau8821->fs * 256) >> clk_adc_src;
441

 > 442		for (i = 0 ; i < 4 ; i++) {

443 if ((clk_adc >> dmic_speed_sel[i].param) <=
444 nau8821->dmic_clk_threshold) {
445 speed_selection = dmic_speed_sel[i].val;
446 break;
447 }
448 }
449
450 dev_dbg(nau8821->dev,
451 "clk_adc=%d, dmic_clk_threshold = %d, param=%d, val = %d\n",
452 clk_adc, nau8821->dmic_clk_threshold,
453 dmic_speed_sel[i].param, dmic_speed_sel[i].val);
454 regmap_update_bits(nau8821->regmap, NAU8821_R13_DMIC_CTRL,
455 NAU8821_DMIC_SRC_MASK,
456 (speed_selection << NAU8821_DMIC_SRC_SFT));
457
458 return 0;
459 }
460

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

build bot
#2 lore raw
In reply to Seven Lee
CC: kbuild-all(a)lists.01.org In-Reply-To: <[email protected]> References: <[email protected]> TO: Seven Lee <[email protected]> TO…

CC: kbuild-all(a)lists.01.org
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Seven Lee <[email protected]>
TO: broonie(a)kernel.org
CC: alsa-devel(a)alsa-project.org
CC: scott6986(a)gmail.com
CC: Seven Lee <[email protected]>
CC: KCHSU0(a)nuvoton.com
CC: lgirdwood(a)gmail.com
CC: YHCHuang(a)nuvoton.com
CC: CTLIN0(a)nuvoton.com
CC: dardar923(a)gmail.com
CC: supercraig0719(a)gmail.com

Hi Seven,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on asoc/for-next]
[also build test WARNING on v5.14-rc7 next-20210824]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Seven-Lee/ASoC-nau8821-Add-driver-for-Nuvoton-codec-NAU88L21/20210824-121846
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

:::::: branch date: 13 hours ago
:::::: commit date: 13 hours ago
config: openrisc-randconfig-m031-20210824 (attached as .config)
compiler: or1k-linux-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
sound/soc/codecs/nau8821.c:456 dmic_clock_control() error: uninitialized symbol 'speed_selection'.

vim +/speed_selection +456 sound/soc/codecs/nau8821.c

429cd8c43255317 Seven Lee 2021-08-24  418  
429cd8c43255317 Seven Lee 2021-08-24  419  static const struct snd_kcontrol_new nau8821_adc_ch0_dmic =
429cd8c43255317 Seven Lee 2021-08-24  420  	SOC_DAPM_SINGLE("Switch", NAU8821_R13_DMIC_CTRL,
429cd8c43255317 Seven Lee 2021-08-24  421  		NAU8821_DMIC_EN_SFT, 1, 0);
429cd8c43255317 Seven Lee 2021-08-24  422  
429cd8c43255317 Seven Lee 2021-08-24  423  static int dmic_clock_control(struct snd_soc_dapm_widget *w,
429cd8c43255317 Seven Lee 2021-08-24  424  		struct snd_kcontrol *k, int  event)
429cd8c43255317 Seven Lee 2021-08-24  425  {
429cd8c43255317 Seven Lee 2021-08-24  426  	struct snd_soc_component *component =
429cd8c43255317 Seven Lee 2021-08-24  427  		snd_soc_dapm_to_component(w->dapm);
429cd8c43255317 Seven Lee 2021-08-24  428  	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
429cd8c43255317 Seven Lee 2021-08-24  429  	int i, speed_selection, clk_adc_src, clk_adc;
429cd8c43255317 Seven Lee 2021-08-24  430  	unsigned int clk_divider_r03;
429cd8c43255317 Seven Lee 2021-08-24  431  
429cd8c43255317 Seven Lee 2021-08-24  432  	/* The DMIC clock is gotten from adc clock divided by
429cd8c43255317 Seven Lee 2021-08-24  433  	 * CLK_DMIC_SRC (1, 2, 4, 8). The clock has to be equal or
429cd8c43255317 Seven Lee 2021-08-24  434  	 * less than nau8821->dmic_clk_threshold.
429cd8c43255317 Seven Lee 2021-08-24  435  	 */
429cd8c43255317 Seven Lee 2021-08-24  436  	regmap_read(nau8821->regmap, NAU8821_R03_CLK_DIVIDER,
429cd8c43255317 Seven Lee 2021-08-24  437  		&clk_divider_r03);
429cd8c43255317 Seven Lee 2021-08-24  438  	clk_adc_src = (clk_divider_r03 & NAU8821_CLK_ADC_SRC_MASK)
429cd8c43255317 Seven Lee 2021-08-24  439  		>> NAU8821_CLK_ADC_SRC_SFT;
429cd8c43255317 Seven Lee 2021-08-24  440  	clk_adc = (nau8821->fs * 256) >> clk_adc_src;
429cd8c43255317 Seven Lee 2021-08-24  441  
429cd8c43255317 Seven Lee 2021-08-24  442  	for (i = 0 ; i < 4 ; i++) {
429cd8c43255317 Seven Lee 2021-08-24  443  		if ((clk_adc >> dmic_speed_sel[i].param) <=
429cd8c43255317 Seven Lee 2021-08-24  444  			nau8821->dmic_clk_threshold) {
429cd8c43255317 Seven Lee 2021-08-24  445  			speed_selection = dmic_speed_sel[i].val;
429cd8c43255317 Seven Lee 2021-08-24  446  			break;
429cd8c43255317 Seven Lee 2021-08-24  447  		}
429cd8c43255317 Seven Lee 2021-08-24  448  	}
429cd8c43255317 Seven Lee 2021-08-24  449  
429cd8c43255317 Seven Lee 2021-08-24  450  	dev_dbg(nau8821->dev,
429cd8c43255317 Seven Lee 2021-08-24  451  		"clk_adc=%d, dmic_clk_threshold = %d, param=%d, val = %d\n",
429cd8c43255317 Seven Lee 2021-08-24  452  		clk_adc, nau8821->dmic_clk_threshold,
429cd8c43255317 Seven Lee 2021-08-24  453  		dmic_speed_sel[i].param, dmic_speed_sel[i].val);
429cd8c43255317 Seven Lee 2021-08-24  454  	regmap_update_bits(nau8821->regmap, NAU8821_R13_DMIC_CTRL,
429cd8c43255317 Seven Lee 2021-08-24  455  		NAU8821_DMIC_SRC_MASK,
429cd8c43255317 Seven Lee 2021-08-24 @456  		(speed_selection << NAU8821_DMIC_SRC_SFT));
429cd8c43255317 Seven Lee 2021-08-24  457  
429cd8c43255317 Seven Lee 2021-08-24  458  	return 0;
429cd8c43255317 Seven Lee 2021-08-24  459  }
429cd8c43255317 Seven Lee 2021-08-24  460  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#3 lore raw
In reply to Seven Lee

couple of nit-picks/typos/indentations, see below.

Quoted 3 lines · Seven Lee

The driver is for codec NAU88L21 of Nuvoton Technology Corporation. The NAU88L21 is an ultra-low power high performance audio codec that supportsboth analog and digital audio functions.

supports both

sound/soc/codecs/Kconfig config SND_SOC_ALL_CODECS · line 139

Quoted 9 lines
sound/soc/codecs/Kconfig +1 -0
index 82ee233a269d..11bcf17b5f91 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

indent looks off?

sound/soc/codecs/Kconfig config SND_SOC_NAU8810 · line 1911

Quoted 11 lines
sound/soc/codecs/Kconfig +4 -0
 	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
+

and here indent is off as well?

Quoted 7 lines
sound/soc/codecs/Kconfig +7 -0
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/clk.h>

sound/soc/codecs/Kconfig config SND_SOC_NAU8810

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+#include <linux/acpi.h>
+#include <linux/math64.h>
+#include <linux/semaphore.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/jack.h>

alphabetical order?

Quoted 42 lines
sound/soc/codecs/Kconfig +42 -0
+/**
+ * nau8821_sema_acquire - acquire the semaphore of nau8821
+ * @nau8821:  component to register the codec private data with
+ * @timeout: how long in jiffies to wait before failure or zero to wait
+ * until release
+ *
+ * Attempts to acquire the semaphore with number of jiffies. If no more
+ * tasks are allowed to acquire the semaphore, calling this function will
+ * put the task to sleep. If the semaphore is not released within the
+ * specified number of jiffies, this function returns.
+ * If the semaphore is not released within the specified number of jiffies,
+ * this function returns -ETIME. If the sleep is interrupted by a signal,
+ * this function will return -EINTR. It returns 0 if the semaphore was
+ * acquired successfully.
+ *
+ * Acquires the semaphore without jiffies. Try to acquire the semaphore
+ * atomically. Returns 0 if the semaphore has been acquired successfully
+ * or 1 if it cannot be acquired.
+ */
+static int nau8821_sema_acquire(struct nau8821 *nau8821, long timeout)
+{
+	int ret;
+
+	if (!nau8821->irq)
+		return 1;
+
+	if (timeout) {
+		ret = down_timeout(&nau8821->jd_sem, timeout);
+		if (ret < 0)
+			dev_dbg(nau8821->dev, "Acquire semaphore timeout\n");
+	} else {
+		ret = down_trylock(&nau8821->jd_sem);
+		if (ret)
+			dev_dbg(nau8821->dev, "Acquire semaphore fail\n");
+	}
+
+	return ret;
+}
+
+/**
+ * nau8821_sema_release - release the semaphore of nau8821
+ * @nau8821:  component to register the codec private data with

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+ *
+ * Release the semaphore which may be called from any context and
+ * even by tasks which have never called down().
+ */
+static inline void nau8821_sema_release(struct nau8821 *nau8821)
+{
+	if (!nau8821->irq)
+		return;
+	up(&nau8821->jd_sem);
+}

is there any specific reason why Nuvoton codec drivers use a semaphore? isn't a mutex good enough?

Quoted 13 lines
sound/soc/codecs/Kconfig +12 -0
+
+/**
+ * nau8821_sema_reset - reset the semaphore for nau8821
+ * @nau8821:  component to register the codec private data with
+ *
+ * Reset the counter of the semaphore. Call this function to restart
+ * a new round task management.
+ */
+static inline void nau8821_sema_reset(struct nau8821 *nau8821)
+{
+	nau8821->jd_sem.count = 1;
+}
 

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+static int nau8821_left_adc_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		msleep(125);

use a define to keep track of sleep times in a header file?

Quoted 14 lines
sound/soc/codecs/Kconfig +14 -0
+		regmap_update_bits(nau8821->regmap, NAU8821_R01_ENA_CTRL,
+			NAU8821_EN_ADCL, NAU8821_EN_ADCL);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_update_bits(nau8821->regmap,
+			NAU8821_R01_ENA_CTRL, NAU8821_EN_ADCL, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+static int nau8821_right_adc_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		msleep(125);

#define?

Quoted 16 lines
sound/soc/codecs/Kconfig +16 -0
+		regmap_update_bits(nau8821->regmap, NAU8821_R01_ENA_CTRL,
+			NAU8821_EN_ADCR, NAU8821_EN_ADCR);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_update_bits(nau8821->regmap,
+			NAU8821_R01_ENA_CTRL, NAU8821_EN_ADCR, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int nau8821_pump_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	struct nau8821 *nau8821 =
+		snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		/* Prevent startup click by letting charge pump to ramp up */
+		msleep(20);

#define?

Quoted 46 lines
sound/soc/codecs/Kconfig +45 -0
+		regmap_update_bits(nau8821->regmap, NAU8821_R80_CHARGE_PUMP,
+			NAU8821_JAMNODCLOW, NAU8821_JAMNODCLOW);
+		break;
+	case SND_SOC_DAPM_PRE_PMD:
+		regmap_update_bits(nau8821->regmap, NAU8821_R80_CHARGE_PUMP,
+			NAU8821_JAMNODCLOW, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int nau8821_output_dac_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		/* Disables the TESTDAC to let DAC signal pass through. */
+		regmap_update_bits(nau8821->regmap, NAU8821_R66_BIAS_ADJ,
+			NAU8821_BIAS_TESTDAC_EN, 0);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_update_bits(nau8821->regmap, NAU8821_R66_BIAS_ADJ,
+			NAU8821_BIAS_TESTDAC_EN, NAU8821_BIAS_TESTDAC_EN);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	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;

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+		osrate = osr_dac_sel[osr].osr;
+	} else {
+		if (osr >= ARRAY_SIZE(osr_adc_sel))
+			return -EINVAL;
+		osrate = osr_adc_sel[osr].osr;
+	}
+
+	if (!osrate || rate * osrate > CLK_DA_AD_MAX) {
+		dev_err(nau8821->dev,
+		"exceed the maximum frequency of CLK_ADC or CLK_DAC\n");

odd indentation

Quoted 4 lines
sound/soc/codecs/Kconfig +4 -0
+		return -EINVAL;
+	}
+
+	return 0;

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +9 -0
+}
 
+static int nau8821_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
+{
+	struct snd_soc_component *component = codec_dai->component;
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+	unsigned int ctrl1_val = 0, ctrl2_val = 0;
+
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBM_CFM:

use CDP_CFP

sound/soc/codecs/Kconfig

Quoted 3 lines
sound/soc/codecs/Kconfig +3 -0
+		ctrl2_val |= NAU8821_I2S_MS_MASTER;
+		break;
+	case SND_SOC_DAIFMT_CBS_CFS:

use CBC_CFC

Quoted 41 lines
sound/soc/codecs/Kconfig +41 -0
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+	case SND_SOC_DAIFMT_NB_NF:
+		break;
+	case SND_SOC_DAIFMT_IB_NF:
+		ctrl1_val |= NAU8821_I2S_BP_INV;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+		ctrl1_val |= NAU8821_I2S_DF_I2S;
+		break;
+	case SND_SOC_DAIFMT_LEFT_J:
+		ctrl1_val |= NAU8821_I2S_DF_LEFT;
+		break;
+	case SND_SOC_DAIFMT_RIGHT_J:
+		ctrl1_val |= NAU8821_I2S_DF_RIGTH;
+		break;
+	case SND_SOC_DAIFMT_DSP_A:
+		ctrl1_val |= NAU8821_I2S_DF_PCM_AB;
+		break;
+	case SND_SOC_DAIFMT_DSP_B:
+		ctrl1_val |= NAU8821_I2S_DF_PCM_AB;
+		ctrl1_val |= NAU8821_I2S_PCMB_EN;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	nau8821_sema_acquire(nau8821, HZ);
+
+	regmap_update_bits(nau8821->regmap, NAU8821_R1C_I2S_PCM_CTRL1,
+		NAU8821_I2S_DL_MASK | NAU8821_I2S_DF_MASK |
+		NAU8821_I2S_BP_MASK | NAU8821_I2S_PCMB_MASK, ctrl1_val);

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+	regmap_update_bits(nau8821->regmap, NAU8821_R1D_I2S_PCM_CTRL2,
+		NAU8821_I2S_MS_MASK, ctrl2_val);
+
+	nau8821_sema_release(nau8821);
+
+	return 0;
+}
+
+static int nau8821_digital_mute(struct snd_soc_dai *dai, int mute,
+	int direction)

indentation?

Quoted 46 lines
sound/soc/codecs/Kconfig +45 -0
+{
+	struct snd_soc_component *component = dai->component;
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+	unsigned int val = 0;
+
+	if (mute)
+		val = NAU8821_DAC_SOFT_MUTE;
+
+	return regmap_update_bits(nau8821->regmap,
+		NAU8821_R31_MUTE_CTRL, NAU8821_DAC_SOFT_MUTE, val);
+}
+
 
+static int nau8821_set_bias_level(struct snd_soc_component *component,
+		enum snd_soc_bias_level level)
+{
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+	struct regmap *regmap = nau8821->regmap;
+
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		break;
+
+	case SND_SOC_BIAS_PREPARE:
+		break;
+
+	case SND_SOC_BIAS_STANDBY:
+		/* Setup codec configuration after resume */
+		if (snd_soc_component_get_bias_level(component) ==
+			SND_SOC_BIAS_OFF)
+			nau8821_resume_setup(nau8821);
+		break;
+
+	case SND_SOC_BIAS_OFF:
+		/* HPL/HPR short to ground */
+		regmap_update_bits(regmap, NAU8821_R0D_JACK_DET_CTRL,
+			NAU8821_SPKR_DWN1R | NAU8821_SPKR_DWN1L, 0);
+		if (nau8821->irq) {
+			/* Reset semaphore */
+			nau8821_sema_reset(nau8821);
+			/* Reset the configuration of jack type for detection.
+			 * Detach 2kOhm Resistors from MICBIAS to MICGND1/2.
+			 */
+			regmap_update_bits(regmap, NAU8821_R74_MIC_BIAS,
+				NAU8821_MICBIAS_JKR2, 0);
+			/* Turn off all interruptions before system shutdown.

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+			 * Keep theinterruption quiet before resume
+			 * setup completes.
+			 */
+			regmap_write(regmap,
+				NAU8821_R12_INTERRUPT_DIS_CTRL, 0xffff);
+			regmap_update_bits(regmap, NAU8821_R0F_INTERRUPT_MASK,
+				NAU8821_IRQ_EJECT_EN | NAU8821_IRQ_INSERT_EN,
+				NAU8821_IRQ_EJECT_EN | NAU8821_IRQ_INSERT_EN);
+		}
+		break;

default case?

sound/soc/codecs/Kconfig

Quoted 13 lines
sound/soc/codecs/Kconfig +13 -0
+	}
+
+	return 0;
+}
+
+static int __maybe_unused nau8821_suspend(struct snd_soc_component *component)
+{
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+
+	if (nau8821->irq)
+		disable_irq(nau8821->irq);
+	snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF);
+	/* Power down codec power; don't suppoet button wakeup */

support?

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +9 -0
+	snd_soc_dapm_disable_pin(nau8821->dapm, "MICBIAS");
+	snd_soc_dapm_sync(nau8821->dapm);
+	regcache_cache_only(nau8821->regmap, true);
+	regcache_mark_dirty(nau8821->regmap);
+
+	return 0;
+}
+
 
+MODULE_LICENSE("GPL v2");

MODULE_LICENSE("GPL");

the license version is provided by the SPDX line

maintainer
#4 lore raw
Quoted 11 lines · Pierre-Louis Bossart

sound/soc/codecs/nau8821.c line 251

Quoted 6 lines · Seven Lee
sound/soc/codecs/nau8821.c new file +6 -0
+static inline void nau8821_sema_release(struct nau8821 *nau8821)
+{
+	if (!nau8821->irq)
+		return;
+	up(&nau8821->jd_sem);
+}

is there any specific reason why Nuvoton codec drivers use a semaphore? isn't a mutex good enough?

I've been asking for documentation of what's going on with the locking on every revision of this so far to no success. As far as I can tell the driver is doing something weird where it needs to take and release the lock in different contexts which doesn't work with the kernel's mutex implementation where you need to take and release the mutex in the same context.

Quoted 5 lines

sound/soc/codecs/nau8821.c line 470

Quoted 3 lines
sound/soc/codecs/nau8821.c new file +3 -0
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		msleep(125);

use a define to keep track of sleep times in a header file?

I'm never sure that moving the magic numbers for sleeps out of line is actually helpful, it's an extra barrier to figuring out the actual sequence of operations and unless there's multiple users of the same underlying delay it doesn't really buy anything.

#5 lore raw
Quoted 10 lines · Mark Brown
Quoted 9 lines · Pierre-Louis Bossart

sound/soc/codecs/nau8821.c line 251

Quoted 6 lines · Seven Lee
sound/soc/codecs/nau8821.c new file +6 -0
+static inline void nau8821_sema_release(struct nau8821 *nau8821)
+{
+	if (!nau8821->irq)
+		return;
+	up(&nau8821->jd_sem);
+}

is there any specific reason why Nuvoton codec drivers use a semaphore? isn't a mutex good enough?

Quoted 6 lines

I've been asking for documentation of what's going on with the locking on every revision of this so far to no success. As far as I can tell the driver is doing something weird where it needs to take and release the lock in different contexts which doesn't work with the kernel's mutex implementation where you need to take and release the mutex in the same context.

Currently, we have deleted the semaphore and actual measurement. We plan to remove the semaphore after estimation and discussion. We estimate that the operation time of jack detection is less 100ms so that the risk is much smaller.

Quoted 9 lines
Quoted 5 lines

sound/soc/codecs/nau8821.c line 470

Quoted 4 lines
sound/soc/codecs/nau8821.c new file +3 -0
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		msleep(125);

use a define to keep track of sleep times in a header file?

I'm never sure that moving the magic numbers for sleeps out of line is actually helpful, it's an extra barrier to figuring out the actual sequence of operations and unless there's multiple users of the same underlying delay it doesn't really buy anything.

I agree with Mark description.

maintainer
#6 lore raw
Quoted 9 lines · Seven Lee
Quoted 6 lines · Mark Brown

I've been asking for documentation of what's going on with the locking on every revision of this so far to no success. As far as I can tell the driver is doing something weird where it needs to take and release the lock in different contexts which doesn't work with the kernel's mutex implementation where you need to take and release the mutex in the same context.

Quoted 4 lines

Currently, we have deleted the semaphore and actual measurement. We plan to remove the semaphore after estimation and discussion. We estimate that the operation time of jack detection is less 100ms so that the risk is much smaller.

OK, that sounds good - we can always revisit later if needed.

#7 lore raw
In reply to Pierre-Louis Bossart
Quoted 7 lines · Pierre-Louis Bossart

couple of nit-picks/typos/indentations, see below.

Quoted 3 lines · Seven Lee

The driver is for codec NAU88L21 of Nuvoton Technology Corporation. The NAU88L21 is an ultra-low power high performance audio codec that supportsboth analog and digital audio functions.

supports both

Okay, I will fix it.

Quoted 10 lines

sound/soc/codecs/Kconfig config SND_SOC_ALL_CODECS · line 139

Quoted 9 lines
sound/soc/codecs/Kconfig +1 -0
index 82ee233a269d..11bcf17b5f91 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

indent looks off?

Okay, I will fix it.

Quoted 7 lines
Quoted 7 lines
sound/soc/codecs/Kconfig +0 -0
  	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
 
Quoted 5 lines

sound/soc/codecs/Kconfig config SND_SOC_NAU8810 · line 1911

Quoted 4 lines
sound/soc/codecs/Kconfig +4 -0
+config SND_SOC_NAU8821
+        tristate "Nuvoton Technology Corporation NAU88L21 CODEC"
+        depends on I2C
+

and here indent is off as well?

Okay, I will fix it.

Quoted 10 lines
Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/acpi.h>
+#include <linux/math64.h>
+#include <linux/semaphore.h>
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 7 lines
sound/soc/codecs/Kconfig +7 -0
+#include <sound/initval.h>
+#include <sound/tlv.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/jack.h>

alphabetical order?

Okay, I will modify it for alphabetical order.

Quoted 45 lines
Quoted 45 lines
sound/soc/codecs/Kconfig +45 -0
+/**
+ * nau8821_sema_acquire - acquire the semaphore of nau8821
+ * @nau8821:  component to register the codec private data with
+ * @timeout: how long in jiffies to wait before failure or zero to wait
+ * until release
+ *
+ * Attempts to acquire the semaphore with number of jiffies. If no more
+ * tasks are allowed to acquire the semaphore, calling this function will
+ * put the task to sleep. If the semaphore is not released within the
+ * specified number of jiffies, this function returns.
+ * If the semaphore is not released within the specified number of jiffies,
+ * this function returns -ETIME. If the sleep is interrupted by a signal,
+ * this function will return -EINTR. It returns 0 if the semaphore was
+ * acquired successfully.
+ *
+ * Acquires the semaphore without jiffies. Try to acquire the semaphore
+ * atomically. Returns 0 if the semaphore has been acquired successfully
+ * or 1 if it cannot be acquired.
+ */
+static int nau8821_sema_acquire(struct nau8821 *nau8821, long timeout)
+{
+	int ret;
+
+	if (!nau8821->irq)
+		return 1;
+
+	if (timeout) {
+		ret = down_timeout(&nau8821->jd_sem, timeout);
+		if (ret < 0)
+			dev_dbg(nau8821->dev, "Acquire semaphore timeout\n");
+	} else {
+		ret = down_trylock(&nau8821->jd_sem);
+		if (ret)
+			dev_dbg(nau8821->dev, "Acquire semaphore fail\n");
+	}
+
+	return ret;
+}
+
+/**
+ * nau8821_sema_release - release the semaphore of nau8821
+ * @nau8821:  component to register the codec private data with
+ *
+ * Release the semaphore which may be called from any context and
+ * even by tasks which have never called down().
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 7 lines

+ */

sound/soc/codecs/Kconfig +6 -0
+static inline void nau8821_sema_release(struct nau8821 *nau8821)
+{
+	if (!nau8821->irq)
+		return;
+	up(&nau8821->jd_sem);
+}

is there any specific reason why Nuvoton codec drivers use a semaphore? isn't a mutex good enough?

The goal is not to be affected by playback during jack detection. I'm worried that the jack detection time is too long. At this time, an interrupt occurs and jack detection hasn't finished yet. But we estimate that the operation time of jack detection is less than 100ms so that the risk is much smaller. Therefore, we remove the semaphore.

Quoted 15 lines
Quoted 15 lines
sound/soc/codecs/Kconfig +15 -0
+
+/**
+ * nau8821_sema_reset - reset the semaphore for nau8821
+ * @nau8821:  component to register the codec private data with
+ *
+ * Reset the counter of the semaphore. Call this function to restart
+ * a new round task management.
+ */
+static inline void nau8821_sema_reset(struct nau8821 *nau8821)
+{
+	nau8821->jd_sem.count = 1;
+}
+static int nau8821_left_adc_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 7 lines
sound/soc/codecs/Kconfig +7 -0
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		msleep(125);

use a define to keep track of sleep times in a header file?

I agree with Mark description, it's an extra barrier to figuring out the actual sequence of operations and unless there's multiple users of the same underlying delay it doesn't really by anything.

Quoted 17 lines
Quoted 17 lines
sound/soc/codecs/Kconfig +17 -0
+		regmap_update_bits(nau8821->regmap, NAU8821_R01_ENA_CTRL,
+			NAU8821_EN_ADCL, NAU8821_EN_ADCL);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_update_bits(nau8821->regmap,
+			NAU8821_R01_ENA_CTRL, NAU8821_EN_ADCL, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int nau8821_right_adc_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 7 lines
sound/soc/codecs/Kconfig +7 -0
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		msleep(125);

#define?

Same as above.

Quoted 19 lines
Quoted 19 lines
sound/soc/codecs/Kconfig +19 -0
+		regmap_update_bits(nau8821->regmap, NAU8821_R01_ENA_CTRL,
+			NAU8821_EN_ADCR, NAU8821_EN_ADCR);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_update_bits(nau8821->regmap,
+			NAU8821_R01_ENA_CTRL, NAU8821_EN_ADCR, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int nau8821_pump_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 7 lines
sound/soc/codecs/Kconfig +7 -0
+	struct nau8821 *nau8821 =
+		snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		/* Prevent startup click by letting charge pump to ramp up */
+		msleep(20);

#define?

Same as above.

Quoted 48 lines
Quoted 48 lines
sound/soc/codecs/Kconfig +48 -0
+		regmap_update_bits(nau8821->regmap, NAU8821_R80_CHARGE_PUMP,
+			NAU8821_JAMNODCLOW, NAU8821_JAMNODCLOW);
+		break;
+	case SND_SOC_DAPM_PRE_PMD:
+		regmap_update_bits(nau8821->regmap, NAU8821_R80_CHARGE_PUMP,
+			NAU8821_JAMNODCLOW, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int nau8821_output_dac_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		/* Disables the TESTDAC to let DAC signal pass through. */
+		regmap_update_bits(nau8821->regmap, NAU8821_R66_BIAS_ADJ,
+			NAU8821_BIAS_TESTDAC_EN, 0);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_update_bits(nau8821->regmap, NAU8821_R66_BIAS_ADJ,
+			NAU8821_BIAS_TESTDAC_EN, NAU8821_BIAS_TESTDAC_EN);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	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))
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 7 lines
sound/soc/codecs/Kconfig +7 -0
+			return -EINVAL;
+		osrate = osr_adc_sel[osr].osr;
+	}
+
+	if (!osrate || rate * osrate > CLK_DA_AD_MAX) {
+		dev_err(nau8821->dev,
+		"exceed the maximum frequency of CLK_ADC or CLK_DAC\n");

odd indentation

Okay, I will fix it.

Quoted 7 lines
Quoted 7 lines
sound/soc/codecs/Kconfig +7 -0
+		return -EINVAL;
+	}
+
+	return 0;
+}
+static int nau8821_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
+{
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 6 lines
sound/soc/codecs/Kconfig +6 -0
+	struct snd_soc_component *component = codec_dai->component;
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+	unsigned int ctrl1_val = 0, ctrl2_val = 0;
+
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBM_CFM:

use CDP_CFP

Okay, I will fix it.

Quoted 6 lines

sound/soc/codecs/Kconfig

Quoted 4 lines
sound/soc/codecs/Kconfig +3 -0
+		ctrl2_val |= NAU8821_I2S_MS_MASTER;
+		break;
+	case SND_SOC_DAIFMT_CBS_CFS:

use CBC_CFC

Okay, I will fix it.

Quoted 46 lines
Quoted 46 lines
sound/soc/codecs/Kconfig +45 -0
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+	case SND_SOC_DAIFMT_NB_NF:
+		break;
+	case SND_SOC_DAIFMT_IB_NF:
+		ctrl1_val |= NAU8821_I2S_BP_INV;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+		ctrl1_val |= NAU8821_I2S_DF_I2S;
+		break;
+	case SND_SOC_DAIFMT_LEFT_J:
+		ctrl1_val |= NAU8821_I2S_DF_LEFT;
+		break;
+	case SND_SOC_DAIFMT_RIGHT_J:
+		ctrl1_val |= NAU8821_I2S_DF_RIGTH;
+		break;
+	case SND_SOC_DAIFMT_DSP_A:
+		ctrl1_val |= NAU8821_I2S_DF_PCM_AB;
+		break;
+	case SND_SOC_DAIFMT_DSP_B:
+		ctrl1_val |= NAU8821_I2S_DF_PCM_AB;
+		ctrl1_val |= NAU8821_I2S_PCMB_EN;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	nau8821_sema_acquire(nau8821, HZ);
+
+	regmap_update_bits(nau8821->regmap, NAU8821_R1C_I2S_PCM_CTRL1,
+		NAU8821_I2S_DL_MASK | NAU8821_I2S_DF_MASK |
+		NAU8821_I2S_BP_MASK | NAU8821_I2S_PCMB_MASK, ctrl1_val);
+	regmap_update_bits(nau8821->regmap, NAU8821_R1D_I2S_PCM_CTRL2,
+		NAU8821_I2S_MS_MASK, ctrl2_val);
+
+	nau8821_sema_release(nau8821);
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 6 lines
sound/soc/codecs/Kconfig +6 -0
+
+	return 0;
+}
+
+static int nau8821_digital_mute(struct snd_soc_dai *dai, int mute,
+	int direction)

indentation?

Okay, I will indent in this line.

Quoted 50 lines
Quoted 50 lines
sound/soc/codecs/Kconfig +49 -0
+{
+	struct snd_soc_component *component = dai->component;
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+	unsigned int val = 0;
+
+	if (mute)
+		val = NAU8821_DAC_SOFT_MUTE;
+
+	return regmap_update_bits(nau8821->regmap,
+		NAU8821_R31_MUTE_CTRL, NAU8821_DAC_SOFT_MUTE, val);
+}
+
+static int nau8821_set_bias_level(struct snd_soc_component *component,
+		enum snd_soc_bias_level level)
+{
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+	struct regmap *regmap = nau8821->regmap;
+
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+		break;
+
+	case SND_SOC_BIAS_PREPARE:
+		break;
+
+	case SND_SOC_BIAS_STANDBY:
+		/* Setup codec configuration after resume */
+		if (snd_soc_component_get_bias_level(component) ==
+			SND_SOC_BIAS_OFF)
+			nau8821_resume_setup(nau8821);
+		break;
+
+	case SND_SOC_BIAS_OFF:
+		/* HPL/HPR short to ground */
+		regmap_update_bits(regmap, NAU8821_R0D_JACK_DET_CTRL,
+			NAU8821_SPKR_DWN1R | NAU8821_SPKR_DWN1L, 0);
+		if (nau8821->irq) {
+			/* Reset semaphore */
+			nau8821_sema_reset(nau8821);
+			/* Reset the configuration of jack type for detection.
+			 * Detach 2kOhm Resistors from MICBIAS to MICGND1/2.
+			 */
+			regmap_update_bits(regmap, NAU8821_R74_MIC_BIAS,
+				NAU8821_MICBIAS_JKR2, 0);
+			/* Turn off all interruptions before system shutdown.
+			 * Keep theinterruption quiet before resume
+			 * setup completes.
+			 */
+			regmap_write(regmap,
Quoted 8 lines

sound/soc/codecs/Kconfig

Quoted 6 lines
sound/soc/codecs/Kconfig +6 -0
+				NAU8821_R12_INTERRUPT_DIS_CTRL, 0xffff);
+			regmap_update_bits(regmap, NAU8821_R0F_INTERRUPT_MASK,
+				NAU8821_IRQ_EJECT_EN | NAU8821_IRQ_INSERT_EN,
+				NAU8821_IRQ_EJECT_EN | NAU8821_IRQ_INSERT_EN);
+		}
+		break;

default case?

Okay, I will add default case.

Quoted 16 lines
Quoted 4 lines
sound/soc/codecs/Kconfig +3 -0
+	}
+
+	return 0;

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+}
+
+static int __maybe_unused nau8821_suspend(struct snd_soc_component *component)
+{
+	struct nau8821 *nau8821 = snd_soc_component_get_drvdata(component);
+
+	if (nau8821->irq)
+		disable_irq(nau8821->irq);
+	snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF);
+	/* Power down codec power; don't suppoet button wakeup */

support?

Okay, I will fix this word.

Quoted 12 lines

sound/soc/codecs/Kconfig

Quoted 10 lines
sound/soc/codecs/Kconfig +9 -0
+	snd_soc_dapm_disable_pin(nau8821->dapm, "MICBIAS");
+	snd_soc_dapm_sync(nau8821->dapm);
+	regcache_cache_only(nau8821->regmap, true);
+	regcache_mark_dirty(nau8821->regmap);
+
+	return 0;
+}
+
+MODULE_LICENSE("GPL v2");

MODULE_LICENSE("GPL"); the license version is provided by the SPDX line

Okay, I will fix it.

maintainer
#8 lore raw
In reply to Seven Lee

sound/soc/codecs/nau8821.c line 4

Quoted 5 lines · Seven Lee
sound/soc/codecs/nau8821.c new file +4 -0
@@ -0,0 +1,1804 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * nau8821.c -- Nuvoton NAU88L21 audio codec driver
+ *

Please make the entire comment a C++ one so things look more intentional.

Quoted 9 lines
sound/soc/codecs/nau8821.c new file +9 -0
+/**
+ * nau8821_sema_acquire - acquire the semaphore of nau8821
+ * @nau8821:  component to register the codec private data with
+ * @timeout: how long in jiffies to wait before failure or zero to wait
+ * until release
+ *
+ * Attempts to acquire the semaphore with number of jiffies. If no more
+ * tasks are allowed to acquire the semaphore, calling this function will
+ * put the task to sleep. If the semaphore is not released within the

sound/soc/codecs/nau8821.c line 218

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -0
+ * specified number of jiffies, this function returns.
+ * If the semaphore is not released within the specified number of jiffies,
+ * this function returns -ETIME. If the sleep is interrupted by a signal,
+ * this function will return -EINTR. It returns 0 if the semaphore was
+ * acquired successfully.
+ *
+ * Acquires the semaphore without jiffies. Try to acquire the semaphore
+ * atomically. Returns 0 if the semaphore has been acquired successfully
+ * or 1 if it cannot be acquired.
+ */

As I said in reply to Pierre's mail and as I have said on previous verisons of this patch can you please explain what is going on with the semaphore - why it's being used, how it's supposed to work and so on. The above comment just documents what a semaphore is which isn't the compliated or unusual part here, what's complicated and unusual is the fact that there's a semaphore in use at all.

As I have also suggested in reply to previous versions of this patch I strongly recommend splitting the semaphore related functionality out into separate patches so that it doesn't block the rest of the driver.

Please don't ignore review comments, people are generally making them for a reason and are likely to have the same concerns if issues remain unaddressed. Having to repeat the same comments can get repetitive and make people question the value of time spent reviewing. If you disagree with the review comments that's fine but you need to reply and discuss your concerns so that the reviewer can understand your decisions.

#9 lore raw
Quoted 9 lines · Mark Brown

sound/soc/codecs/nau8821.c line 4

Quoted 5 lines · Seven Lee
sound/soc/codecs/nau8821.c new file +4 -0
@@ -0,0 +1,1804 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * nau8821.c -- Nuvoton NAU88L21 audio codec driver
+ *

Please make the entire comment a C++ one so things look more intentional.

Okay, I will fix this comment for look more international.

Quoted 33 lines
Quoted 10 lines
sound/soc/codecs/nau8821.c new file +9 -0
+/**
+ * nau8821_sema_acquire - acquire the semaphore of nau8821
+ * @nau8821:  component to register the codec private data with
+ * @timeout: how long in jiffies to wait before failure or zero to wait
+ * until release
+ *
+ * Attempts to acquire the semaphore with number of jiffies. If no more
+ * tasks are allowed to acquire the semaphore, calling this function will
+ * put the task to sleep. If the semaphore is not released within the

sound/soc/codecs/nau8821.c line 218

Quoted 10 lines
sound/soc/codecs/nau8821.c new file +10 -0
+ * specified number of jiffies, this function returns.
+ * If the semaphore is not released within the specified number of jiffies,
+ * this function returns -ETIME. If the sleep is interrupted by a signal,
+ * this function will return -EINTR. It returns 0 if the semaphore was
+ * acquired successfully.
+ *
+ * Acquires the semaphore without jiffies. Try to acquire the semaphore
+ * atomically. Returns 0 if the semaphore has been acquired successfully
+ * or 1 if it cannot be acquired.
+ */

As I said in reply to Pierre's mail and as I have said on previous verisons of this patch can you please explain what is going on with the semaphore - why it's being used, how it's supposed to work and so on. The above comment just documents what a semaphore is which isn't the compliated or unusual part here, what's complicated and unusual is the fact that there's a semaphore in use at all.

As I have also suggested in reply to previous versions of this patch I strongly recommend splitting the semaphore related functionality out into separate patches so that it doesn't block the rest of the driver.

Quoted 6 lines

Please don't ignore review comments, people are generally making them for a reason and are likely to have the same concerns if issues remain unaddressed. Having to repeat the same comments can get repetitive and make people question the value of time spent reviewing. If you disagree with the review comments that's fine but you need to reply and discuss your concerns so that the reviewer can understand your decisions.

we have deleted the semaphore and actual measurement. We plan to remove the semaphore after estimation and discussion. We estimate that the operation time of jack detection is less 100ms so that the risk is much smaller.