Skip to contentSkip to conversation

ASoC: codecs: add support for ES8326

PATCH In review Zhu Ning 3 participants 5 messages Jul 7, 2022 – Jul 8, 2022

Subsystems (2)
lore
Share & tools
lore

Zhu Ning

author
#0 lore raw

PATCH 1/1 ASoC: codecs: add support for ES8326

The ES8326 codec is not compatible with ES8316 and requires a dedicated driver.

---
 sound/soc/codecs/Kconfig  |   5 +
 sound/soc/codecs/Makefile |   2 +
 sound/soc/codecs/es8326.c | 776 ++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/es8326.h | 187 +++++++++
 4 files changed, 970 insertions(+)
 mode change 100644 => 100755 sound/soc/codecs/Kconfig
 mode change 100644 => 100755 sound/soc/codecs/Makefile
 create mode 100755 sound/soc/codecs/es8326.c
 create mode 100755 sound/soc/codecs/es8326.h
sound/soc/codecs/Kconfig +5 -0
old mode 100644
new mode 100755
index 6165db92a629..b0a15cce416d
@@ -98,6 +98,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_DA9055
 	imply SND_SOC_DMIC
 	imply SND_SOC_ES8316
+	imply SND_SOC_ES8326
 	imply SND_SOC_ES8328_SPI
 	imply SND_SOC_ES8328_I2C
 	imply SND_SOC_ES7134
@@ -911,6 +912,10 @@ config SND_SOC_ES8316
 	tristate "Everest Semi ES8316 CODEC"
 	depends on I2C
 
+config SND_SOC_ES8326
+	tristate "Everest Semi ES8326 CODEC"
+	depends on I2C
+
 config SND_SOC_ES8328
 	tristate
 
sound/soc/codecs/Makefile +2 -0
old mode 100644
new mode 100755
index 28dc4edfd01f..ae9d789b5381
@@ -100,6 +100,7 @@ snd-soc-dmic-objs := dmic.o
 snd-soc-es7134-objs := es7134.o
 snd-soc-es7241-objs := es7241.o
 snd-soc-es8316-objs := es8316.o
+snd-soc-es8326-objs := es8326.o
 snd-soc-es8328-objs := es8328.o
 snd-soc-es8328-i2c-objs := es8328-i2c.o
 snd-soc-es8328-spi-objs := es8328-spi.o
@@ -452,6 +453,7 @@ obj-$(CONFIG_SND_SOC_DMIC)	+= snd-soc-dmic.o
 obj-$(CONFIG_SND_SOC_ES7134)	+= snd-soc-es7134.o
 obj-$(CONFIG_SND_SOC_ES7241)	+= snd-soc-es7241.o
 obj-$(CONFIG_SND_SOC_ES8316)    += snd-soc-es8316.o
+obj-$(CONFIG_SND_SOC_ES8326)    += snd-soc-es8326.o
 obj-$(CONFIG_SND_SOC_ES8328)	+= snd-soc-es8328.o
 obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
 obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
sound/soc/codecs/es8326.c new file +776 -0

776 lines not on this page · raw message

sound/soc/codecs/es8326.h new file +187 -0

188 lines not on this page · raw message

Signature · 1 line
2.36.1
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Zhu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on tiwai-sound/for-next linus/master v5.19-rc5 next-20220706] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhu-Ning/ASoC-codecs-add-support-for-ES8326/20220707-115006
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220707/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/fda793f4ec55b33955344b93a8c290fe207d54d4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Zhu-Ning/ASoC-codecs-add-support-for-ES8326/20220707-115006
        git checkout fda793f4ec55b33955344b93a8c290fe207d54d4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash sound/soc/codecs/

If you fix the issue, kindly add following tag where applicable

All warnings (new ones prefixed by >>):

>> sound/soc/codecs/es8326.c:742:35: warning: 'es8326_i2c_id' defined but not used [-Wunused-const-variable=]
     742 | static const struct i2c_device_id es8326_i2c_id[] = {
         |                                   ^~~~~~~~~~~~~

vim +/es8326_i2c_id +742 sound/soc/codecs/es8326.c

741

 > 742	static const struct i2c_device_id es8326_i2c_id[] = {

743 {"es8326", 0 },
744 {}
745 };
746 MODULE_DEVICE_TABLE(i2c, es8326_i2c_id);
747

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#2 lore raw
In reply to Zhu Ning
Thank you for the patch! Perhaps something to improve:

Hi Zhu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on tiwai-sound/for-next linus/master v5.19-rc5 next-20220707] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhu-Ning/ASoC-codecs-add-support-for-ES8326/20220707-115006
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: arm-randconfig-r014-20220707 (https://download.01.org/0day-ci/archive/20220707/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 66ae1d60bb278793fd651cece264699d522bab84)

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 arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/intel-lab-lkp/linux/commit/fda793f4ec55b33955344b93a8c290fe207d54d4
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Zhu-Ning/ASoC-codecs-add-support-for-ES8326/20220707-115006
git checkout fda793f4ec55b33955344b93a8c290fe207d54d4
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/clk/qcom/ sound/soc/codecs/

If you fix the issue, kindly add following tag where applicable

All warnings (new ones prefixed by >>):

>> sound/soc/codecs/es8326.c:612:13: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]
           if((reg && ES8326_VERSION_B) == 1)
                      ^
   sound/soc/codecs/es8326.h:185:29: note: expanded from macro 'ES8326_VERSION_B'
   #define ES8326_VERSION_B (1 << 0)
                               ^

1 warning generated.

vim +612 sound/soc/codecs/es8326.c

531
532 static struct snd_soc_dai_driver es8326_dai = {
533 .name = "ES8326 HiFi",
534 .playback = {
535 .stream_name = "Playback",
536 .channels_min = 1,
537 .channels_max = 2,
538 .rates = es8326_RATES,
539 .formats = es8326_FORMATS,
540 },
541 .capture = {
542 .stream_name = "Capture",
543 .channels_min = 1,
544 .channels_max = 2,
545 .rates = es8326_RATES,
546 .formats = es8326_FORMATS,
547 },
548 .ops = &es8326_ops,
549 .symmetric_rate = 1,
550 };
551 static int es8326_resume(struct snd_soc_component *component)
552 {
553 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
554
555 regmap_write(es8326->regmap, ES8326_CLK_CTL_01, ES8326_CLK_ON);
556 /* Two channel ADC */
557 regmap_write(es8326->regmap, ES8326_PULLUP_CTL_F9, 0x02);
558 regmap_write(es8326->regmap, ES8326_CLK_INV_02, 0x00);
559 regmap_write(es8326->regmap, ES8326_CLK_DIV_CPC_0C, 0x1F);
560 regmap_write(es8326->regmap, ES8326_CLK_VMIDS1_10, 0xC8);
561 regmap_write(es8326->regmap, ES8326_CLK_VMIDS2_11, 0x88);
562 regmap_write(es8326->regmap, ES8326_CLK_CAL_TIME_12, 0x20);
563 regmap_write(es8326->regmap, ES8326_SYS_BIAS_1D, 0x08);
564 regmap_write(es8326->regmap, ES8326_DAC2HPMIX_25, 0x22);
565 regmap_write(es8326->regmap, ES8326_ADC1_SRC_2A, es8326->mic1_src);
566 regmap_write(es8326->regmap, ES8326_ADC2_SRC_2B, es8326->mic2_src);
567 regmap_write(es8326->regmap, ES8326_HPJACK_TIMER_56, 0x88);
568 regmap_write(es8326->regmap, ES8326_HP_DET_57,
569 ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol);
570 regmap_write(es8326->regmap, ES8326_INT_SOURCE_58, 0x08);
571 regmap_write(es8326->regmap, ES8326_INTOUT_IO_59, 0x45);
572 regmap_write(es8326->regmap, ES8326_RESET_00, ES8326_CSM_ON);
573 snd_soc_component_update_bits(component, ES8326_PAGGAIN_23,
574 ES8326_MIC_SEL_MASK, ES8326_MIC1_SEL);
575
576 es8326_irq(es8326->irq, es8326);
577 return 0;
578 }
579 static int es8326_probe(struct snd_soc_component *component)
580 {
581 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component);
582 int ret;
583 u8 reg;
584
585 es8326->component = component;
586 es8326->jd_inverted = device_property_read_bool(component->dev,
587 "everest,jack-detect-inverted");
588
589 ret = device_property_read_u8(component->dev, "everest,mic1-src", &es8326->mic1_src);
590 if (ret != 0) {
591 dev_dbg(component->dev, "mic1-src return %d", ret);
592 es8326->mic1_src = ES8326_ADC_AMIC;
593 }
594 dev_dbg(component->dev, "mic1-src %x", es8326->mic1_src);
595
596 ret = device_property_read_u8(component->dev, "everest,mic2-src", &es8326->mic2_src);
597 if (ret != 0) {
598 dev_dbg(component->dev, "mic2-src return %d", ret);
599 es8326->mic2_src = ES8326_ADC_DMIC;
600 }
601 dev_dbg(component->dev, "mic2-src %x", es8326->mic2_src);
602
603 ret = device_property_read_u8(component->dev, "everest,jack-pol", &es8326->jack_pol);
604 if (ret != 0) {
605 dev_dbg(component->dev, "jack-pol return %d", ret);
606 es8326->jack_pol = ES8326_HP_DET_BUTTON_POL | ES8326_HP_TYPE_OMTP;
607 }
608 dev_dbg(component->dev, "jack-pol %x", es8326->jack_pol);
609
610 es8326_resume(component);
611 reg = snd_soc_component_read(component, ES8326_CHIP_VERSION_FF);

 > 612		if((reg && ES8326_VERSION_B) == 1)

613 {
614 regmap_write(es8326->regmap, ES8326_ANA_VSEL_1C, 0x7F);
615 regmap_write(es8326->regmap, ES8326_VMIDLOW_22, 0x0F);
616 regmap_write(es8326->regmap, ES8326_DAC2HPMIX_25, 0xAA);
617 regmap_write(es8326->regmap, ES8326_HP_DRVIER_24, 0x20);
618 }
619 return 0;
620 }
621

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#3 lore raw
In reply to Zhu Ning
Thank you for the patch! Perhaps something to improve:

Hi Zhu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on tiwai-sound/for-next linus/master v5.19-rc5 next-20220707] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhu-Ning/ASoC-codecs-add-support-for-ES8326/20220707-115006
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: arm64-buildonly-randconfig-r006-20220707 (https://download.01.org/0day-ci/archive/20220708/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 66ae1d60bb278793fd651cece264699d522bab84)

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 arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/fda793f4ec55b33955344b93a8c290fe207d54d4
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Zhu-Ning/ASoC-codecs-add-support-for-ES8326/20220707-115006
git checkout fda793f4ec55b33955344b93a8c290fe207d54d4
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash sound/soc/codecs/

If you fix the issue, kindly add following tag where applicable

All warnings (new ones prefixed by >>):

sound/soc/codecs/es8326.c:612:13: warning: converting the result of '<<' to a boolean always evaluates to true [-Wtautological-constant-compare]

           if((reg && ES8326_VERSION_B) == 1)
                      ^
   sound/soc/codecs/es8326.h:185:29: note: expanded from macro 'ES8326_VERSION_B'
   #define ES8326_VERSION_B (1 << 0)
                               ^
>> sound/soc/codecs/es8326.c:742:35: warning: unused variable 'es8326_i2c_id' [-Wunused-const-variable]
   static const struct i2c_device_id es8326_i2c_id[] = {
                                     ^

2 warnings generated.

vim +/es8326_i2c_id +742 sound/soc/codecs/es8326.c

741

 > 742	static const struct i2c_device_id es8326_i2c_id[] = {

743 {"es8326", 0 },
744 {}
745 };
746 MODULE_DEVICE_TABLE(i2c, es8326_i2c_id);
747

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
maintainer
#4 lore raw
In reply to Zhu Ning
Quoted 1 line · Zhu Ning

The ES8326 codec is not compatible with ES8316 and requires a dedicated driver.

There's a bunch of bot reported issues as well as those below. Other than the interrupt management this should all be fairly small, the bulk of the driver looks good:

sound/soc/codecs/es8326.c line 115

Quoted 6 lines
sound/soc/codecs/es8326.c new file +6 -0
+	SOC_ENUM_SINGLE(ES8326_DAC_DSM_4D, 4, 4, dacpol_txt);
+static const struct soc_enum alc_winsize =
+	SOC_ENUM_SINGLE(ES8326_ADC_RAMPRATE_2E, 4, 16, winsize);
+static const struct soc_enum drc_winsize =
+	SOC_ENUM_SINGLE(ES8326_DRC_WINSIZE_54, 4, 16, winsize);
+static const struct snd_kcontrol_new es8326_snd_controls[] = {

We needs osme blank lines between declarations here to improve legibility.

sound/soc/codecs/es8326.c line 357

Quoted 5 lines
sound/soc/codecs/es8326.c new file +5 -0
+/*
+ * Note that this should be called from init rather than from hw_params.
+ */
+static int es8326_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+				 int clk_id, unsigned int freq, int dir)

I don't see any reason why it *couldn't* be called from hw_params - it'll mean the constraints don't take effect but that might be desirable if it's called from hw_params due to being able to reprogram the input clock.

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+static int es8326_probe(struct snd_soc_component *component)

More missing blank lines.

sound/soc/codecs/es8326.c line 596

Quoted 8 lines
sound/soc/codecs/es8326.c new file +8 -0
+	ret = device_property_read_u8(component->dev, "everest,mic1-src", &es8326->mic1_src);
+	if (ret != 0) {
+		dev_dbg(component->dev, "mic1-src return %d", ret);
+		es8326->mic1_src = ES8326_ADC_AMIC;
+	}
+	dev_dbg(component->dev, "mic1-src %x", es8326->mic1_src);
+
+	ret = device_property_read_u8(component->dev, "everest,mic2-src", &es8326->mic2_src);

This is adding a DT binding, the binding needs to be documented.

sound/soc/codecs/es8326.c line 612

Quoted 1 line
sound/soc/codecs/es8326.c new file +1 -0
+	if((reg && ES8326_VERSION_B) == 1)

Coding style and I'm not sure the logic there is what's intended?

sound/soc/codecs/es8326.c line 618

Quoted 6 lines
sound/soc/codecs/es8326.c new file +6 -0
+	{
+		regmap_write(es8326->regmap, ES8326_ANA_VSEL_1C, 0x7F);
+		regmap_write(es8326->regmap, ES8326_VMIDLOW_22, 0x0F);
+		regmap_write(es8326->regmap, ES8326_DAC2HPMIX_25, 0xAA);
+		regmap_write(es8326->regmap, ES8326_HP_DRVIER_24, 0x20);
+	}

Should there be something similar in the resume path? I'm also not seeing anything that manages the register cache over suspend.

sound/soc/codecs/es8326.c line 638

Quoted 3 lines
sound/soc/codecs/es8326.c new file +3 -0
+	/* Enable irq and sync initial jack state */
+	enable_irq(es8326->irq);
+	es8326_irq(es8326->irq, es8326);

The driver souldn't need to enable or disable the IRQ by hand, it should just configure the device to not generate interrupts when not in use. Enabling and disabling doesn't play nicely with shared interrupts and is in general typically a warning sign.

sound/soc/codecs/es8326.c line 750

Quoted 3 lines
sound/soc/codecs/es8326.c new file +3 -0
+#ifdef CONFIG_OF
+static const struct of_device_id es8326_of_match[] = {
+	{ .compatible = "everest, es8326", },

There shouldn't be a space in the compatible string.